Skip to content

Fix: Validate tool name presence in MCP tools/call requests#287

Merged
lpcox merged 2 commits intomainfrom
copilot/fix-invalid-json-error-handling
Jan 16, 2026
Merged

Fix: Validate tool name presence in MCP tools/call requests#287
lpcox merged 2 commits intomainfrom
copilot/fix-invalid-json-error-handling

Conversation

Copy link
Contributor

Copilot AI commented Jan 16, 2026

The TestHandleRequest_ToolsCall_InvalidJSON test was failing because requests with missing or empty tool names returned "unknown tool: " instead of "invalid params".

Root Cause

Valid JSON structures like {"arguments": {}}, null, or {} successfully unmarshal but leave callParams.Name as an empty string. The code then called callTool("") which returned "unknown tool: " rather than validating the parameter first.

Changes

internal/sys/sys.go

  • Added validation after unmarshaling to check if callParams.Name is empty
  • Returns "invalid params: missing tool name" before attempting tool lookup

internal/sys/sys_test.go

  • Removed "empty tool name" case from TestHandleRequest_ToolsCall_UnknownTool since explicit empty strings are now correctly categorized as invalid params rather than unknown tools
// After unmarshal, validate tool name is present
if callParams.Name == "" {
    log.Printf("Tool call missing name field")
    return nil, fmt.Errorf("invalid params: missing tool name")
}

This distinguishes between malformed requests (missing required field) and valid requests for non-existent tools, providing clearer error semantics.


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

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix error handling for invalid tool call requests Fix: Validate tool name presence in MCP tools/call requests Jan 16, 2026
Copilot AI requested a review from lpcox January 16, 2026 06:35
@lpcox lpcox marked this pull request as ready for review January 16, 2026 06:36
@lpcox lpcox merged commit bf2c071 into main Jan 16, 2026
3 of 4 checks passed
@lpcox lpcox deleted the copilot/fix-invalid-json-error-handling branch January 16, 2026 06:36
Copilot stopped work on behalf of lpcox due to an error January 16, 2026 06:37
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