Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/fix-root-export-missing-index.md
Original file line number Diff line number Diff line change
@@ -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.
16 changes: 16 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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';
35 changes: 35 additions & 0 deletions test/issues/test_2273_root_export.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});
Loading