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
5 changes: 5 additions & 0 deletions .changeset/lazy-mcp-client-module.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@executor-js/plugin-mcp": patch
---

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.
3 changes: 2 additions & 1 deletion packages/plugins/mcp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@
"typecheck": "tsgo --noEmit",
"test": "vitest run",
"test:watch": "vitest",
"typecheck:slow": "bunx tsc --noEmit -p tsconfig.json"
"typecheck:slow": "bunx tsc --noEmit -p tsconfig.json",
"gen:call-tool-result-schema": "bun scripts/gen-call-tool-result-schema.ts"
},
"dependencies": {
"@cfworker/json-schema": "^4.1.1",
Expand Down
26 changes: 26 additions & 0 deletions packages/plugins/mcp/scripts/gen-call-tool-result-schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Regenerates src/sdk/call-tool-result-schema.gen.ts from the installed
// @modelcontextprotocol/core. The schema is baked into a generated file so
// the runtime never imports the core package (importing it costs ~8.6MB of
// heap per Cloudflare isolate; see client-module.ts). Run after bumping the
// core dependency:
// bun scripts/gen-call-tool-result-schema.ts
// call-tool-result-schema.test.ts fails if the generated copy drifts from the
// installed package.
import { writeFileSync } from "node:fs";
import { resolve } from "node:path";

import { CallToolResultSchema } from "@modelcontextprotocol/core";

const schema = CallToolResultSchema.toJSONSchema();
const target = resolve(import.meta.dir, "../src/sdk/call-tool-result-schema.gen.ts");

writeFileSync(
target,
`// Generated by scripts/gen-call-tool-result-schema.ts — do not edit.
// JSON Schema of @modelcontextprotocol/core's CallToolResultSchema, baked in
// so the runtime never pays the core package's module-eval cost (see
// client-module.ts). call-tool-result-schema.test.ts guards drift.
export const callToolResultJsonSchema = ${JSON.stringify(schema, null, 2)} as const;
`,
);
console.log(`wrote ${target}`);
Loading
Loading