From 7f15ce26e76b5bc0f2866e7edcb09ae95baa81a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikl=C3=B3s=20Fazekas?= Date: Mon, 23 Nov 2026 10:58:14 +0100 Subject: [PATCH 1/2] fix(mcp): an invalid tool argument reaches claude.ai as a tool error naming it Under MCP 2025-06-18 an invalid tool argument becomes a JSON-RPC -32602 error, which claude.ai shows only as "the tool failed (unavailable)". Tool calls now return it as an isError result naming the bad argument on every protocol. Continuation calls keep the protocol error, and spans and analytics still record the original failure. --- apps/server/src/mcp/McpHttpServer.test.ts | 41 ++++++++++++++------- apps/server/src/mcp/McpHttpServer.ts | 44 +++++++++++++++++++++-- apps/server/src/mcp/toolkits/core.test.ts | 5 ++- 3 files changed, 72 insertions(+), 18 deletions(-) diff --git a/apps/server/src/mcp/McpHttpServer.test.ts b/apps/server/src/mcp/McpHttpServer.test.ts index 3b2cb665b3548..026e24ae48c67 100644 --- a/apps/server/src/mcp/McpHttpServer.test.ts +++ b/apps/server/src/mcp/McpHttpServer.test.ts @@ -192,6 +192,11 @@ const callTool = (name: string, args: Record) => ); }); +const invalidArgumentText = (result: McpSchema.CallToolResult) => { + expect(result.isError).toBe(true); + return result.content.map((part) => (part.type === "text" ? part.text : "")).join(""); +}; + const callSnapshot = (args: Record) => callTool("preview_snapshot", args); it.effect.each([ @@ -687,8 +692,10 @@ it.effect("decodes a JSON-stringified delegate target as the same object", () => yield* callTool("delegate_task", { task, target: JSON.stringify(target) }); for (const invalidTarget of ["{model:", '{"model":42}']) { - const error = yield* Effect.flip(callTool("delegate_task", { task, target: invalidTarget })); - expect(error).toBeInstanceOf(McpSchema.InvalidParams); + const rejected = yield* callTool("delegate_task", { task, target: invalidTarget }); + expect(invalidArgumentText(rejected)).toContain( + "Invalid parameters for tool 'delegate_task'", + ); } expect(calls).toHaveLength(2); expect(calls[0]).toEqual({ @@ -705,16 +712,26 @@ it.effect("decodes a JSON-stringified delegate target as the same object", () => it.effect("rejects arguments a tool does not declare instead of dropping them", () => { const calls: Array = []; return Effect.gen(function* () { - const launch = yield* Effect.flip( - callTool("t3_thread_launch", { title: "Repro", scratch: true, prompt: "say hi" }), - ); - const wait = yield* Effect.flip( - callTool("t3_thread_wait", { threadId: "thread-excess-arguments", timeout: 5_000 }), - ); + // A protocol error here reaches claude.ai only as "the tool failed (unavailable)". + const launch = yield* callTool("t3_thread_launch", { + title: "Repro", + scratch: true, + prompt: "say hi", + }); + const wait = yield* callTool("t3_thread_wait", { + threadId: "thread-excess-arguments", + timeout: 5_000, + }); + const read = yield* callTool("t3_thread_read", { + threadId: "thread-excess-arguments", + position: 5_100, + limit: 20, + }); expect(calls).toEqual([]); - expect(launch.message).toContain('Unknown argument "prompt"'); - expect(wait.message).toContain('Unknown argument "timeout"'); + expect(invalidArgumentText(launch)).toContain('Unknown argument "prompt"'); + expect(invalidArgumentText(wait)).toContain('Unknown argument "timeout"'); + expect(invalidArgumentText(read)).toContain('Unknown argument "position"'); }).pipe(Effect.provide(layerRecordingTools(calls))); }); @@ -773,9 +790,9 @@ it.effect.each(["limit", "runLimit", "maxCharsPerItem"])( const rejected = yield* callTool("t3_thread_read", { threadId: "thread-below-minimum", [field]: 0, - }).pipe(Effect.flip); + }); - expect(String(rejected)).toContain("greater than or equal to 1"); + expect(invalidArgumentText(rejected)).toContain("greater than or equal to 1"); expect(calls).toEqual([]); }).pipe(Effect.provide(layerRecordingTools(calls))); }, diff --git a/apps/server/src/mcp/McpHttpServer.ts b/apps/server/src/mcp/McpHttpServer.ts index be41f8630b7dd..cb79e59021bd4 100644 --- a/apps/server/src/mcp/McpHttpServer.ts +++ b/apps/server/src/mcp/McpHttpServer.ts @@ -1248,6 +1248,42 @@ const withToolSpans = Effect.fn("McpHttpServer.withToolSpans")(function* (registration: Effect.Effect) { + const server = yield* McpServer.McpServer; + const reportingServer = McpServer.McpServer.of({ + ...server, + addTool: Effect.fn("McpServer.addTool")(function (options) { + return server.addTool({ + ...options, + handle: (payload) => + options.handle(payload).pipe( + Effect.catchTags({ + InvalidParams: (error) => + Effect.serviceOption(McpSchema.McpRequestContext).pipe( + Effect.flatMap((request) => + Option.isSome(request) && + (request.value.requestState !== undefined || + request.value.inputResponses !== undefined) + ? Effect.fail(error) + : Effect.succeed( + new McpSchema.CallToolResult({ + isError: true, + content: [{ type: "text", text: error.message }], + }), + ), + ), + ), + }), + ), + }); + }), + }); + return yield* registration.pipe(Effect.provideService(McpServer.McpServer, reportingServer)); +}); + /** `McpServer.registerToolkit` advertises the full codec schema; agents get the compact one. */ const withAdvertisedSchemas = Effect.fn("McpHttpServer.withAdvertisedSchemas")(function* < Tools extends Record, @@ -1299,9 +1335,11 @@ export const toolkitRegistration = , EX, handlers: McpToolAccess.HandlersLayer, ) => Layer.effectDiscard( - withToolAnalytics( - withToolSpans( - withAdvertisedSchemas(toolkit, McpServer.registerToolkit(decodeAsAdvertised(toolkit))), + withInvalidArgumentsAsToolErrors( + withToolAnalytics( + withToolSpans( + withAdvertisedSchemas(toolkit, McpServer.registerToolkit(decodeAsAdvertised(toolkit))), + ), ), ), ).pipe( diff --git a/apps/server/src/mcp/toolkits/core.test.ts b/apps/server/src/mcp/toolkits/core.test.ts index 33c356af4e7e1..3ba2f971c73f4 100644 --- a/apps/server/src/mcp/toolkits/core.test.ts +++ b/apps/server/src/mcp/toolkits/core.test.ts @@ -606,12 +606,11 @@ it.effect("rejects an unknown organize target instead of archiving the calling t .pipe( Effect.provideService(McpInvocationContext.McpInvocationContext, scope), Effect.provideService(McpSchema.McpServerClient, client), - Effect.result, ); expect(dispatched).toEqual([]); expect(outcome).toMatchObject({ - _tag: "Failure", - failure: { message: expect.stringContaining('Unknown argument "threadIds"') }, + isError: true, + content: [{ type: "text", text: expect.stringContaining('Unknown argument "threadIds"') }], }); }).pipe( Effect.provide( From 287c391d407ca62dc76c6406ea178bdc2d94aa79 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 23 Nov 2026 10:51:45 +0000 Subject: [PATCH 2/2] test(mcp): drop a duplicate unknown-argument case Co-Authored-By: Claude Opus 5.5 --- apps/server/src/mcp/McpHttpServer.test.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/apps/server/src/mcp/McpHttpServer.test.ts b/apps/server/src/mcp/McpHttpServer.test.ts index 026e24ae48c67..aed212fe30395 100644 --- a/apps/server/src/mcp/McpHttpServer.test.ts +++ b/apps/server/src/mcp/McpHttpServer.test.ts @@ -722,16 +722,10 @@ it.effect("rejects arguments a tool does not declare instead of dropping them", threadId: "thread-excess-arguments", timeout: 5_000, }); - const read = yield* callTool("t3_thread_read", { - threadId: "thread-excess-arguments", - position: 5_100, - limit: 20, - }); expect(calls).toEqual([]); expect(invalidArgumentText(launch)).toContain('Unknown argument "prompt"'); expect(invalidArgumentText(wait)).toContain('Unknown argument "timeout"'); - expect(invalidArgumentText(read)).toContain('Unknown argument "position"'); }).pipe(Effect.provide(layerRecordingTools(calls))); });