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 22, 14:30 UTC
fix(server): all MCP tools now send compact schemas, cutting tool context by 23% (#25790)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Theo Browne committed
Oct 26, 2026 at 23:59 UTC
bc813670d9c428fa42707a0d78c01e03177016ba
3 files changed
+47
-2
apps/server/src/mcp/McpHttpServer.test.ts
+14
@@ -21,6 +21,7 @@ import { HttpBody, HttpClient, HttpClientRequest, HttpRouter } from "effect/http
21
import * as ProjectService from "../project/ProjectService.ts";
22
import * as PullRequestReviewGuideService from "../pullRequest/PullRequestReviewGuideService.ts";
23
import * as ServerConfig from "../config.ts";
24
+import { advertisedJsonSchema } from "./advertisedJsonSchema.ts";
25
import * as McpHttpServer from "./McpHttpServer.ts";
26
import * as McpToolAccess from "./McpToolAccess.ts";
27
import * as McpToolAccessTestkit from "./McpToolAccess.testkit.ts";
@@ -29,6 +30,7 @@ import * as McpSessionRegistry from "./McpSessionRegistry.ts";
30
import * as OrchestratorMcpService from "./OrchestratorMcpService.ts";
31
import * as PreviewAutomationBroker from "./PreviewAutomationBroker.ts";
32
import { OrchestratorToolkit } from "./toolkits/orchestrator/tools.ts";
33
+import { PreviewToolkit } from "./toolkits/preview/tools.ts";
34
import { ProjectToolkit } from "./toolkits/project/tools.ts";
35
36
const environmentId = EnvironmentId.make("environment-mcp-test");
@@ -356,6 +358,18 @@ it.effect("refuses preview tools to a client outside a thread before they run",
358
}).pipe(Effect.provide(layerTest)),
359
);
360
361
+it.effect("advertises the compact input schema for every registered tool", () =>
362
+ Effect.gen(function* () {
363
+ const server = yield* McpServer.McpServer;
364
+ const tools: Record<string, Tool.Any> = PreviewToolkit.tools;
365
+
366
+ expect(server.tools.length).toBe(Object.keys(tools).length);
367
+ for (const { tool } of server.tools) {
368
+ expect(tool.inputSchema, tool.name).toEqual(advertisedJsonSchema(tools[tool.name]!));
369
+ }
370
+ }).pipe(Effect.provide(layerTest)),
371
+);
372
+
373
it.effect("checks each preview_act action against that action's own input", () =>
374
Effect.scoped(
375
Effect.gen(function* () {
apps/server/src/mcp/McpHttpServer.ts
+32
-1
@@ -948,6 +948,35 @@ const withToolAnalytics =
948
return yield* registration.pipe(Effect.provideService(McpServer.McpServer, recordingServer));
949
});
950
951
+/** `McpServer.registerToolkit` advertises the full codec schema; agents get the compact one. */
952
+const withAdvertisedSchemas = Effect.fn("McpHttpServer.withAdvertisedSchemas")(function* <
953
+ Tools extends Record<string, Tool.Any>,
954
+ A,
955
+ E,
956
+ R,
957
+>(toolkit: Toolkit.Toolkit<Tools>, registration: Effect.Effect<A, E, R>) {
958
+ const server = yield* McpServer.McpServer;
959
+ const tools: Record<string, Tool.Any> = toolkit.tools;
960
+ const advertisingServer = McpServer.McpServer.of({
961
+ ...server,
962
+ addTool: Effect.fn("McpServer.addTool")(function (options) {
963
+ const tool = tools[options.tool.name];
964
+ return server.addTool(
965
+ tool === undefined
966
+ ? options
967
+ : {
968
+ ...options,
969
+ tool: new McpSchema.Tool({
970
+ ...options.tool,
971
+ inputSchema: advertisedJsonSchema(tool),
972
+ }),
973
+ },
974
+ );
975
+ }),
976
+ });
977
+ return yield* registration.pipe(Effect.provideService(McpServer.McpServer, advertisingServer));
978
+});
979
+
980
/**
981
* `McpServer.toolkit` asks for every service its tools declare when it
982
* registers them, but the auth middleware provides `McpInvocationContext` to
@@ -959,7 +988,9 @@ export const toolkitRegistration = <Tools extends Record<string, Tool.Any>, EX,
988
handlers: McpToolAccess.HandlersLayer<Tools, EX, RX>,
989
) => {
990
const registration = Layer.effectDiscard(
962
- withToolAnalytics(McpServer.registerToolkit(decodeAsAdvertised(toolkit))),
991
+ withToolAnalytics(
992
+ withAdvertisedSchemas(toolkit, McpServer.registerToolkit(decodeAsAdvertised(toolkit))),
993
+ ),
994
).pipe(Layer.provide(McpServer.McpServer.layer));
995
// @effect-diagnostics-next-line unsafeEffectTypeAssertion:off - the auth middleware provides it per request.
996
const registered = registration as Layer.Layer<
apps/server/src/provider/agentContextBudget.json
+1
-1
@@ -1,5 +1,5 @@
1
{
2
"claudeSystemAppendBytes": 4857,
3
"codexAdditionalContextBytes": 5409,
4
- "mcpToolListJsonBytes": 54964
4
+ "mcpToolListJsonBytes": 42328
5
}