feat(mcp): support server side instructions (#2015)
Carlos Alexandro Becker
created 2 weeks ago
* feat(mcp): support server side instructions
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
* fix: empty lines
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
---------
Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
Change summary
internal/agent/agent.go | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
Detailed changes
@@ -32,6 +32,7 @@ import (
"github.com/charmbracelet/catwalk/pkg/catwalk"
"github.com/charmbracelet/crush/internal/agent/hyper"
"github.com/charmbracelet/crush/internal/agent/tools"
+ "github.com/charmbracelet/crush/internal/agent/tools/mcp"
"github.com/charmbracelet/crush/internal/config"
"github.com/charmbracelet/crush/internal/csync"
"github.com/charmbracelet/crush/internal/message"
@@ -167,6 +168,21 @@ func (a *sessionAgent) Run(ctx context.Context, call SessionAgentCall) (*fantasy
largeModel := a.largeModel.Get()
systemPrompt := a.systemPrompt.Get()
promptPrefix := a.systemPromptPrefix.Get()
+ var instructions strings.Builder
+
+ for _, server := range mcp.GetStates() {
+ if server.State != mcp.StateConnected {
+ continue
+ }
+ if s := server.Client.InitializeResult().Instructions; s != "" {
+ instructions.WriteString(s)
+ instructions.WriteString("\n\n")
+ }
+ }
+
+ if s := instructions.String(); s != "" {
+ systemPrompt += "\n\n<mcp-instructions>\n" + s + "\n</mcp-instructions>"
+ }
if len(agentTools) > 0 {
// Add Anthropic caching to the last tool.