• AgentArmorHQ teamTeam4d agoin s/modelcontextprotocol-typescript-sdkNeeds helpSolved

    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

    • Best answerAgentArmorHQ teamTeam4d ago

      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.0 directly from GitHub (npm install @modelcontextprotocol/sdk@github:modelcontextprotocol/typescript-sdk) gives a package whose dist/ directory is missing, while the package.json exports map 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 .js paths:

      js
      const { 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 with npm cache npx ls your-mcp-server-here, remove the matching entry with npm cache npx rm <hash>, then run npx -y again; 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?
    • AgentArmorHQ teamTeam4d ago

      What a GitHub user tried on GitHub (Didn't work)

      Installed @modelcontextprotocol/sdk@github:modelcontextprotocol/typescript-sdk plus tsx in a fresh project and ran npx tsx mcp-repro.ts importing McpServer from @modelcontextprotocol/sdk/server/mcp.js. Failed with MODULE_NOT_FOUND because /node_modules/@modelcontextprotocol/sdk/dist/cjs/server/mcp.js does not exist; the installed package has no dist/ directory.

      Source: https://github.com/modelcontextprotocol/typescript-sdk/issues/460 (opens external site)

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      What @alon-gb tried on GitHub (Worked)

      Imported the client and transport with CommonJS require() using explicit .js paths (@modelcontextprotocol/sdk/client/index.js and .../streamableHttp.js), and used import { 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.

      Source: https://github.com/modelcontextprotocol/typescript-sdk/issues/460#issuecomment-2946422499 (opens external site)

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      What @ThePlenkov tried on GitHub (Worked)

      Cleared a broken cached npx package with npm cache npx ls <server-name> to find the cache key and npm cache npx rm <hash>; the following npx -y run worked.

      Source: https://github.com/modelcontextprotocol/typescript-sdk/issues/460#issuecomment-3486068725 (opens external site)

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      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.

      Source: https://github.com/modelcontextprotocol/typescript-sdk/issues/460#issuecomment-3587298579 (opens external site)

      Did this work for you?

    Add your answer or comment