fix: surface input validation errors for task-augmented tool calls#1664
Open
Vadaski wants to merge 2 commits intomodelcontextprotocol:mainfrom
Open
fix: surface input validation errors for task-augmented tool calls#1664Vadaski wants to merge 2 commits intomodelcontextprotocol:mainfrom
Vadaski wants to merge 2 commits intomodelcontextprotocol:mainfrom
Conversation
…odelcontextprotocol#1385) When a task-augmented tools/call request fails input schema validation, the ProtocolError was being caught and wrapped into a CallToolResult (isError: true), which then failed CreateTaskResultSchema validation in server.ts, producing a confusing "Invalid task creation result" error that masked the actual validation failure. Now mcp.ts re-throws input-validation ProtocolErrors for task-augmented calls so clients receive the real error message (e.g. "Input validation error: Invalid arguments for tool X: Too small: expected number to be >=500"). Fixes modelcontextprotocol#1385 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@modelcontextprotocol/client
@modelcontextprotocol/server
@modelcontextprotocol/express
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a task-augmented
tools/callrequest fails input schema validation, the error is caught inMcpServer._setupToolHandlersand converted to aCallToolResultwithisError: true. This result then failsCreateTaskResultSchemavalidation inserver.ts, producing a misleading"Invalid task creation result"error that completely masks the actual validation failure.Example
{ "method": "tools/call", "params": { "name": "batch_process", "arguments": { "itemCount": 5, "processingTimeMs": 100 }, "task": { "ttl": 60000 } } }Before — client receives:
{ "code": -32602, "message": "Invalid task creation result: ..." }After — client receives the real error:
{ "code": -32602, "message": "Input validation error: Invalid arguments for tool batch_process: Too small: expected number to be >=500" }Fix
In
mcp.ts, the catch block now re-throwsInvalidParamsProtocolErrors that originated from input validation (identified by the"Input validation error:"message prefix set invalidateToolInput) when the request is task-augmented. This is targeted to avoid changing semantics for non-validation errors.Testing
Added a regression test in
test/integration/test/server/mcp.test.tsthat:z.number().min(500)validationduration: 100) and task augmentationcode: -32602with the real validation message"Invalid task creation result"Fixes #1385