@devries-cameron20 / t3code-1 / commits / f7b0b3c4d7
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): MCP list tools clamp an oversized limit instead of failing (#30976)

Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>

MarcoDotIO committed Nov 14, 2026 at 20:00 UTC f7b0b3c4d730fbf40b87465523631a7d3ac33472
6 files changed +40 -16
apps/server/src/mcp/McpHttpServer.test.ts
+32 -11
@@ -43,6 +43,7 @@ import * as ServerSecretStore from "../auth/ServerSecretStore.ts";
43 import * as ServerEnvironment from "../environment/ServerEnvironment.ts";
44 import * as Sqlite from "../persistence/Sqlite.ts";
45 import * as ManagedPolicy from "../policy/ManagedPolicy.ts";
46 +import * as PreviewManager from "../preview/Manager.ts";
47
48 import * as DeviceService from "../device/DeviceService.ts";
49 import * as PullRequestReviewGuideService from "../pullRequest/PullRequestReviewGuideService.ts";
@@ -59,7 +60,9 @@ import * as OrchestratorMcpService from "./OrchestratorMcpService.ts";
60 import * as PreviewAutomationBroker from "./PreviewAutomationBroker.ts";
61 import { OrchestratorToolkit } from "./toolkits/orchestrator/tools.ts";
62 import { PreviewToolkit } from "./toolkits/preview/tools.ts";
63 +import { PreviewControlsToolkit } from "./toolkits/previewControls/tools.ts";
64 import { ProjectToolkit } from "./toolkits/project/tools.ts";
65 +import { ThreadToolkit } from "./toolkits/thread/tools.ts";
66
67 const environmentId = EnvironmentId.make("environment-mcp-test");
68 const threadId = ThreadId.make("thread-mcp-test");
@@ -295,7 +298,10 @@ const layerRecordingTools = (calls: Array<unknown>) => {
298 OrchestratorToolkit.tools.t3_thread_list,
299 OrchestratorToolkit.tools.t3_thread_read,
300 OrchestratorToolkit.tools.t3_thread_wait,
301 + ProjectToolkit.tools.t3_project_list,
302 ProjectToolkit.tools.t3_project_update,
303 + ThreadToolkit.tools.t3_queue,
304 + PreviewControlsToolkit.tools.t3_preview_list,
305 ProjectToolkit.tools.t3_thread_launch,
306 );
307 const record = McpToolAccess.reads((params: unknown) =>
@@ -312,7 +318,10 @@ const layerRecordingTools = (calls: Array<unknown>) => {
318 t3_thread_list: record,
319 t3_thread_read: record,
320 t3_thread_wait: record,
321 + t3_project_list: record,
322 t3_project_update: record,
323 + t3_queue: record,
324 + t3_preview_list: record,
325 t3_thread_launch: record,
326 }),
327 ).pipe(
@@ -322,6 +331,8 @@ const layerRecordingTools = (calls: Array<unknown>) => {
331 McpToolAccessTestkit.liveThreadsLayer,
332 Layer.mock(OrchestratorMcpService.OrchestratorMcpService)({}),
333 Layer.mock(ProjectService.ProjectService)({}),
334 + Layer.mock(PreviewManager.PreviewManager)({}),
335 + Layer.mock(PreviewAutomationBroker.PreviewAutomationBroker)({}),
336 Layer.mock(ThreadLaunchService.ThreadLaunchService)({}),
337 Layer.mock(ManagedProjectFolders.ManagedProjectFolders)({
338 namedProjectsRoot: process.cwd(),
@@ -749,18 +760,28 @@ it.effect.each(["limit", "runLimit", "maxCharsPerItem"])(
760 },
761 );
762
752 -it.effect("clamps a t3_thread_list limit above its maximum instead of rejecting the call", () => {
753 - const calls: Array<unknown> = [];
754 - return Effect.gen(function* () {
755 - yield* callTool("t3_thread_list", { allProjects: true, limit: 200 });
756 - yield* callTool("t3_thread_list", { allProjects: true, limit: 7 });
763 +const clampedListLimits = [
764 + { tool: "t3_thread_list", input: { allProjects: true }, maximum: 100 },
765 + { tool: "t3_project_list", input: {}, maximum: 100 },
766 + { tool: "t3_queue", input: { action: "list" }, maximum: 100 },
767 + { tool: "t3_preview_list", input: {}, maximum: 50 },
768 +];
769
758 - expect(calls).toEqual([
759 - { allProjects: true, limit: 100 },
760 - { allProjects: true, limit: 7 },
761 - ]);
762 - }).pipe(Effect.provide(layerRecordingTools(calls)));
763 -});
770 +it.effect.each(clampedListLimits)(
771 + "clamps a $tool limit above its maximum instead of rejecting the call",
772 + ({ tool, input, maximum }) => {
773 + const calls: Array<unknown> = [];
774 + return Effect.gen(function* () {
775 + yield* callTool(tool, { ...input, limit: maximum * 2 });
776 + yield* callTool(tool, { ...input, limit: 7 });
777 +
778 + expect(calls).toEqual([
779 + { ...input, limit: maximum },
780 + { ...input, limit: 7 },
781 + ]);
782 + }).pipe(Effect.provide(layerRecordingTools(calls)));
783 + },
784 +);
785
786 it("keeps cross-tool routing out of the delegate_task description", () => {
787 const description = OrchestratorToolkit.tools.delegate_task.description ?? "";
apps/server/src/mcp/toolkits/previewControls/tools.ts
+2 -1
@@ -1,4 +1,5 @@
1 import {
2 + clampedPositiveInt,
3 NonNegativeInt,
4 OrchestratorMcpFailure,
5 PreviewAutomationError,
@@ -28,7 +29,7 @@ const PreviewListTool = Tool.make("t3_preview_list", {
29 "List this thread's preview tabs. Only `runtime:'server'` entries can be automated here. Others are in the user's local desktop app. Never pass a non-server `tabId` to a `preview_*` tool. Tell the user that tab is on their local desktop and this environment cannot reach it.",
30 parameters: Schema.Struct({
31 cursor: Schema.optional(NonNegativeInt),
31 - limit: Schema.optional(Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 50 }))),
32 + limit: Schema.optional(clampedPositiveInt(50)),
33 }),
34 success: Schema.Struct({
35 ...PreviewListResult.fields,
apps/server/src/mcp/toolkits/project/tools.ts
+2 -1
@@ -1,5 +1,6 @@
1 import { McpAttachmentInput } from "../attachment/input.ts";
2 import {
3 + clampedPositiveInt,
4 NonNegativeInt,
5 ModelSelection,
6 TrimmedNonEmptyString,
@@ -55,7 +56,7 @@ const ProjectListTool = Tool.make("t3_project_list", {
56 parameters: Schema.Struct({
57 environmentId: OrchestratorMcpEnvironmentTarget,
58 cursor: Schema.optional(NonNegativeInt),
58 - limit: Schema.optional(Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 100 }))),
59 + limit: Schema.optional(clampedPositiveInt(100)),
60 }),
61 success: Schema.Struct({
62 projects: Schema.Array(Project),
apps/server/src/mcp/toolkits/thread/tools.ts
+2 -1
@@ -19,6 +19,7 @@ import {
19 RunId,
20 NonNegativeInt,
21 ProjectId,
22 + clampedPositiveInt,
23 } from "@t3tools/contracts";
24 import * as SecureRandom from "effect/crypto/SecureRandom";
25 import * as Schema from "effect/Schema";
@@ -99,7 +100,7 @@ const QueueTool = Tool.make("t3_queue", {
100 beforeRunId: Schema.optional(Schema.NullOr(RunId)),
101 targetRunId: Schema.optional(RunId),
102 cursor: Schema.optional(NonNegativeInt),
102 - limit: Schema.optional(Schema.Int.check(Schema.isBetween({ minimum: 1, maximum: 100 }))),
103 + limit: Schema.optional(clampedPositiveInt(100)),
104 }),
105 success: Schema.Union([
106 Schema.Struct({ items: Schema.Array(queueEntry), nextCursor: Schema.NullOr(NonNegativeInt) }),
apps/server/src/provider/agentContextBudget.json
+1 -1
@@ -1,5 +1,5 @@
1 {
2 "claudeSystemAppendBytes": 5930,
3 "codexAdditionalContextBytes": 7324,
4 - "mcpToolListJsonBytes": 49790
4 + "mcpToolListJsonBytes": 49749
5 }
packages/contracts/src/orchestratorMcp.ts
+1 -1
@@ -343,7 +343,7 @@ export const OrchestratorMcpEnvironmentTarget = Schema.optional(
343 // Codex hides `minimum` and `maximum` from the model, so a value above the maximum clamps on
344 // decode instead of failing the call; pagination returns the rest. Values below 1 still fail:
345 // 0 asks for nothing, and answering it with one item would be a different request.
346 -const clampedPositiveInt = (maximum: number) =>
346 +export const clampedPositiveInt = (maximum: number) =>
347 PositiveInt.pipe(
348 Schema.decodeTo(
349 PositiveInt.check(Schema.isLessThanOrEqualTo(maximum)),