Skip to content

fix: add root src/index.ts so the advertised root export resolves (#2273) - #2632

Open
ousamabenyounes wants to merge 1 commit into
modelcontextprotocol:v1.xfrom
ousamabenyounes:fix/issue-2273
Open

fix: add root src/index.ts so the advertised root export resolves (#2273)#2632
ousamabenyounes wants to merge 1 commit into
modelcontextprotocol:v1.xfrom
ousamabenyounes:fix/issue-2273

Conversation

@ousamabenyounes

Copy link
Copy Markdown

Summary

Fixes #2273

package.json (v1.x) advertises a root . export:

"exports": { ".": {
  "types": "./dist/esm/index.d.ts",
  "import": "./dist/esm/index.js",
  "require": "./dist/cjs/index.js"
} }

but there was no src/index.ts, so tsc never emitted those files and they were absent from the published tarball. Both an ESM import and a CJS require of the package root threw ERR_MODULE_NOT_FOUND before any consumer code ran. Subpath exports (/client, /server, …) were unaffected.

This adds a side-effect-free root barrel per the direction in the issue triage:

  • export * from './types.js' — protocol types, schemas, constants
  • export * from './inMemory.js'InMemoryTransport

Client and Server intentionally stay on their ./client / ./server subpath exports to avoid TS2308 ambiguous re-export collisions. The change is additive and non-breaking; main is unaffected (it is a monorepo with no root package).

Test verification (RED → GREEN)

New regression test test/issues/test_2273_root_export.test.ts imports the root barrel and asserts it resolves and re-exports the protocol surface + a working InMemoryTransport.

RED — new test on unmodified v1.x (no src/index.ts):

FAIL  test/issues/test_2273_root_export.test.ts
Error: Cannot find module '../../src/index.js' imported from '.../test/issues/test_2273_root_export.test.ts'
 Test Files  1 failed (1)

GREEN — with src/index.ts added:

✓ test/issues/test_2273_root_export.test.ts (3 tests) 7ms
 Test Files  1 passed (1)
      Tests  3 passed (3)

End-to-end packaging check — after npm run build, the previously-missing root files now emit and both loaders resolve:

dist/esm/index.js EXISTS
dist/cjs/index.js EXISTS
dist/esm/index.d.ts EXISTS
ESM OK — symbols: 172 — LATEST: 2025-11-25 — InMemoryTransport: function
CJS OK — symbols: 172 — JSONRPC_VERSION: 2.0
npm pack --dry-run: all three root files present in the tarball

Full local suite

  • npm run typecheck (tsgo), npm run lint (eslint + prettier), npm run build, npm test (vitest): all green.
  • No regressions: baseline 52 files / 1639 tests → with fix 53 files / 1642 tests (+1 file, +3 new tests, 0 failures).

Files changed

File Change
src/index.ts New side-effect-free root barrel re-exporting ./types.js + ./inMemory.js
test/issues/test_2273_root_export.test.ts Regression test for the root export
.changeset/fix-root-export-missing-index.md Changeset (sdk package, patch)

@ousamabenyounes
ousamabenyounes requested a review from a team as a code owner August 10, 2026 02:43
@changeset-bot

changeset-bot Bot commented Aug 10, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 31192a4

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Aug 10, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@modelcontextprotocol/sdk@2632

commit: 31192a4

@claude claude Bot added the v1 Issues / PRs related to v1.x label Aug 18, 2026
…delcontextprotocol#2273)

package.json maps the `.` export to dist/{esm,cjs}/index.{js,d.ts}, but v1.x
had no src/index.ts, so tsc emitted nothing for the root and both
`import '@modelcontextprotocol/sdk'` and `require('@modelcontextprotocol/sdk')`
threw ERR_MODULE_NOT_FOUND before consumer code ran. Add a side-effect-free
root barrel re-exporting ./types.js and ./inMemory.js; Client and Server stay
on their ./client / ./server subpaths to avoid ambiguous re-export collisions.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v1 Issues / PRs related to v1.x

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant