Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions apps/server/src/mcp/McpHttpServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { HttpBody, HttpClient, HttpClientRequest, HttpRouter } from "effect/http
import * as ProjectService from "../project/ProjectService.ts";
import * as PullRequestReviewGuideService from "../pullRequest/PullRequestReviewGuideService.ts";
import * as ServerConfig from "../config.ts";
import { advertisedJsonSchema } from "./advertisedJsonSchema.ts";
import * as McpHttpServer from "./McpHttpServer.ts";
import * as McpToolAccess from "./McpToolAccess.ts";
import * as McpToolAccessTestkit from "./McpToolAccess.testkit.ts";
Expand All @@ -29,6 +30,7 @@ import * as McpSessionRegistry from "./McpSessionRegistry.ts";
import * as OrchestratorMcpService from "./OrchestratorMcpService.ts";
import * as PreviewAutomationBroker from "./PreviewAutomationBroker.ts";
import { OrchestratorToolkit } from "./toolkits/orchestrator/tools.ts";
import { PreviewToolkit } from "./toolkits/preview/tools.ts";
import { ProjectToolkit } from "./toolkits/project/tools.ts";

const environmentId = EnvironmentId.make("environment-mcp-test");
Expand Down Expand Up @@ -356,6 +358,18 @@ it.effect("refuses preview tools to a client outside a thread before they run",
}).pipe(Effect.provide(layerTest)),
);

it.effect("advertises the compact input schema for every registered tool", () =>
Effect.gen(function* () {
const server = yield* McpServer.McpServer;
const tools: Record<string, Tool.Any> = PreviewToolkit.tools;

expect(server.tools.length).toBe(Object.keys(tools).length);
for (const { tool } of server.tools) {
expect(tool.inputSchema, tool.name).toEqual(advertisedJsonSchema(tools[tool.name]!));
}
}).pipe(Effect.provide(layerTest)),
);

it.effect("checks each preview_act action against that action's own input", () =>
Effect.scoped(
Effect.gen(function* () {
Expand Down
33 changes: 32 additions & 1 deletion apps/server/src/mcp/McpHttpServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,35 @@ const withToolAnalytics =
return yield* registration.pipe(Effect.provideService(McpServer.McpServer, recordingServer));
});

/** `McpServer.registerToolkit` advertises the full codec schema; agents get the compact one. */
const withAdvertisedSchemas = Effect.fn("McpHttpServer.withAdvertisedSchemas")(function* <
Tools extends Record<string, Tool.Any>,
A,
E,
R,
>(toolkit: Toolkit.Toolkit<Tools>, registration: Effect.Effect<A, E, R>) {
const server = yield* McpServer.McpServer;
const tools: Record<string, Tool.Any> = toolkit.tools;
const advertisingServer = McpServer.McpServer.of({
...server,
addTool: Effect.fn("McpServer.addTool")(function (options) {
const tool = tools[options.tool.name];
return server.addTool(
tool === undefined
? options
: {
...options,
tool: new McpSchema.Tool({
...options.tool,
inputSchema: advertisedJsonSchema(tool),
}),
},
);
}),
});
return yield* registration.pipe(Effect.provideService(McpServer.McpServer, advertisingServer));
});

/**
* `McpServer.toolkit` asks for every service its tools declare when it
* registers them, but the auth middleware provides `McpInvocationContext` to
Expand All @@ -959,7 +988,9 @@ export const toolkitRegistration = <Tools extends Record<string, Tool.Any>, EX,
handlers: McpToolAccess.HandlersLayer<Tools, EX, RX>,
) => {
const registration = Layer.effectDiscard(
withToolAnalytics(McpServer.registerToolkit(decodeAsAdvertised(toolkit))),
withToolAnalytics(
withAdvertisedSchemas(toolkit, McpServer.registerToolkit(decodeAsAdvertised(toolkit))),
),
).pipe(Layer.provide(McpServer.McpServer.layer));
// @effect-diagnostics-next-line unsafeEffectTypeAssertion:off - the auth middleware provides it per request.
const registered = registration as Layer.Layer<
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/provider/agentContextBudget.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"claudeSystemAppendBytes": 4857,
"codexAdditionalContextBytes": 5409,
"mcpToolListJsonBytes": 54964
"mcpToolListJsonBytes": 42328
}
Loading