diff --git a/.changeset/fix-root-export-missing-index.md b/.changeset/fix-root-export-missing-index.md new file mode 100644 index 0000000000..3c5383aa6e --- /dev/null +++ b/.changeset/fix-root-export-missing-index.md @@ -0,0 +1,7 @@ +--- +'@modelcontextprotocol/sdk': patch +--- + +Fix the advertised root package export failing with `ERR_MODULE_NOT_FOUND`. `package.json` maps the `.` export to `dist/{esm,cjs}/index.{js,d.ts}`, but there was no `src/index.ts`, so `tsc` never emitted those files and they were absent from the published tarball — both +`import '@modelcontextprotocol/sdk'` and `require('@modelcontextprotocol/sdk')` threw before consumer code ran. Adds a side-effect-free `src/index.ts` re-exporting the shared protocol surface (`./types.js`) and the in-memory transport (`./inMemory.js`); `Client` and `Server` +remain on their `./client` / `./server` subpath exports to avoid ambiguous re-export collisions. Subpath imports are unchanged. diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000000..4391ab910b --- /dev/null +++ b/src/index.ts @@ -0,0 +1,16 @@ +/** + * Root entry point for `@modelcontextprotocol/sdk`. + * + * `package.json` maps the root `.` export to `dist/{esm,cjs}/index.{js,d.ts}`, + * but there was no `src/index.ts`, so `tsc` never emitted those files and they + * were absent from the published tarball. Importing the package root therefore + * failed with `ERR_MODULE_NOT_FOUND` before any consumer code ran (#2273). + * + * Re-export the shared protocol surface (types, schemas, constants) and the + * in-memory transport. `Client` and `Server` intentionally stay on their + * `./client` / `./server` subpath exports to avoid TS2308 ambiguous re-export + * collisions at the root. + */ + +export * from './types.js'; +export * from './inMemory.js'; diff --git a/test/issues/test_2273_root_export.test.ts b/test/issues/test_2273_root_export.test.ts new file mode 100644 index 0000000000..a7872b799a --- /dev/null +++ b/test/issues/test_2273_root_export.test.ts @@ -0,0 +1,35 @@ +/** + * Regression test for https://github.com/modelcontextprotocol/typescript-sdk/issues/2273 + * + * `package.json` advertises a root `.` export that maps to + * `dist/{esm,cjs}/index.{js,d.ts}`, but v1.x had no `src/index.ts`, so `tsc` + * emitted nothing for the root and importing `@modelcontextprotocol/sdk` failed + * with `ERR_MODULE_NOT_FOUND` before any consumer code ran. + * + * This exercises the root barrel directly (the same module `tsc` compiles into + * the advertised dist files): it must resolve and re-export the shared protocol + * surface and the in-memory transport. + */ + +import { describe, it, expect } from 'vitest'; +import * as root from '../../src/index.js'; +import { LATEST_PROTOCOL_VERSION, SUPPORTED_PROTOCOL_VERSIONS, JSONRPC_VERSION, InMemoryTransport } from '../../src/index.js'; + +describe('root package export (#2273)', () => { + it('re-exports the shared protocol constants', () => { + expect(LATEST_PROTOCOL_VERSION).toBe('2025-11-25'); + expect(SUPPORTED_PROTOCOL_VERSIONS).toContain(LATEST_PROTOCOL_VERSION); + expect(JSONRPC_VERSION).toBe('2.0'); + }); + + it('re-exports the in-memory transport as a working class', () => { + expect(typeof InMemoryTransport).toBe('function'); + const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); + expect(clientTransport).toBeInstanceOf(InMemoryTransport); + expect(serverTransport).toBeInstanceOf(InMemoryTransport); + }); + + it('re-exports a non-empty protocol surface', () => { + expect(Object.keys(root).length).toBeGreaterThan(0); + }); +});