Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 16, 2026

Problem

MCP gateway was passing empty arguments {} to backend servers, causing tool calls to fail with "missing required parameter" errors. Gateway logs showed args={} even when clients sent populated arguments.

Root Cause

The SDK handler callback signature provides arguments in two places:

func(ctx context.Context, req *sdk.CallToolRequest, args interface{})

Code was using the args parameter (SDK internal state), not req.Params.Arguments (actual client arguments as json.RawMessage).

Changes

Argument Extraction (internal/server/unified.go)

  • Extract arguments from req.Params.Arguments and unmarshal to map[string]interface{}
  • Default to empty map if arguments field missing or nil
  • Applied to both regular tool handlers and sys_init handler

Protocol Compliance (internal/mcp/connection.go)

  • Added nil check in callTool() to ensure arguments never nil for SDK-based transports
  • Added ensureToolCallArguments() helper to guarantee arguments field exists for plain JSON transport
  • MCP protocol requires arguments field always present, even if empty

Test Coverage

  • Added connection_arguments_test.go - verifies argument handling for empty, null, and omitted cases
  • Added tool_call_arguments_test.go - end-to-end verification that arguments reach backend correctly

Example

Before:

[INFO] MCP tool call request, tool=list_code_scanning_alerts, args={}
[DEBUG] github→tools/call {"params":{"arguments":{},"name":"list_code_scanning_alerts"}}
[ERROR] Backend error: missing required parameter: owner

After:

[INFO] MCP tool call request, tool=list_code_scanning_alerts, args={"owner":"org","repo":"repo"}
[DEBUG] github→tools/call {"params":{"arguments":{"owner":"org","repo":"repo"},"name":"list_code_scanning_alerts"}}
[INFO] Tool call successful

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits January 16, 2026 19:07
…rectly passed

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
… instead of args parameter

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix argument stripping issue in MCP gateway calls Fix MCP tool call arguments being stripped from SDK requests Jan 16, 2026
Copilot AI requested a review from lpcox January 16, 2026 19:27
@lpcox lpcox marked this pull request as ready for review January 16, 2026 19:34
@lpcox lpcox merged commit 77e68c6 into main Jan 16, 2026
3 checks passed
@lpcox lpcox deleted the copilot/check-mcp-gateway-argument-stripping branch January 16, 2026 19:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants