The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 23:30 UTC
fix(server): MCP tools reject top-level arguments they do not declare (#26721)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Nov 11, 2026 at 11:50 UTC
184bb3950f62f4b918897dc2d7f206f8af04cf5c
4 files changed
+130
-18
apps/server/src/mcp/McpDeviceToolkit.test.ts
+13
@@ -571,6 +571,19 @@ describe("device targeting across hosts", () => {
571
),
572
);
573
574
+ it.effect("names a device_screenshot argument the tool does not declare", () =>
575
+ run([session("mac-mini", "MAC-UDID", "ios")], ({ call }) =>
576
+ Effect.gen(function* () {
577
+ const result = yield* call("device_screenshot", {
578
+ deviceId: "MAC-UDID",
579
+ includeImage: false,
580
+ });
581
+ expect(result.isError).toBe(true);
582
+ expect(text(result)).toContain('Unknown argument "includeImage"');
583
+ }),
584
+ ),
585
+ );
586
+
587
it.effect("tells an agent to open a device id before screenshotting it", () =>
588
run([], ({ call }) =>
589
Effect.gen(function* () {
apps/server/src/mcp/McpHttpServer.test.ts
+65
-1
@@ -30,6 +30,11 @@ import { McpSchema, McpServer, Tool, Toolkit } from "effect/ai";
30
import { HttpBody, HttpClient, HttpClientRequest, HttpRouter } from "effect/http";
31
32
import * as ProjectService from "../project/ProjectService.ts";
33
+import * as ManagedProjectFolders from "../project/ManagedProjectFolders.ts";
34
+import * as ThreadLaunchService from "../orchestration-v2/ThreadLaunchService.ts";
35
+import * as DocumentText from "../provider/DocumentText.ts";
36
+import * as ProviderRegistry from "../provider/ProviderRegistry.ts";
37
+import * as GitVcsDriver from "../vcs/GitVcsDriver.ts";
38
import * as EnvironmentAuth from "../auth/EnvironmentAuth.ts";
39
import * as McpOAuth from "../auth/McpOAuth.ts";
40
import * as ServerSecretStore from "../auth/ServerSecretStore.ts";
@@ -271,6 +276,7 @@ const layerRecordingTools = (calls: Array<unknown>) => {
276
OrchestratorToolkit.tools.t3_thread_read,
277
OrchestratorToolkit.tools.t3_thread_wait,
278
ProjectToolkit.tools.t3_project_update,
279
+ ProjectToolkit.tools.t3_thread_launch,
280
);
281
const record = McpToolAccess.reads((params: unknown) =>
282
Effect.sync(() => calls.push(params)).pipe(
@@ -286,6 +292,7 @@ const layerRecordingTools = (calls: Array<unknown>) => {
292
t3_thread_read: record,
293
t3_thread_wait: record,
294
t3_project_update: record,
295
+ t3_thread_launch: record,
296
}),
297
).pipe(
298
Layer.provideMerge(McpHttpServer.layerInProcessMcpServer),
@@ -294,10 +301,19 @@ const layerRecordingTools = (calls: Array<unknown>) => {
301
McpToolAccessTestkit.liveThreadsLayer,
302
Layer.mock(OrchestratorMcpService.OrchestratorMcpService)({}),
303
Layer.mock(ProjectService.ProjectService)({}),
297
- NodeServices.layer,
304
+ Layer.mock(ThreadLaunchService.ThreadLaunchService)({}),
305
+ Layer.mock(ManagedProjectFolders.ManagedProjectFolders)({
306
+ namedProjectsRoot: process.cwd(),
307
+ }),
308
+ Layer.mock(GitVcsDriver.GitVcsDriver)({}),
309
+ Layer.mock(ServerSettings.ServerSettingsService)({}),
310
+ Layer.mock(DocumentText.DocumentText)({}),
311
+ Layer.mock(ProviderRegistry.ProviderRegistry)({}),
312
+ ServerConfig.layerTest(process.cwd(), { prefix: "t3-mcp-http-server-test-" }),
313
NodeCrypto.layer,
314
),
315
),
316
+ Layer.provideMerge(NodeServices.layer),
317
);
318
};
319
@@ -576,6 +592,22 @@ it.effect("checks each preview_act action against that action's own input", () =
592
).pipe(Effect.provide(layerTest)),
593
);
594
595
+it.effect("rejects a hand-registered tool's undeclared argument before asking the browser", () =>
596
+ Effect.scoped(
597
+ Effect.gen(function* () {
598
+ const inputs = yield* serveSnapshots("mcp-excess-argument-client", snapshotResult);
599
+
600
+ const snapshot = yield* callSnapshot({ includeImages: true });
601
+
602
+ expect(inputs).toEqual([]);
603
+ expect(snapshot.isError).toBe(true);
604
+ expect(snapshot.content).toEqual([
605
+ { type: "text", text: expect.stringContaining('Unknown argument "includeImages"') },
606
+ ]);
607
+ }),
608
+ ).pipe(Effect.provide(layerTest)),
609
+);
610
+
611
it.effect("decodes null optional arguments the way it decodes omitted ones", () => {
612
const calls: Array<unknown> = [];
613
return Effect.gen(function* () {
@@ -593,6 +625,38 @@ it.effect("decodes null optional arguments the way it decodes omitted ones", ()
625
}).pipe(Effect.provide(layerRecordingTools(calls)));
626
});
627
628
+it.effect("rejects arguments a tool does not declare instead of dropping them", () => {
629
+ const calls: Array<unknown> = [];
630
+ return Effect.gen(function* () {
631
+ const launch = yield* Effect.flip(
632
+ callTool("t3_thread_launch", { title: "Repro", scratch: true, prompt: "say hi" }),
633
+ );
634
+ const wait = yield* Effect.flip(
635
+ callTool("t3_thread_wait", { threadId: "thread-excess-arguments", timeout: 5_000 }),
636
+ );
637
+
638
+ expect(calls).toEqual([]);
639
+ expect(launch.message).toContain('Unknown argument "prompt"');
640
+ expect(wait.message).toContain('Unknown argument "timeout"');
641
+ }).pipe(Effect.provide(layerRecordingTools(calls)));
642
+});
643
+
644
+it.effect("accepts a nested key the merged advertised schema shows", () => {
645
+ const calls: Array<unknown> = [];
646
+ return Effect.gen(function* () {
647
+ yield* Effect.exit(
648
+ callTool("t3_thread_launch", {
649
+ title: "Root",
650
+ projectId: "project-1",
651
+ message: "say hi",
652
+ workspaceStrategy: { type: "root", baseRef: "main" },
653
+ }),
654
+ );
655
+
656
+ expect(calls).toHaveLength(1);
657
+ }).pipe(Effect.provide(layerRecordingTools(calls)));
658
+});
659
+
660
it.effect(
661
"clamps t3_thread_read page sizes above their maximum instead of rejecting the call",
662
() => {
apps/server/src/mcp/McpHttpServer.ts
+47
-15
@@ -7,6 +7,7 @@ import * as FileSystem from "effect/FileSystem";
7
import * as Layer from "effect/Layer";
8
import * as Option from "effect/Option";
9
import * as Path from "effect/Path";
10
+import * as Predicate from "effect/Predicate";
11
import * as Schema from "effect/Schema";
12
import * as Sink from "effect/Sink";
13
import * as Stream from "effect/Stream";
@@ -470,16 +471,50 @@ const saveScreenshot = Effect.fn("McpHttpServer.saveScreenshot")(function* (
471
return screenshotPath;
472
});
473
474
+const MAX_NAMED_ARGUMENTS = 5;
475
+const MAX_ARGUMENT_NAME_CHARS = 64;
476
+
477
+/**
478
+ * Rejects top-level arguments the advertised schema does not list, naming them. Nested objects stay lenient:
479
+ * the advertised schema merges tagged unions, so strict decoding would reject keys agents were shown.
480
+ */
481
+const advertisedArgumentsOnly = (tool: Tool.Any) => {
482
+ const { properties } = advertisedJsonSchema(tool);
483
+ const accepted = new Set(Predicate.isObject(properties) ? Object.keys(properties) : []);
484
+ const acceptedText = [...accepted].join(", ") || "none";
485
+ return Schema.Record(Schema.String, Schema.Unknown).check(
486
+ Schema.makeFilter((input) => {
487
+ const unknown = Object.keys(input).filter((key) => !accepted.has(key));
488
+ if (unknown.length === 0) return undefined;
489
+ const named = unknown
490
+ .slice(0, MAX_NAMED_ARGUMENTS)
491
+ .map((key) => JSON.stringify(cutText(key, MAX_ARGUMENT_NAME_CHARS)));
492
+ const more =
493
+ unknown.length > named.length ? ` and ${unknown.length - named.length} more` : "";
494
+ return `Unknown argument${unknown.length === 1 ? "" : "s"} ${named.join(", ")}${more}. Accepted arguments: ${acceptedText}.`;
495
+ }),
496
+ );
497
+};
498
+
499
/** Decode with the advertised JSON codec, which permits null for optional fields that the raw schema rejects. */
500
const decodeAsAdvertised = <Tools extends Record<string, Tool.Any>>(
501
toolkit: Toolkit.Toolkit<Tools>,
502
): Toolkit.Toolkit<Tools> =>
503
Toolkit.make(
504
...Object.values(toolkit.tools).map((tool) =>
479
- tool.setParameters(Schema.toCodecJson(tool.parametersSchema)),
505
+ tool.setParameters(
506
+ advertisedArgumentsOnly(tool).pipe(
507
+ Schema.decodeTo(Schema.toCodecJson(tool.parametersSchema)),
508
+ ),
509
+ ),
510
),
511
) as unknown as Toolkit.Toolkit<Tools>;
512
513
+const parameterValidationMessage = (error: unknown) =>
514
+ AiError.isAiError(error) && error.reason._tag === "ToolParameterValidationError"
515
+ ? error.reason.message
516
+ : undefined;
517
+
518
const isPreviewAutomationError = Schema.is(PreviewAutomationError);
519
520
const previewSnapshotFailure = Effect.fn("previewSnapshotFailure")(function <E>(
@@ -498,7 +533,9 @@ const previewSnapshotFailure = Effect.fn("previewSnapshotFailure")(function <E>(
533
? firstFailure._tag
534
: "PreviewSnapshotError";
535
// Preview errors contain server-authored recovery guidance, never page output.
501
- const message = isPreviewAutomationError(firstFailure) ? firstFailure.message : undefined;
536
+ const message = isPreviewAutomationError(firstFailure)
537
+ ? firstFailure.message
538
+ : parameterValidationMessage(firstFailure);
539
const result = new McpSchema.CallToolResult({
540
isError: true,
541
structuredContent: {
@@ -749,9 +786,6 @@ const registerImageTool = Effect.fn("McpHttpServer.registerImageTool")(function*
786
onFailure: imageToolFailure(tool.name, operation, failureText),
787
onSuccess: ({ encodedResult }) => {
788
const { screenshot, ...rest } = encodedResult as ImageToolResult;
752
- const includeImage =
753
- (payload as { readonly includeImage?: boolean } | undefined)?.includeImage !==
754
- false;
789
const metadata = {
790
...rest,
791
screenshot: {
@@ -766,15 +800,11 @@ const registerImageTool = Effect.fn("McpHttpServer.registerImageTool")(function*
800
structuredContent: metadata,
801
content: [
802
{ type: "text", text: JSON.stringify(metadata) },
769
- ...(includeImage
770
- ? [
771
- {
772
- type: "image" as const,
773
- data: new Uint8Array(Buffer.from(screenshot.data, "base64")),
774
- mimeType: screenshot.mimeType,
775
- },
776
- ]
777
- : []),
803
+ {
804
+ type: "image" as const,
805
+ data: new Uint8Array(Buffer.from(screenshot.data, "base64")),
806
+ mimeType: screenshot.mimeType,
807
+ },
808
],
809
}),
810
);
@@ -803,7 +833,9 @@ const registerDeviceScreenshot = Effect.fn("McpHttpServer.registerDeviceScreensh
833
"screenshot",
834
(error) => {
835
if (!isDeviceToolError(error)) {
806
- return isOrchestratorMcpFailure(error) ? error.message : "Device screenshot failed.";
836
+ return isOrchestratorMcpFailure(error)
837
+ ? error.message
838
+ : (parameterValidationMessage(error) ?? "Device screenshot failed.");
839
}
840
return error._tag === "DeviceOperationError" && error.reason === "hub_rejected"
841
? `${error.message} Call device_list to check the device state, and device_open if it needs to be reopened.`
apps/server/src/mcp/toolkits/core.test.ts
+5
-2
@@ -285,7 +285,10 @@ it.effect("returns an HTML render reference that Codex and Claude tool rows both
285
server
286
.callTool({
287
name,
288
- arguments: { path: "/t3-missing-dir/revenue.html", title: "Revenue", height: 240 },
288
+ arguments: {
289
+ path: "/t3-missing-dir/revenue.html",
290
+ ...(name === "html_render" ? { title: "Revenue", height: 240 } : {}),
291
+ },
292
})
293
.pipe(
294
Effect.provideService(McpInvocationContext.McpInvocationContext, caller),
@@ -402,7 +405,7 @@ it.effect("rejects an unknown organize target instead of archiving the calling t
405
expect(dispatched).toEqual([]);
406
expect(outcome).toMatchObject({
407
_tag: "Failure",
405
- failure: { message: expect.stringContaining("Expected no excess property") },
408
+ failure: { message: expect.stringContaining('Unknown argument "threadIds"') },
409
});
410
}).pipe(
411
Effect.provide(