GeezerVison is showing github.com — fix(server): all MCP tools now send compact schemas, cutting tool con… · aorwall/t3code@bc81367
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/server/src/mcp/McpHttpServer.test.ts +14Lines changed: 14 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -21,6 +21,7 @@ import { HttpBody, HttpClient, HttpClientRequest, HttpRouter } from "effect/http | 21 | 21 | import * as ProjectService from "../project/ProjectService.ts"; | 22 | 22 | import * as PullRequestReviewGuideService from "../pullRequest/PullRequestReviewGuideService.ts"; | 23 | 23 | import * as ServerConfig from "../config.ts"; | | 24 | +import { advertisedJsonSchema } from "./advertisedJsonSchema.ts"; | 24 | 25 | import * as McpHttpServer from "./McpHttpServer.ts"; | 25 | 26 | import * as McpToolAccess from "./McpToolAccess.ts"; | 26 | 27 | import * as McpToolAccessTestkit from "./McpToolAccess.testkit.ts"; | @@ -29,6 +30,7 @@ import * as McpSessionRegistry from "./McpSessionRegistry.ts"; | 29 | 30 | import * as OrchestratorMcpService from "./OrchestratorMcpService.ts"; | 30 | 31 | import * as PreviewAutomationBroker from "./PreviewAutomationBroker.ts"; | 31 | 32 | import { OrchestratorToolkit } from "./toolkits/orchestrator/tools.ts"; | | 33 | +import { PreviewToolkit } from "./toolkits/preview/tools.ts"; | 32 | 34 | import { ProjectToolkit } from "./toolkits/project/tools.ts"; | 33 | 35 |
| 34 | 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", | 356 | 358 | }).pipe(Effect.provide(layerTest)), | 357 | 359 | ); | 358 | 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 | + | 359 | 373 | it.effect("checks each preview_act action against that action's own input", () => | 360 | 374 | Effect.scoped( | 361 | 375 | Effect.gen(function* () { | |
Collapse file Copy file name to clipboardExpand all lines: apps/server/src/mcp/McpHttpServer.ts +32-1Lines changed: 32 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -948,6 +948,35 @@ const withToolAnalytics = | 948 | 948 | return yield* registration.pipe(Effect.provideService(McpServer.McpServer, recordingServer)); | 949 | 949 | }); | 950 | 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 | + | 951 | 980 | /** | 952 | 981 | * `McpServer.toolkit` asks for every service its tools declare when it | 953 | 982 | * registers them, but the auth middleware provides `McpInvocationContext` to | @@ -959,7 +988,9 @@ export const toolkitRegistration = <Tools extends Record<string, Tool.Any>, EX, | 959 | 988 | handlers: McpToolAccess.HandlersLayer<Tools, EX, RX>, | 960 | 989 | ) => { | 961 | 990 | const registration = Layer.effectDiscard( | 962 | | - withToolAnalytics(McpServer.registerToolkit(decodeAsAdvertised(toolkit))), | | 991 | + withToolAnalytics( | | 992 | + withAdvertisedSchemas(toolkit, McpServer.registerToolkit(decodeAsAdvertised(toolkit))), | | 993 | + ), | 963 | 994 | ).pipe(Layer.provide(McpServer.McpServer.layer)); | 964 | 995 | // @effect-diagnostics-next-line unsafeEffectTypeAssertion:off - the auth middleware provides it per request. | 965 | 996 | const registered = registration as Layer.Layer< | |
Collapse file Copy file name to clipboard +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | { | 2 | 2 | "claudeSystemAppendBytes": 4857, | 3 | 3 | "codexAdditionalContextBytes": 5409, | 4 | | - "mcpToolListJsonBytes": 54964 | | 4 | + "mcpToolListJsonBytes": 42328 | 5 | 5 | } |
|