Skip to content

Commit fa5f70b

Browse files
rootcursoragent
andcommitted
fix: accept omitted tool arguments for zero-param tools like get_me
Treat nil or empty Arguments JSON as {} before unmarshaling so clients that omit arguments match tools with empty input schemas. Fixes #2587 Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 33849e9 commit fa5f70b

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

pkg/inventory/server_tool.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,11 @@ func NewServerToolWithContextHandler[In any, Out any](tool mcp.Tool, toolset Too
133133
HandlerFunc: func(_ any) mcp.ToolHandler {
134134
return func(ctx context.Context, req *mcp.CallToolRequest) (*mcp.CallToolResult, error) {
135135
var arguments In
136-
if err := json.Unmarshal(req.Params.Arguments, &arguments); err != nil {
136+
args := req.Params.Arguments
137+
if len(args) == 0 {
138+
args = json.RawMessage(`{}`)
139+
}
140+
if err := json.Unmarshal(args, &arguments); err != nil {
137141
return &mcp.CallToolResult{
138142
Content: []mcp.Content{
139143
&mcp.TextContent{Text: fmt.Sprintf("invalid arguments: %s", err)},

pkg/inventory/server_tool_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,29 @@ func TestNewServerToolWithContextHandler_ValidArguments_Succeeds(t *testing.T) {
7878
require.True(t, ok)
7979
assert.Equal(t, "success: octocat/hello-world", textContent.Text)
8080
}
81+
82+
func TestNewServerToolWithContextHandler_NilArguments_TreatedAsEmptyObject(t *testing.T) {
83+
tool := NewServerToolWithContextHandler(
84+
mcp.Tool{Name: "zero_arg_tool"},
85+
testToolsetMetadata("test"),
86+
func(_ context.Context, _ *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) {
87+
return &mcp.CallToolResult{
88+
Content: []mcp.Content{
89+
&mcp.TextContent{Text: "ok"},
90+
},
91+
}, args, nil
92+
},
93+
)
94+
95+
handler := tool.HandlerFunc(nil)
96+
result, err := handler(context.Background(), &mcp.CallToolRequest{
97+
Params: &mcp.CallToolParamsRaw{
98+
Name: "zero_arg_tool",
99+
Arguments: nil,
100+
},
101+
})
102+
103+
require.NoError(t, err)
104+
require.NotNil(t, result)
105+
assert.False(t, result.IsError)
106+
}

0 commit comments

Comments
 (0)