Skip to content

Commit 91062c2

Browse files
authored
Load the MCP client SDK lazily on first outbound connection (#1747)
1 parent 05c3b22 commit 91062c2

12 files changed

Lines changed: 567 additions & 43 deletions
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@executor-js/plugin-mcp": patch
3+
---
4+
5+
Load the MCP client SDK lazily on first outbound connection instead of at module evaluation. Runtimes that bundle the plugin (notably Cloudflare Workers) no longer pay the client package's module-eval memory and CPU on startup or on code paths that never dial an MCP server.

‎packages/plugins/mcp/package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@
5858
"typecheck": "tsgo --noEmit",
5959
"test": "vitest run",
6060
"test:watch": "vitest",
61-
"typecheck:slow": "bunx tsc --noEmit -p tsconfig.json"
61+
"typecheck:slow": "bunx tsc --noEmit -p tsconfig.json",
62+
"gen:call-tool-result-schema": "bun scripts/gen-call-tool-result-schema.ts"
6263
},
6364
"dependencies": {
6465
"@cfworker/json-schema": "^4.1.1",
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Regenerates src/sdk/call-tool-result-schema.gen.ts from the installed
2+
// @modelcontextprotocol/core. The schema is baked into a generated file so
3+
// the runtime never imports the core package (importing it costs ~8.6MB of
4+
// heap per Cloudflare isolate; see client-module.ts). Run after bumping the
5+
// core dependency:
6+
// bun scripts/gen-call-tool-result-schema.ts
7+
// call-tool-result-schema.test.ts fails if the generated copy drifts from the
8+
// installed package.
9+
import { writeFileSync } from "node:fs";
10+
import { resolve } from "node:path";
11+
12+
import { CallToolResultSchema } from "@modelcontextprotocol/core";
13+
14+
const schema = CallToolResultSchema.toJSONSchema();
15+
const target = resolve(import.meta.dir, "../src/sdk/call-tool-result-schema.gen.ts");
16+
17+
writeFileSync(
18+
target,
19+
`// Generated by scripts/gen-call-tool-result-schema.ts — do not edit.
20+
// JSON Schema of @modelcontextprotocol/core's CallToolResultSchema, baked in
21+
// so the runtime never pays the core package's module-eval cost (see
22+
// client-module.ts). call-tool-result-schema.test.ts guards drift.
23+
export const callToolResultJsonSchema = ${JSON.stringify(schema, null, 2)} as const;
24+
`,
25+
);
26+
console.log(`wrote ${target}`);

0 commit comments

Comments
 (0)