The best way to control Claude Code, Codex and more from any computer or phone
fix(server): t3_thread_read clamps oversized page sizes instead of failing (#22901)
Co-authored-by: fixfon <12512757+fixfon@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: grey-tsosie <45133231+grey-tsosie@users.noreply.github.com>
Theo Browne committed
Oct 21, 2026 at 14:12 UTC
ee11fbd971b2f94d7ba2ec411a36581671f8494a
3 files changed
+86
-3
apps/server/src/mcp/McpHttpServer.test.ts
+47
@@ -375,6 +375,53 @@ it.effect("decodes null optional arguments the way it decodes omitted ones", ()
375
}).pipe(Effect.provide(layerRecordingTools(calls)));
376
});
377
378
+it.effect(
379
+ "clamps t3_thread_read page sizes above their maximum instead of rejecting the call",
380
+ () => {
381
+ const calls: Array<unknown> = [];
382
+ return Effect.gen(function* () {
383
+ const thread = { threadId: "thread-clamped-arguments" };
384
+ // Codex never shows the model these bounds, so an over-large page must still read.
385
+ yield* callTool("t3_thread_read", {
386
+ ...thread,
387
+ limit: 150,
388
+ runLimit: 80,
389
+ maxCharsPerItem: 60_000,
390
+ });
391
+ yield* callTool("t3_thread_read", {
392
+ ...thread,
393
+ limit: 100,
394
+ runLimit: 50,
395
+ maxCharsPerItem: 50_000,
396
+ });
397
+ yield* callTool("t3_thread_read", { ...thread, limit: 7, runLimit: 1, maxCharsPerItem: 1 });
398
+
399
+ expect(calls).toEqual([
400
+ { ...thread, limit: 100, runLimit: 50, maxCharsPerItem: 50_000 },
401
+ { ...thread, limit: 100, runLimit: 50, maxCharsPerItem: 50_000 },
402
+ { ...thread, limit: 7, runLimit: 1, maxCharsPerItem: 1 },
403
+ ]);
404
+ }).pipe(Effect.provide(layerRecordingTools(calls)));
405
+ },
406
+);
407
+
408
+it.effect.each(["limit", "runLimit", "maxCharsPerItem"])(
409
+ "still rejects a t3_thread_read %s below its minimum",
410
+ (field) => {
411
+ const calls: Array<unknown> = [];
412
+ return Effect.gen(function* () {
413
+ // Zero is a different request than one item, so it fails rather than answering another question.
414
+ const rejected = yield* callTool("t3_thread_read", {
415
+ threadId: "thread-below-minimum",
416
+ [field]: 0,
417
+ }).pipe(Effect.flip);
418
+
419
+ expect(String(rejected)).toContain("greater than or equal to 1");
420
+ expect(calls).toEqual([]);
421
+ }).pipe(Effect.provide(layerRecordingTools(calls)));
422
+ },
423
+);
424
+
425
it.effect(
426
"registers the pull request toolkit and surfaces a missing capability as a tool error",
427
() =>
apps/server/src/mcp/toolkits/orchestrator/tools.test.ts
new
+16
@@ -0,0 +1,16 @@
1
+import { expect, it } from "@effect/vitest";
2
+import { Tool } from "effect/ai";
3
+
4
+import { OrchestratorToolkit } from "./tools.ts";
5
+
6
+// Oversized page sizes clamp on decode, so the schema has no `maximum`; Codex also drops
7
+// bounds from its TypeScript view. The description is the only place a model sees a limit.
8
+it("states t3_thread_read page size limits in the parameter descriptions", () => {
9
+ const schema = Tool.getJsonSchema(OrchestratorToolkit.tools.t3_thread_read) as {
10
+ readonly properties: Readonly<Record<string, { readonly description?: string }>>;
11
+ };
12
+ const limits = { limit: "100", runLimit: "50", maxCharsPerItem: "50000" };
13
+ for (const [name, maximum] of Object.entries(limits)) {
14
+ expect(schema.properties[name]?.description, name).toContain(maximum);
15
+ }
16
+});
packages/contracts/src/orchestratorMcp.ts
+23
-3
@@ -363,15 +363,35 @@ export const OrchestratorMcpThreadListResult = Schema.Struct({
363
});
364
export type OrchestratorMcpThreadListResult = typeof OrchestratorMcpThreadListResult.Type;
365
366
+// Codex hides `minimum` and `maximum` from the model, so a value above the maximum clamps on
367
+// decode instead of failing the call; pagination returns the rest. Values below 1 still fail:
368
+// 0 asks for nothing, and answering it with one item would be a different request.
369
+const clampedPositiveInt = (maximum: number) =>
370
+ PositiveInt.pipe(
371
+ Schema.decodeTo(
372
+ PositiveInt.check(Schema.isLessThanOrEqualTo(maximum)),
373
+ SchemaTransformation.transform({
374
+ decode: (value) => Math.min(value, maximum),
375
+ encode: (value) => value,
376
+ }),
377
+ ),
378
+ );
379
+
380
export const OrchestratorMcpThreadReadInput = Schema.Struct({
381
threadId: ThreadId,
382
itemId: Schema.optional(TurnItemId),
383
textOffset: Schema.optional(NonNegativeInt),
384
view: Schema.optional(Schema.Literals(["messages", "activity"])),
385
afterPosition: Schema.optional(NonNegativeInt),
372
- limit: Schema.optional(PositiveInt.check(Schema.isLessThanOrEqualTo(100))),
373
- runLimit: Schema.optional(PositiveInt.check(Schema.isLessThanOrEqualTo(50))),
374
- maxCharsPerItem: Schema.optional(PositiveInt.check(Schema.isLessThanOrEqualTo(50_000))),
386
+ limit: Schema.optional(clampedPositiveInt(100)).annotate({
387
+ description: "Maximum timeline items to return, from 1 to 100.",
388
+ }),
389
+ runLimit: Schema.optional(clampedPositiveInt(50)).annotate({
390
+ description: "Maximum recent runs to return, from 1 to 50.",
391
+ }),
392
+ maxCharsPerItem: Schema.optional(clampedPositiveInt(50_000)).annotate({
393
+ description: "Maximum text characters per item, from 1 to 50000.",
394
+ }),
395
});
396
export type OrchestratorMcpThreadReadInput = typeof OrchestratorMcpThreadReadInput.Type;
397