[test] Add tests for mcp.Connection.callTool - #10937
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds end-to-end SDK dispatch tests for Connection.callTool.
Changes:
- Tests nil/default and forwarded arguments.
- Tests backend and unknown-tool errors.
Show a summary per file
| File | Description |
|---|---|
internal/mcp/call_tool_test.go |
Adds SDK-backed callTool tests. |
Review details
Tip
Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Balanced
| }, func(_ context.Context, req *sdk.CallToolRequest) (*sdk.CallToolResult, error) { | ||
| args, err := ParseToolArguments(req) |
🔒 mcpg Read-Only Stress — gVisorSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Notes:
Overall: PASS References: §31324778450
|
🔒 mcpg Read-Only Stress — defaultSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Overall: PASS Part B detail: All 7 MCP write tools returned gateway error References: §31324778475
|
🔒 mcpg Read-Only Stress — docker-sbxSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Overall: PASS
References: §31324778474
|
Test Coverage Improvement:
callToolFunction Analyzed
internal/mcpConnection.callTool(inconnection_methods.go)Why This Function?
callToolis the gateway's coretools/calldispatch path — it normalizes nilargumentsto an empty map (a hard MCP protocol requirement) before invoking the backend SDK session'sCallTool. It had only 20% statement coverage: existing tests exercised argument marshaling/unmarshaling at the HTTP JSON layer and nil-session error paths, but never exercised the real SDK call path (theif p.Arguments == nilbranch and the successfulgetSDKSession().CallTool(...)call were both untested).Tests Added
TestCallTool_NilArgumentsDefaultsToEmptyMap— verifies omittedargumentsbecomes an empty map at the backendTestCallTool_ArgumentsForwarded— verifies provided arguments are forwarded unmodifiedTestCallTool_BackendHandlerError— verifies a Go error from the backend tool handler surfaces as an errorTestCallTool_UnknownToolName— verifies an unknown tool name produces an errorAll four tests spin up a real
sdk.NewStreamableHTTPHandler-backedhttptest.Server(rather than mocking JSON-RPC at the HTTP layer), so they exercise the actualcallSDKMethod → callParamMethod → sdk.ClientSession.CallTooldispatch path end-to-end.Coverage Report
Test Execution
gofmtandgo vetare clean on the new file.Generated by Test Coverage Improver
Next run will target the next most complex under-tested function