Skip to content

Commit 1c50f99

Browse files
committed
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
1 parent b0ef89f commit 1c50f99

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

.changeset/task-error-masking.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
"@modelcontextprotocol/server": patch
3+
---
4+
5+
fix: prevent task-augmented tool errors from being masked
6+
7+
Re-throw McpErrors for task-augmented requests instead of wrapping them
8+
in createToolError(). This prevents protocol errors from being masked
9+
by "Invalid task creation result" errors during CreateTaskResultSchema validation.
10+
11+
Fixes #1385

packages/server/src/server/mcp.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,13 @@ export class McpServer {
224224
await this.validateToolOutput(tool, result, request.params.name);
225225
return result;
226226
} catch (error) {
227+
// For task-augmented requests, re-throw McpErrors to avoid masking
228+
// them with "Invalid task creation result" errors in server.ts
229+
if (request.params.task && error instanceof McpError) {
230+
throw error;
231+
}
227232
if (error instanceof McpError && error.code === ErrorCode.UrlElicitationRequired) {
228-
throw error; // Return the error to the caller without wrapping in CallToolResult
233+
throw error;
229234
}
230235
return this.createToolError(error instanceof Error ? error.message : String(error));
231236
}

0 commit comments

Comments
 (0)