on main help sign in
fix(mcp): append to output instead of replacing (#658)
ae3b3d7Carlos Alexandro Becker
internal/llm/agent/mcp-tools.go+5−4
@@ -6,6 +6,7 @@ import (
6 "fmt"
6 "fmt"
7 "log/slog"
7 "log/slog"
8 "slices"
8 "slices"
9+ "strings"
9 "sync"
10 "sync"
10 "time"
11 "time"
11
12
@@ -122,16 +123,16 @@ func runTool(ctx context.Context, name, toolName string, input string) (tools.To
122 return tools.NewTextErrorResponse(err.Error()), nil
123 return tools.NewTextErrorResponse(err.Error()), nil
123 }
124 }
124
125
125− output := ""
126+ var output strings.Builder
126 for _, v := range result.Content {
127 for _, v := range result.Content {
127 if v, ok := v.(mcp.TextContent); ok {
128 if v, ok := v.(mcp.TextContent); ok {
128− output = v.Text
129+ output.WriteString(v.Text)
129 } else {
130 } else {
130− output = fmt.Sprintf("%v", v)
131+ _, _ = fmt.Fprintf(&output, "%v: ", v)
131 }
132 }
132 }
133 }
133
134
134− return tools.NewTextResponse(output), nil
135+ return tools.NewTextResponse(output.String()), nil
135}
136}
136
137
137func (b *McpTool) Run(ctx context.Context, params tools.ToolCall) (tools.ToolResponse, error) {
138func (b *McpTool) Run(ctx context.Context, params tools.ToolCall) (tools.ToolResponse, error) {