Skip to content

Commit 638976e

Browse files
advancedresearcharraycursoragent
andcommitted
test: cover typed empty struct for omitted tool arguments
Verify zero-parameter tools using struct input types also succeed when clients omit the arguments field entirely. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 3457fd6 commit 638976e

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

pkg/inventory/server_tool_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,32 @@ func TestNewServerToolWithContextHandler_EmptyArguments_TreatedAsEmptyObject(t *
126126
})
127127
}
128128
}
129+
130+
func TestNewServerToolWithContextHandler_EmptyArguments_TypedEmptyStruct(t *testing.T) {
131+
type emptyArgs struct{}
132+
133+
tool := NewServerToolWithContextHandler(
134+
mcp.Tool{Name: "typed_zero_arg_tool"},
135+
testToolsetMetadata("test"),
136+
func(_ context.Context, _ *mcp.CallToolRequest, args emptyArgs) (*mcp.CallToolResult, any, error) {
137+
return &mcp.CallToolResult{
138+
Content: []mcp.Content{
139+
&mcp.TextContent{Text: "ok"},
140+
},
141+
}, args, nil
142+
},
143+
)
144+
145+
handler := tool.HandlerFunc(nil)
146+
147+
result, err := handler(context.Background(), &mcp.CallToolRequest{
148+
Params: &mcp.CallToolParamsRaw{
149+
Name: "typed_zero_arg_tool",
150+
Arguments: nil,
151+
},
152+
})
153+
154+
require.NoError(t, err)
155+
require.NotNil(t, result)
156+
assert.False(t, result.IsError)
157+
}

0 commit comments

Comments
 (0)