From d60ddb2b4ae57991d640e7490200c63b0a506418 Mon Sep 17 00:00:00 2001 From: rajanpanth Date: Mon, 20 Jul 2026 16:47:19 +0545 Subject: [PATCH 1/2] fix: add root src/index.ts so the advertised root export resolves package.json maps the root "." export to dist/{esm,cjs}/index.js and dist/esm/index.d.ts, but with no src/index.ts the build never emitted those files, so importing '@modelcontextprotocol/sdk' from the published package failed with ERR_MODULE_NOT_FOUND. Add a root entry that re-exports the shared protocol types/schemas and the in-memory transport. Client and Server stay on their ./client and ./server subpath exports to avoid ambiguous re-export collisions. Fixes #2273 --- .changeset/fix-root-export-missing-index.md | 5 ++++ src/index.ts | 13 ++++++++++ test/index.test.ts | 28 +++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 .changeset/fix-root-export-missing-index.md create mode 100644 src/index.ts create mode 100644 test/index.test.ts diff --git a/.changeset/fix-root-export-missing-index.md b/.changeset/fix-root-export-missing-index.md new file mode 100644 index 0000000000..3f0233b8d9 --- /dev/null +++ b/.changeset/fix-root-export-missing-index.md @@ -0,0 +1,5 @@ +--- +'@modelcontextprotocol/sdk': patch +--- + +Fix the root package export: add `src/index.ts` so the advertised `dist/{esm,cjs}/index.js` and `dist/esm/index.d.ts` are actually emitted and published. The root entry re-exports the shared protocol types/schemas and the in-memory transport; `Client` and `Server` remain on their `./client` and `./server` subpaths. diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000000..91fc719498 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,13 @@ +// Root entry for `@modelcontextprotocol/sdk`. +// +// package.json exposes this file via the `.` export. Without a source file +// here, tsc emits nothing for the advertised dist/{esm,cjs}/index.{js,d.ts} +// paths and the root import of the published package fails to resolve +// (issue #2273). +// +// Re-export the shared protocol schemas/types and the in-memory transport. +// `Client` and `Server` intentionally stay on their `./client` and `./server` +// subpath exports: re-exporting both here would collide on identically named +// symbols (TS2308). +export * from './types.js'; +export * from './inMemory.js'; diff --git a/test/index.test.ts b/test/index.test.ts new file mode 100644 index 0000000000..db01bd09fb --- /dev/null +++ b/test/index.test.ts @@ -0,0 +1,28 @@ +import { describe, it, expect } from 'vitest'; +import { readFileSync } from 'node:fs'; +import { join } from 'node:path'; +import * as rootExport from '../src/index.js'; + +// Regression tests for #2273: package.json advertises a root `.` export, so a +// root source entry must exist and re-export the shared protocol surface. +describe('root package export', () => { + it('exposes the shared protocol types and schemas', () => { + expect(rootExport.LATEST_PROTOCOL_VERSION).toBeDefined(); + expect(rootExport.CallToolResultSchema).toBeDefined(); + expect(rootExport.JSONRPCMessageSchema).toBeDefined(); + }); + + it('exposes the in-memory transport', () => { + expect(rootExport.InMemoryTransport).toBeTypeOf('function'); + }); + + it('matches the paths advertised in the package.json exports map', () => { + const pkg = JSON.parse(readFileSync(join(__dirname, '..', 'package.json'), 'utf8')); + const root = pkg.exports['.']; + // The `.` export must keep pointing at the root index build outputs + // that src/index.ts produces. + expect(root.import).toBe('./dist/esm/index.js'); + expect(root.require).toBe('./dist/cjs/index.js'); + expect(root.types).toBe('./dist/esm/index.d.ts'); + }); +}); From 422397be1183bbf8d827397cc56b023f71568625 Mon Sep 17 00:00:00 2001 From: rajanpanth Date: Mon, 20 Jul 2026 21:31:17 +0545 Subject: [PATCH 2/2] chore: format changeset --- .changeset/fix-root-export-missing-index.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.changeset/fix-root-export-missing-index.md b/.changeset/fix-root-export-missing-index.md index 3f0233b8d9..ccc23e0baa 100644 --- a/.changeset/fix-root-export-missing-index.md +++ b/.changeset/fix-root-export-missing-index.md @@ -2,4 +2,5 @@ '@modelcontextprotocol/sdk': patch --- -Fix the root package export: add `src/index.ts` so the advertised `dist/{esm,cjs}/index.js` and `dist/esm/index.d.ts` are actually emitted and published. The root entry re-exports the shared protocol types/schemas and the in-memory transport; `Client` and `Server` remain on their `./client` and `./server` subpaths. +Fix the root package export: add `src/index.ts` so the advertised `dist/{esm,cjs}/index.js` and `dist/esm/index.d.ts` are actually emitted and published. The root entry re-exports the shared protocol types/schemas and the in-memory transport; `Client` and `Server` remain on their +`./client` and `./server` subpaths.