modelcontextprotocol / modelcontextprotocol/typescript-sdk

CommonJS export paths broken - missing index.js file in dist/cjs

Open
#971 8 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug fix proposed P1 ready for work
Dominant language
TypeScript
Stars
13.4k
Forks
2.2k
Avg merge
3d 15h
Merged PRs (30d)
4

Description

Describe the bug

The CommonJS exports in @modelcontextprotocol/sdk package are broken due to missing dist/cjs/index.js file. The package.json exports configuration points to non-existent files, causing MODULE_NOT_FOUND errors when importing from the main package entry point in CommonJS/Node.js environments.

To Reproduce

Steps to reproduce the behavior:

  1. Create a Node.js project with CommonJS module resolution (or TypeScript compiling to CommonJS)
  2. Install @modelcontextprotocol/sdk@^1.17.3
  3. Try to import from the main export: import { McpError } from "@modelcontextprotocol/sdk"
  4. Run the application with Node.js
  5. Observe the MODULE_NOT_FOUND error

Minimal reproduction:

// test.js
const { McpError } = require('@modelcontextprotocol/sdk');
console.log(McpError);
node test.js
# Error: Cannot find module '/path/to/node_modules/@modelcontextprotocol/sdk/dist/cjs/index.js'

Expected behavior

The main package import should work without errors:

import { McpError } from "@modelcontextprotocol/sdk";
// Should successfully import McpError class

Logs

Error: Cannot find module '/Users/adam/src/maxcare-ai/monorepo/node_modules/@modelcontextprotocol/sdk/dist/cjs/index.js'
    at createEsmNotFoundErr (node:internal/modules/cjs/loader:1447:15)
    at finalizeEsmResolution (node:internal/modules/cjs/loader:1436:9)
    at resolveExports (node:internal/modules/cjs/loader:671:14)
    at Module._findPath (node:internal/modules/cjs/loader:738:31)
    at Module._resolveFilename (node:internal/modules/cjs/loader:1396:27)
    at defaultResolveImpl (node:internal/modules/cjs/loader:1051:19)
    at resolveForCJSWithHooks (node:internal/modules/cjs/loader:1056:22)
    at Module._load (node:internal/modules/cjs/loader:1219:37)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:238:24) {
  code: 'MODULE_NOT_FOUND',
  path: '/Users/adam/src/maxcare-ai/monorepo/node_modules/@modelcontextprotocol/sdk'
}

Additional context

  • Package version: 1.17.3 (also affects 1.17.4)
  • Node.js version: 24.7.0
  • Environment: TypeScript project compiled to CommonJS

Root cause analysis:
The package.json exports configuration references:

"exports": {
  ".": {
    "import": "./dist/esm/index.js",
    "require": "./dist/cjs/index.js"  // ❌ This file doesn't exist
  }
}

Actual file structure:

dist/cjs/
├── types.js        ✅ (contains McpError)
├── server/index.js ✅
├── client/index.js ✅
├── cli.js          ✅
└── index.js        ❌ missing

Current workaround:
Using the full path import works: import { McpError } from "@modelcontextprotocol/sdk/types.js"

Suggested fix:
Either create the missing dist/cjs/index.js file that re-exports the main classes/functions, or update the exports configuration to point to existing files like types.js for the main export.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by checking package.json exports alongside the dist/cjs file structure, then run the provided test.js reproduction with require('@modelcontextprotocol/sdk'). Done means the main CommonJS package import resolves successfully and exposes McpError without a MODULE_NOT_FOUND error.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
api, build-system
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.