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)); }