Skip to content

Conversation

@codewithkenzo
Copy link

Summary

Fixes #1385

When a task-augmented tools/call request fails validation, the error was being masked by "Invalid task creation result" instead of showing the actual error message.

The Problem

  1. Task-augmented request fails (e.g., InvalidParams)
  2. Error is caught in mcp.ts and wrapped via createToolError() → returns { isError: true }
  3. In server.ts, result is validated against CreateTaskResultSchema
  4. Validation fails because { isError: true } doesn't have a task property
  5. User sees: "Invalid task creation result: ..." instead of the actual validation error

The Fix

Re-throw all McpError types for task-augmented requests instead of wrapping them in createToolError(). This allows protocol-level errors to propagate correctly rather than being masked by task result validation.

} catch (error) {
    // For task-augmented requests, re-throw McpErrors to avoid masking
    // them with "Invalid task creation result" errors in server.ts
    if (request.params.task && error instanceof McpError) {
        throw error;
    }
    if (error instanceof McpError && error.code === ErrorCode.UrlElicitationRequired) {
        throw error;
    }
    return this.createToolError(error instanceof Error ? error.message : String(error));
}

Rationale

This follows established RPC patterns (JSON-RPC, gRPC, tRPC) where validation errors are protocol-level errors, not application results. The MCP spec also distinguishes between:

  • Tool execution errorsisError: true (so LLM can see and self-correct)
  • Protocol/exceptional errors → Protocol-level error response

Task result validation failures fall into the "exceptional conditions" category and should propagate as protocol errors.

Testing

  • Typecheck passes
  • Existing task lifecycle integration tests pass
  • Pre-existing test failure in authExtensions.test.ts is unrelated (exists on main)

Re-throw McpErrors for task-augmented requests to avoid masking them
with 'Invalid task creation result' errors in server.ts validation.

The issue occurs when a task-augmented tools/call request fails validation:
1. Error is caught in mcp.ts and wrapped via createToolError()
2. Result is validated against CreateTaskResultSchema in server.ts
3. Validation fails because the error result lacks a task property
4. User sees 'Invalid task creation result' instead of the actual error

This fix re-throws all McpError types for task-augmented requests,
allowing the actual error to propagate instead of being masked.

Fixes modelcontextprotocol#1385
@codewithkenzo codewithkenzo requested a review from a team as a code owner February 2, 2026 14:52
@changeset-bot
Copy link

changeset-bot bot commented Feb 2, 2026

🦋 Changeset detected

Latest commit: 1c50f99

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@modelcontextprotocol/server Patch
@modelcontextprotocol/express Patch
@modelcontextprotocol/hono Patch
@modelcontextprotocol/node Patch

Not sure what this means? Click here to learn what changesets are.

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

@codewithkenzo
Copy link
Author

This follows up on my comment in #1385. Based on further analysis, I expanded the fix to re-throw all McpError types for task-augmented requests (not just InvalidParams) since any protocol-level error would hit the same masking issue.

Happy to adjust if maintainers prefer a narrower scope.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 2, 2026

Open in StackBlitz

@modelcontextprotocol/client

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

@modelcontextprotocol/server

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

@modelcontextprotocol/express

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

@modelcontextprotocol/hono

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

@modelcontextprotocol/node

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

commit: 1c50f99

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