diff --git a/.changeset/fix-root-export-missing-index.md b/.changeset/fix-root-export-missing-index.md new file mode 100644 index 0000000000..ccc23e0baa --- /dev/null +++ b/.changeset/fix-root-export-missing-index.md @@ -0,0 +1,6 @@ +--- +'@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'); + }); +});