on main help sign in
feat(mcp): support server side instructions (#2015)

* 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>

commitfea878e4d4c315f91c190d589891eddbeb8f7ac4 authorCarlos Alexandro Becker <caarlos0@users.noreply.github.com> dateWed 28 Jan 2026, 10:41 (9 months ago) parentc6b0a8a
1 file changed+16
internal/agent/agent.go+16
internal/agent/agent.go+16
@@ -32,6 +32,7 @@ import (
3232 "github.com/charmbracelet/catwalk/pkg/catwalk"
3333 "github.com/charmbracelet/crush/internal/agent/hyper"
3434 "github.com/charmbracelet/crush/internal/agent/tools"
35+ "github.com/charmbracelet/crush/internal/agent/tools/mcp"
3536 "github.com/charmbracelet/crush/internal/config"
3637 "github.com/charmbracelet/crush/internal/csync"
3738 "github.com/charmbracelet/crush/internal/message"
@@ -167,6 +168,21 @@ func (a *sessionAgent) Run(ctx context.Context, call SessionAgentCall) (*fantasy
167168 largeModel := a.largeModel.Get()
168169 systemPrompt := a.systemPrompt.Get()
169170 promptPrefix := a.systemPromptPrefix.Get()
171+ var instructions strings.Builder
172+
173+ for _, server := range mcp.GetStates() {
174+ if server.State != mcp.StateConnected {
175+ continue
176+ }
177+ if s := server.Client.InitializeResult().Instructions; s != "" {
178+ instructions.WriteString(s)
179+ instructions.WriteString("\n\n")
180+ }
181+ }
182+
183+ if s := instructions.String(); s != "" {
184+ systemPrompt += "\n\n<mcp-instructions>\n" + s + "\n</mcp-instructions>"
185+ }
170186
171187 if len(agentTools) > 0 {
172188 // Add Anthropic caching to the last tool.