Skip to content

fix: surface input validation errors for task-augmented tool calls#1664

Open
Vadaski wants to merge 2 commits intomodelcontextprotocol:mainfrom
Vadaski:fix/1385-task-augmented-error-masking
Open

fix: surface input validation errors for task-augmented tool calls#1664
Vadaski wants to merge 2 commits intomodelcontextprotocol:mainfrom
Vadaski:fix/1385-task-augmented-error-masking

Conversation

@Vadaski
Copy link

@Vadaski Vadaski commented Mar 12, 2026

Problem

When a task-augmented tools/call request fails input schema validation, the error is caught in McpServer._setupToolHandlers and converted to a CallToolResult with isError: true. This result then fails CreateTaskResultSchema validation in server.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-throws InvalidParams ProtocolErrors that originated from input validation (identified by the "Input validation error:" message prefix set in validateToolInput) 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.ts that:

  • Registers a task-based tool with z.number().min(500) validation
  • Calls it with an invalid argument (duration: 100) and task augmentation
  • Asserts the client receives code: -32602 with the real validation message
  • Asserts the error does NOT say "Invalid task creation result"

Fixes #1385

…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>
@Vadaski Vadaski requested a review from a team as a code owner March 12, 2026 04:09
@changeset-bot
Copy link

changeset-bot bot commented Mar 12, 2026

⚠️ No Changeset found

Latest commit: 1792369

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 12, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/client@1664

@modelcontextprotocol/server

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/server@1664

@modelcontextprotocol/express

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/express@1664

@modelcontextprotocol/hono

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/hono@1664

@modelcontextprotocol/node

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/node@1664

commit: 0e534b3

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.

Task-augmented tool call errors are wrapped incorrectly, masking actual error messages

1 participant