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.

Loading
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