fix(mcp): bundle build with esbuild so plugin cache never needs node_modules
Claude Code spawns plugin MCP servers straight from the read-only git-content plugin cache, which never gets an npm install for mcp/. The old tsc-multi-file build imported bare specifiers that only resolved via mcp/node_modules, so every fresh plugin install/update produced a -32000 reconnect failure. Bundle mcp/src into a single dependency-free build/index.js instead; the one CJS-heavy import (express, only used by --transport=http) is now dynamic so the stdio path never evaluates it.
This commit is contained in:
+12
-2
@@ -152,6 +152,15 @@ no "not ready yet, retry" state, so an async bootstrap cannot win that race. The
|
||||
build artifact is therefore committed, and `plugins/ccam/.mcp.json` points at
|
||||
`${CLAUDE_PLUGIN_ROOT}/mcp/build/index.js`.
|
||||
|
||||
`npm run mcp:build` bundles `mcp/src` and its runtime dependencies
|
||||
(`esbuild --bundle`) into that single `build/index.js` file — the plugin cache
|
||||
never gets an `npm install` for `mcp/`, so a build that still had bare
|
||||
`node_modules` imports (plain `tsc` output) would throw `MODULE_NOT_FOUND` the
|
||||
instant Claude Code spawned it after any plugin install or update. `express`
|
||||
(only used by `--transport=http`, never by the stdio mode a real MCP host
|
||||
uses) is pulled in lazily via `await import(...)` in `src/index.ts` instead of
|
||||
a static import, so the stdio path never even evaluates it.
|
||||
|
||||
The cost is drift, so freshness is enforced by content hash — `mcp/src` plus the
|
||||
MCP manifests and tsconfig are hashed into `mcp/build/.srchash`:
|
||||
|
||||
@@ -179,8 +188,9 @@ mcp/
|
||||
│ │ └── stats.ts # Statistics tools
|
||||
│ └── types.ts # TypeScript type definitions
|
||||
│
|
||||
├── build/ # Compiled JavaScript (COMMITTED — see above)
|
||||
│ └── .srchash # hash of mcp/src the build was produced from
|
||||
├── build/ # Bundled, dependency-free output (COMMITTED — see above)
|
||||
│ ├── index.js # single esbuild bundle, no node_modules needed to run it
|
||||
│ └── .srchash # hash of mcp/src the build was produced from
|
||||
├── package.json
|
||||
├── tsconfig.json
|
||||
└── README.md
|
||||
|
||||
Reference in New Issue
Block a user