fix(mcp): restore Bun version negotiation#2375
Conversation
a5aeced to
87892f0
Compare
|
All checks are green and the change remains scoped to the Bun transport-version negotiation regression. No further changes are planned; this is ready for review. |
|
getting this reviewed today |
|
Approving. This is a well-scoped fix with a genuine regression test. Problem: The 12.0.1 change (adcp#2364) narrowed the ESM createRequire/__dirname shim to only files whose own source references require( or __dirname, to keep node:url/node:path/node:module out of pure-data modules that browser bundlers can’t resolve. The MCP protocol modules don’t reference those in their own bodies, but their dual ESM/CJS dependencies need the createRequire binding to load under Bun. Node tolerated the missing shim; Bun did not, so the packed ESM artifact broke during MCP negotiation while every Node test stayed green. Fix: Always apply the shim to files under src/lib/protocols/, layered on top of the existing require/__dirname detection. Restores the shim where Bun needs it without reintroducing the browser-bundle breakage, since the protocols directory is node-only. What I verified: The shim condition is correct, and the path check uses nodePath.sep so it’s cross-platform. |
|
Thanks for the thorough review. Applied your optional note — added a one-liner above the // protocols/ is node-only throughout; directory-wide scope also covers future MCP modules automatically.Generated by Claude Code |
Summary
@adcp/sdk/enumsbundle checkRoot cause
The 12.0.1 conditional shim only covered source files that directly referenced
__dirnameorrequire. The MCP protocol modules do not contain those references themselves, but Bun needs thecreateRequirebinding when loading their dual ESM/CJS dependency graph. Removing the former blanket banner therefore made the packed ESM artifact fail while loading MCP dependencies before negotiation could complete.This keeps the conditional build introduced for browser consumers and adds a narrow protocol-directory allowlist instead of restoring the global banner.
Validation
npm run build:libNODE_ENV=test npx --yes node@20 --test-timeout=60000 --test-force-exit --test test/lib/mcp-modern-negotiation.test.jsNODE_ENV=test npx --yes node@20 --test-timeout=60000 --test-force-exit --test test/read-path-abort-timeout.test.jsnpm run verify:packagenpm run check:packagenpm run typecheckgit diff --checkFixes #2369.