Skip to content

mcp: return input validation errors as tool results, not JSON-RPC errors#863

Open
ravyg wants to merge 2 commits intomodelcontextprotocol:mainfrom
ravyg:fix/450-input-validation-tool-error
Open

mcp: return input validation errors as tool results, not JSON-RPC errors#863
ravyg wants to merge 2 commits intomodelcontextprotocol:mainfrom
ravyg:fix/450-input-validation-tool-error

Conversation

@ravyg
Copy link
Copy Markdown

@ravyg ravyg commented Mar 27, 2026

Input validation errors (missing required fields, wrong types) during tool calls
are now returned as CallToolResult with IsError=true instead of JSON-RPC
-32602 errors. This allows LLMs to see the validation error and self-correct,
per the MCP spec.

The existing pattern for handler-returned errors (lines 347-350 in server.go)
already converts regular errors to tool results with IsError=true. This change
applies the same pattern to argument schema validation and unmarshal errors,
resolving the TODO(#450) in the code.

Thanks to @iwyrkore for filing the issue and proposing the approach, and
@findleyr for the cross-SDK analysis in the discussion.

Fixes #450

ravyg and others added 2 commits March 27, 2026 13:58
Input validation errors (missing required fields, wrong types) during
tool calls are now returned as CallToolResult with IsError=true instead
of JSON-RPC -32602 errors. This allows LLMs to see the validation error
and self-correct, per the MCP spec.

Fixes modelcontextprotocol#450
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.

SEP-1303: Input Validation Errors as Tool Execution Errors

1 participant