From 65617bd7d435b5871edb09b1ab3c65c26b2cdef6 Mon Sep 17 00:00:00 2001 From: Gedy Palomino Date: Tue, 1 Jul 2025 00:00:33 -0500 Subject: [PATCH 1/3] fix(mcp): ensure required field if nil --- internal/llm/agent/mcp-tools.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/llm/agent/mcp-tools.go b/internal/llm/agent/mcp-tools.go index 23756064..59a15bdd 100644 --- a/internal/llm/agent/mcp-tools.go +++ b/internal/llm/agent/mcp-tools.go @@ -33,11 +33,15 @@ type MCPClient interface { } func (b *mcpTool) Info() tools.ToolInfo { + required := b.tool.InputSchema.Required + if required == nil { + required = make([]string, 0) + } return tools.ToolInfo{ Name: fmt.Sprintf("%s_%s", b.mcpName, b.tool.Name), Description: b.tool.Description, Parameters: b.tool.InputSchema.Properties, - Required: b.tool.InputSchema.Required, + Required: required, } } From 566694139fff1d6766062bb62a71e7eba2d4ccf4 Mon Sep 17 00:00:00 2001 From: Gedy Palomino Date: Tue, 1 Jul 2025 12:10:22 -0500 Subject: [PATCH 2/3] fix(mcp): handle empty input by initializing with empty JSON object --- internal/llm/agent/mcp-tools.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/llm/agent/mcp-tools.go b/internal/llm/agent/mcp-tools.go index 59a15bdd..b20c9540 100644 --- a/internal/llm/agent/mcp-tools.go +++ b/internal/llm/agent/mcp-tools.go @@ -62,6 +62,9 @@ func runTool(ctx context.Context, c MCPClient, toolName string, input string) (t toolRequest := mcp.CallToolRequest{} toolRequest.Params.Name = toolName var args map[string]any + if input == "" { + input = "{}" + } if err = json.Unmarshal([]byte(input), &args); err != nil { return tools.NewTextErrorResponse(fmt.Sprintf("error parsing parameters: %s", err)), nil } From 3532b7aa09d07f882f90071f2f508db1468f4d85 Mon Sep 17 00:00:00 2001 From: Gedy Palomino Date: Tue, 1 Jul 2025 17:13:28 -0500 Subject: [PATCH 3/3] fix(mcp): trim input string before checking for emptiness in runTool --- internal/llm/agent/mcp-tools.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/llm/agent/mcp-tools.go b/internal/llm/agent/mcp-tools.go index b20c9540..684580c5 100644 --- a/internal/llm/agent/mcp-tools.go +++ b/internal/llm/agent/mcp-tools.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "fmt" + "strings" "github.com/opencode-ai/opencode/internal/config" "github.com/opencode-ai/opencode/internal/llm/tools" @@ -62,7 +63,7 @@ func runTool(ctx context.Context, c MCPClient, toolName string, input string) (t toolRequest := mcp.CallToolRequest{} toolRequest.Params.Name = toolName var args map[string]any - if input == "" { + if strings.TrimSpace(input) == "" { input = "{}" } if err = json.Unmarshal([]byte(input), &args); err != nil {