From 8fbb0cd1eb3ef01cef1a185975fbcf45d0469796 Mon Sep 17 00:00:00 2001 From: Tibsfox Date: Mon, 6 Apr 2026 19:17:26 -0700 Subject: [PATCH] fix(mcp): use createRequire to resolve SDK wildcard subpath imports Node ESM can't resolve wildcard export patterns without .js extension. The MCP SDK's server/stdio and types subpaths use wildcard exports that fail at runtime with ERR_MODULE_NOT_FOUND. Use createRequire (CJS resolver) to resolve physical file paths before passing to dynamic import(), since CJS auto-appends .js. Closes #3603 Co-Authored-By: Claude Opus 4.6 (1M context) --- src/mcp-server.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/mcp-server.ts b/src/mcp-server.ts index d3ea233fe..f7417235e 100644 --- a/src/mcp-server.ts +++ b/src/mcp-server.ts @@ -19,6 +19,10 @@ export interface McpToolDef { // MCP SDK subpath imports use wildcard exports (./*) that NodeNext resolves // at runtime but TypeScript cannot statically type-check. We construct the // specifiers dynamically so tsc treats them as `any`. +// Use createRequire to resolve wildcard subpaths — CJS resolver auto-appends +// .js, which the ESM wildcard export map does not (#3603). +import { createRequire } from 'node:module' +const _require = createRequire(import.meta.url) const MCP_PKG = '@modelcontextprotocol/sdk' /** @@ -42,8 +46,8 @@ export async function startMcpServer(options: { const { tools, version = '0.0.0' } = options const serverMod = await import(`${MCP_PKG}/server`) - const stdioMod = await import(`${MCP_PKG}/server/stdio`) - const typesMod = await import(`${MCP_PKG}/types`) + const stdioMod = await import(_require.resolve(`${MCP_PKG}/server/stdio`)) + const typesMod = await import(_require.resolve(`${MCP_PKG}/types`)) const Server = serverMod.Server const StdioServerTransport = stdioMod.StdioServerTransport