Cannot find module dist/server/mcp.js after installing @modelcontextprotocol/sdk from GitHub
In a TypeScript ESM project on Node v22.13.1 with tsx, installing @modelcontextprotocol/sdk 1.11.0 from the GitHub URL and importing McpServer from '@modelcontextprotocol/sdk/server/mcp.js' fails with
Error: Cannot find module '/tmp/mcp-repro/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/mcp.js'(MODULE_NOT_FOUND). The installed package has no dist/ directory. Is there a working workaround, or is this fixed in a later release?Originally asked on GitHub: https://github.com/modelcontextprotocol/typescript-sdk/issues/460
5 answers
Status: the issue is closed (COMPLETED). A maintainer closed it and said packaging improvements would be revisited at the next breaking change; the thread does not confirm a fix in any released version.
The reporter's hypothesis is that installing
@modelcontextprotocol/sdk@1.11.0directly from GitHub (npm install @modelcontextprotocol/sdk@github:modelcontextprotocol/typescript-sdk) gives a package whosedist/directory is missing, while the package.jsonexportsmap points to./dist/esm/*and./dist/cjs/*, so every import fails with MODULE_NOT_FOUND. The cause was not confirmed by the maintainer.Workaround that worked in the thread (comment 1): keep using ESM for types, but load the runtime bindings with CommonJS
require()and explicit.jspaths:jsconst { Client } = require("@modelcontextprotocol/sdk/client/index.js"); import { type Client as McpClient } from "@modelcontextprotocol/sdk/client/index.js"; const { StreamableHTTPClientTransport } = require("@modelcontextprotocol/sdk/client/streamableHttp.js"); ... const transport = new StreamableHTTPClientTransport(new URL(myMcpUrl)); const client: McpClient = new Client(...)The commenter notes the same approach should work for the server.
Another workaround from the thread (comment 2): if the failure appears when running an MCP server through
npx -y, the npx cache may hold a broken install. List cache keys withnpm cache npx ls your-mcp-server-here, remove the matching entry withnpm cache npx rm <hash>, then runnpx -yagain; this worked for the commenter.General advice: if you do not need a specific commit, prefer the published npm package over the GitHub URL, since the failure in this thread occurred with a GitHub install.
Did this work for you?What a GitHub user tried on GitHub (Didn't work)
Installed
@modelcontextprotocol/sdk@github:modelcontextprotocol/typescript-sdkplus tsx in a fresh project and rannpx tsx mcp-repro.tsimportingMcpServerfrom@modelcontextprotocol/sdk/server/mcp.js. Failed withMODULE_NOT_FOUNDbecause/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/mcp.jsdoes not exist; the installed package has nodist/directory.Source: https://github.com/modelcontextprotocol/typescript-sdk/issues/460 (opens external site)
Did this work for you?What @alon-gb tried on GitHub (Worked)
Imported the client and transport with CommonJS
require()using explicit.jspaths (@modelcontextprotocol/sdk/client/index.jsand.../streamableHttp.js), and usedimport { type Client as McpClient }only for the TypeScript type. This got the MCP client working; the commenter noted the same approach should work for the server.Did this work for you?What @ThePlenkov tried on GitHub (Worked)
Cleared a broken cached npx package with
npm cache npx ls <server-name>to find the cache key andnpm cache npx rm <hash>; the followingnpx -yrun worked.Did this work for you?What @mattzcarey tried on GitHub (Outcome unclear)
A maintainer closed the issue, stating that packaging improvements would be revisited for the next breaking change, but provided no immediate repair or version fix.
Did this work for you?
Related questions
- MCP TypeScript SDK StreamableHttp without sticky sessions in multi-replica deployments?
- MCP stdio server: SyntaxError Unexpected token in deserializeMessage when using console.log
- MCP typescript-sdk: tool inputSchema/outputSchema reject JSON Schema type 'array'?
- Use Zod union/intersection as MCP tool paramsSchema in typescript-sdk?
- MCP Inspector: "Invalid transport type: undefined" when connecting to an SSE server