From 1c50f995f5e1ce82d725b52ab78305c8ba25ed1d Mon Sep 17 00:00:00 2001 From: codewithkenzo <115878491+codewithkenzo@users.noreply.github.com> Date: Mon, 2 Feb 2026 15:52:09 +0100 Subject: [PATCH] fix: prevent task-augmented tool errors from being masked 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 #1385 --- .changeset/task-error-masking.md | 11 +++++++++++ packages/server/src/server/mcp.ts | 7 ++++++- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 .changeset/task-error-masking.md diff --git a/.changeset/task-error-masking.md b/.changeset/task-error-masking.md new file mode 100644 index 000000000..3b963e85e --- /dev/null +++ b/.changeset/task-error-masking.md @@ -0,0 +1,11 @@ +--- +"@modelcontextprotocol/server": patch +--- + +fix: prevent task-augmented tool errors from being masked + +Re-throw McpErrors for task-augmented requests instead of wrapping them +in createToolError(). This prevents protocol errors from being masked +by "Invalid task creation result" errors during CreateTaskResultSchema validation. + +Fixes #1385 diff --git a/packages/server/src/server/mcp.ts b/packages/server/src/server/mcp.ts index 975cca257..8f91c33ef 100644 --- a/packages/server/src/server/mcp.ts +++ b/packages/server/src/server/mcp.ts @@ -224,8 +224,13 @@ export class McpServer { await this.validateToolOutput(tool, result, request.params.name); return result; } 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 the error to the caller without wrapping in CallToolResult + throw error; } return this.createToolError(error instanceof Error ? error.message : String(error)); }