Skip to content

Commit b4cb01e

Browse files
committed
merge commit
2 parents 6525bb6 + 40174d2 commit b4cb01e

71 files changed

Lines changed: 5710 additions & 4516 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changeset/extract-task-manager.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
"@modelcontextprotocol/core": minor
3+
"@modelcontextprotocol/client": minor
4+
"@modelcontextprotocol/server": minor
5+
---
6+
7+
refactor: extract task orchestration from Protocol into TaskManager
8+
9+
**Breaking changes:**
10+
- `taskStore`, `taskMessageQueue`, `defaultTaskPollInterval`, and `maxTaskQueueSize` moved from `ProtocolOptions` to `capabilities.tasks` on `ClientOptions`/`ServerOptions`
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@modelcontextprotocol/server': patch
3+
---
4+
5+
Fix transport errors being silently swallowed by adding missing `onerror` callback invocations before all `createJsonErrorResponse` calls in `WebStandardStreamableHTTPServerTransport`. This ensures errors like parse failures, invalid headers, and session validation errors are properly reported via the `onerror` callback.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@modelcontextprotocol/server': patch
3+
---
4+
5+
Handle stdout errors (e.g. EPIPE) in `StdioServerTransport` gracefully instead of crashing. When the client disconnects abruptly, the transport now catches the stdout error, surfaces it via `onerror`, and closes.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,6 @@ dist/
5252

5353
# Conformance test results
5454
results/
55+
56+
# Ignore local lefthook configuration
57+
lefthook-local.yml

CLAUDE.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,19 @@ The SDK is organized into three main layers:
6262
- `Server` (`packages/server/src/server/server.ts`) - Server implementation extending Protocol with request handler registration
6363
- `McpServer` (`packages/server/src/server/mcp.ts`) - High-level server API with simplified resource/tool/prompt registration
6464

65+
### Public API Exports
66+
67+
The SDK has a two-layer export structure to separate internal code from the public API:
68+
69+
- **`@modelcontextprotocol/core`** (main entry, `packages/core/src/index.ts`) — Internal barrel. Exports everything (including Zod schemas, Protocol class, stdio utils). Only consumed by sibling packages within the monorepo (`private: true`).
70+
- **`@modelcontextprotocol/core/public`** (`packages/core/src/exports/public/index.ts`) — Curated public API. Exports only TypeScript types, error classes, constants, and guards. Re-exported by client and server packages.
71+
- **`@modelcontextprotocol/client`** and **`@modelcontextprotocol/server`** (`packages/*/src/index.ts`) — Final public surface. Package-specific exports (named explicitly) plus re-exports from `core/public`.
72+
73+
When modifying exports:
74+
- Use explicit named exports, not `export *`, in package `index.ts` files and `core/public`.
75+
- Adding a symbol to a package `index.ts` makes it public API — do so intentionally.
76+
- Internal helpers should stay in the core internal barrel and not be added to `core/public` or package index files.
77+
6578
### Transport System
6679

6780
Transports (`packages/core/src/shared/transport.ts`) provide the communication layer:

docs/migration-SKILL.md

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,18 +61,17 @@ Replace all `@modelcontextprotocol/sdk/...` imports using this table.
6161

6262
| v1 import path | v2 package |
6363
| ------------------------------------------------- | ---------------------------- |
64-
| `@modelcontextprotocol/sdk/types.js` | `@modelcontextprotocol/core` |
65-
| `@modelcontextprotocol/sdk/shared/protocol.js` | `@modelcontextprotocol/core` |
66-
| `@modelcontextprotocol/sdk/shared/transport.js` | `@modelcontextprotocol/core` |
67-
| `@modelcontextprotocol/sdk/shared/stdio.js` | `@modelcontextprotocol/core` |
68-
| `@modelcontextprotocol/sdk/shared/uriTemplate.js` | `@modelcontextprotocol/core` |
69-
| `@modelcontextprotocol/sdk/shared/auth.js` | `@modelcontextprotocol/core` |
64+
| `@modelcontextprotocol/sdk/types.js` | `@modelcontextprotocol/client` or `@modelcontextprotocol/server` |
65+
| `@modelcontextprotocol/sdk/shared/protocol.js` | `@modelcontextprotocol/client` or `@modelcontextprotocol/server` |
66+
| `@modelcontextprotocol/sdk/shared/transport.js` | `@modelcontextprotocol/client` or `@modelcontextprotocol/server` |
67+
| `@modelcontextprotocol/sdk/shared/uriTemplate.js` | `@modelcontextprotocol/client` or `@modelcontextprotocol/server` |
68+
| `@modelcontextprotocol/sdk/shared/auth.js` | `@modelcontextprotocol/client` or `@modelcontextprotocol/server` |
69+
| `@modelcontextprotocol/sdk/shared/stdio.js` | `@modelcontextprotocol/client` or `@modelcontextprotocol/server` |
7070

7171
Notes:
7272

73-
- `@modelcontextprotocol/client` and `@modelcontextprotocol/server` both re-export everything from `@modelcontextprotocol/core`, so you can import types from whichever package you already depend on.
73+
- `@modelcontextprotocol/client` and `@modelcontextprotocol/server` both re-export shared types from `@modelcontextprotocol/core`, so import from whichever package you already depend on. Do not import from `@modelcontextprotocol/core` directly — it is an internal package.
7474
- When multiple v1 imports map to the same v2 package, consolidate them into a single import statement.
75-
- If code imports from `sdk/client/...`, install `@modelcontextprotocol/client`. If from `sdk/server/...`, install `@modelcontextprotocol/server`. If from `sdk/types.js` or `sdk/shared/...` only, install `@modelcontextprotocol/core`.
7675

7776
## 4. Renamed Symbols
7877

@@ -91,7 +90,7 @@ Notes:
9190
| `ResourceReference` | `ResourceTemplateReference` |
9291
| `ResourceReferenceSchema` | `ResourceTemplateReferenceSchema` |
9392
| `IsomorphicHeaders` | REMOVED (use Web Standard `Headers`) |
94-
| `AuthInfo` (from `server/auth/types.js`) | `AuthInfo` (now in `@modelcontextprotocol/core`) |
93+
| `AuthInfo` (from `server/auth/types.js`) | `AuthInfo` (now re-exported by `@modelcontextprotocol/client` and `@modelcontextprotocol/server`) |
9594
| `McpError` | `ProtocolError` |
9695
| `ErrorCode` | `ProtocolErrorCode` |
9796
| `ErrorCode.RequestTimeout` | `SdkErrorCode.RequestTimeout` |
@@ -144,7 +143,7 @@ Update error handling:
144143
if (error instanceof McpError && error.code === ErrorCode.RequestTimeout) { ... }
145144

146145
// v2
147-
import { SdkError, SdkErrorCode } from '@modelcontextprotocol/core';
146+
import { SdkError, SdkErrorCode } from '@modelcontextprotocol/client';
148147
if (error instanceof SdkError && error.code === SdkErrorCode.RequestTimeout) { ... }
149148
```
150149

@@ -158,7 +157,7 @@ if (error instanceof StreamableHTTPError) {
158157
}
159158

160159
// v2
161-
import { SdkError, SdkErrorCode } from '@modelcontextprotocol/core';
160+
import { SdkError, SdkErrorCode } from '@modelcontextprotocol/client';
162161
if (error instanceof SdkError && error.code === SdkErrorCode.ClientHttpFailedToOpenStream) {
163162
const status = (error.data as { status?: number })?.status;
164163
}
@@ -195,11 +194,11 @@ Update OAuth error handling:
195194

196195
```typescript
197196
// v1
198-
import { InvalidClientError, InvalidGrantError } from '@modelcontextprotocol/core';
197+
import { InvalidClientError, InvalidGrantError } from '@modelcontextprotocol/client';
199198
if (error instanceof InvalidClientError) { ... }
200199

201200
// v2
202-
import { OAuthError, OAuthErrorCode } from '@modelcontextprotocol/core';
201+
import { OAuthError, OAuthErrorCode } from '@modelcontextprotocol/client';
203202
if (error instanceof OAuthError && error.code === OAuthErrorCode.InvalidClient) { ... }
204203
```
205204

@@ -210,7 +209,7 @@ Zod schemas, all callback return types. Note: `callTool()` and `request()` signa
210209

211210
The variadic `.tool()`, `.prompt()`, `.resource()` methods are removed. Use the `register*` methods with a config object.
212211

213-
**IMPORTANT**: v2 requires schema objects implementing [Standard Schema](https://standardschema.dev/) — raw shapes like `{ name: z.string() }` are no longer supported. Wrap with `z.object()` (Zod v4), or use ArkType's `type({...})`, or Valibot. For raw JSON Schema, wrap with `fromJsonSchema(schema, validator)` from `@modelcontextprotocol/core`. Applies to `inputSchema`, `outputSchema`, and `argsSchema`.
212+
**IMPORTANT**: v2 requires schema objects implementing [Standard Schema](https://standardschema.dev/) — raw shapes like `{ name: z.string() }` are no longer supported. Wrap with `z.object()` (Zod v4), or use ArkType's `type({...})`, or Valibot. For raw JSON Schema, wrap with `fromJsonSchema(schema, validator)` from `@modelcontextprotocol/server`. Applies to `inputSchema`, `outputSchema`, and `argsSchema`.
214213

215214
### Tools
216215

docs/migration.md

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,12 @@ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
5252
```typescript
5353
import { Client, StreamableHTTPClientTransport, StdioClientTransport } from '@modelcontextprotocol/client';
5454
import { McpServer, StdioServerTransport, WebStandardStreamableHTTPServerTransport } from '@modelcontextprotocol/server';
55-
import { CallToolResultSchema } from '@modelcontextprotocol/core';
5655

5756
// Node.js HTTP server transport is in the @modelcontextprotocol/node package
5857
import { NodeStreamableHTTPServerTransport } from '@modelcontextprotocol/node';
5958
```
6059

61-
Note: `@modelcontextprotocol/client` and `@modelcontextprotocol/server` both re-export everything from `@modelcontextprotocol/core`, so you can import types from whichever package you already depend on.
60+
Note: `@modelcontextprotocol/client` and `@modelcontextprotocol/server` both re-export shared types from `@modelcontextprotocol/core`, so you can import types and error classes from whichever package you already depend on. Do not import from `@modelcontextprotocol/core` directly — it is an internal package.
6261

6362
### Dropped Node.js 18 and CommonJS
6463

@@ -117,7 +116,7 @@ Server-side OAuth/auth has been removed entirely from the SDK. This includes `mc
117116

118117
Use a dedicated auth library (e.g., `better-auth`) or a full Authorization Server instead. See the [examples](../examples/server/src/) for a working demo with `better-auth`.
119118

120-
Note: `AuthInfo` has moved from `server/auth/types.ts` to `@modelcontextprotocol/core` (it's now a core type).
119+
Note: `AuthInfo` has moved from `server/auth/types.ts` to the core types and is now re-exported by `@modelcontextprotocol/client` and `@modelcontextprotocol/server`.
121120

122121
### `Headers` object instead of plain objects
123122

@@ -252,7 +251,7 @@ server.registerTool('greet', {
252251
}, async ({ name }) => { ... });
253252

254253
// Raw JSON Schema via fromJsonSchema
255-
import { fromJsonSchema, AjvJsonSchemaValidator } from '@modelcontextprotocol/core';
254+
import { fromJsonSchema, AjvJsonSchemaValidator } from '@modelcontextprotocol/server';
256255
server.registerTool('greet', {
257256
inputSchema: fromJsonSchema({ type: 'object', properties: { name: { type: 'string' } } }, new AjvJsonSchemaValidator())
258257
}, handler);
@@ -434,6 +433,22 @@ const client = new Client(
434433
);
435434
```
436435

436+
### `InMemoryTransport` removed from public API
437+
438+
`InMemoryTransport` has been removed from the public API surface. It was previously used for in-process client-server connections and testing.
439+
440+
For **testing**, import it directly from the internal core package:
441+
442+
```typescript
443+
// v1
444+
import { InMemoryTransport } from '@modelcontextprotocol/sdk/inMemory.js';
445+
446+
// v2 (testing only — @modelcontextprotocol/core is internal, not for production use)
447+
import { InMemoryTransport } from '@modelcontextprotocol/core';
448+
```
449+
450+
For **production in-process connections**, use `StreamableHTTPClientTransport` with a local server URL, or connect client and server via paired streams.
451+
437452
### Removed type aliases and deprecated exports
438453

439454
The following deprecated type aliases have been removed from `@modelcontextprotocol/core`:
@@ -447,9 +462,9 @@ The following deprecated type aliases have been removed from `@modelcontextproto
447462
| `ResourceReferenceSchema` | `ResourceTemplateReferenceSchema` |
448463
| `ResourceReference` | `ResourceTemplateReference` |
449464
| `IsomorphicHeaders` | Use Web Standard `Headers` |
450-
| `AuthInfo` (from `server/auth/types.js`) | `AuthInfo` (now in `@modelcontextprotocol/core`) |
465+
| `AuthInfo` (from `server/auth/types.js`) | `AuthInfo` (now re-exported by `@modelcontextprotocol/client` and `@modelcontextprotocol/server`) |
451466

452-
All other types and schemas exported from `@modelcontextprotocol/sdk/types.js` retain their original names in `@modelcontextprotocol/core`.
467+
All other types and schemas exported from `@modelcontextprotocol/sdk/types.js` retain their original names — import them from `@modelcontextprotocol/client` or `@modelcontextprotocol/server`.
453468

454469
**Before (v1):**
455470

@@ -460,7 +475,7 @@ import { JSONRPCError, ResourceReference, isJSONRPCError } from '@modelcontextpr
460475
**After (v2):**
461476

462477
```typescript
463-
import { JSONRPCErrorResponse, ResourceTemplateReference, isJSONRPCErrorResponse } from '@modelcontextprotocol/core';
478+
import { JSONRPCErrorResponse, ResourceTemplateReference, isJSONRPCErrorResponse } from '@modelcontextprotocol/server';
464479
```
465480

466481
### Request handler context types
@@ -576,7 +591,7 @@ try {
576591
**After (v2):**
577592

578593
```typescript
579-
import { ProtocolError, ProtocolErrorCode, SdkError, SdkErrorCode } from '@modelcontextprotocol/core';
594+
import { ProtocolError, ProtocolErrorCode, SdkError, SdkErrorCode } from '@modelcontextprotocol/client';
580595

581596
try {
582597
await client.callTool({ name: 'test', arguments: {} });
@@ -633,7 +648,7 @@ try {
633648
**After (v2):**
634649

635650
```typescript
636-
import { SdkError, SdkErrorCode } from '@modelcontextprotocol/core';
651+
import { SdkError, SdkErrorCode } from '@modelcontextprotocol/client';
637652

638653
try {
639654
await transport.send(message);
@@ -703,7 +718,7 @@ The `OAUTH_ERRORS` constant has also been removed.
703718
**Before (v1):**
704719

705720
```typescript
706-
import { InvalidClientError, InvalidGrantError, ServerError } from '@modelcontextprotocol/core';
721+
import { InvalidClientError, InvalidGrantError, ServerError } from '@modelcontextprotocol/client';
707722

708723
try {
709724
await refreshToken();
@@ -721,7 +736,7 @@ try {
721736
**After (v2):**
722737

723738
```typescript
724-
import { OAuthError, OAuthErrorCode } from '@modelcontextprotocol/core';
739+
import { OAuthError, OAuthErrorCode } from '@modelcontextprotocol/client';
725740

726741
try {
727742
await refreshToken();

examples/client-quickstart/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
"@modelcontextprotocol/client/_shims": ["./node_modules/@modelcontextprotocol/client/src/shimsNode.ts"],
1616
"@modelcontextprotocol/core": [
1717
"./node_modules/@modelcontextprotocol/client/node_modules/@modelcontextprotocol/core/src/index.ts"
18+
],
19+
"@modelcontextprotocol/core/public": [
20+
"./node_modules/@modelcontextprotocol/client/node_modules/@modelcontextprotocol/core/src/exports/public/index.ts"
1821
]
1922
}
2023
},

examples/client/src/simpleStreamableHttp.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,14 +265,14 @@ async function connect(url?: string): Promise<void> {
265265
form: {}
266266
},
267267
tasks: {
268+
taskStore: clientTaskStore,
268269
requests: {
269270
elicitation: {
270271
create: {}
271272
}
272273
}
273274
}
274-
},
275-
taskStore: clientTaskStore
275+
}
276276
}
277277
);
278278
client.onerror = error => {

examples/client/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
"@modelcontextprotocol/core": [
1111
"./node_modules/@modelcontextprotocol/client/node_modules/@modelcontextprotocol/core/src/index.ts"
1212
],
13+
"@modelcontextprotocol/core/public": [
14+
"./node_modules/@modelcontextprotocol/client/node_modules/@modelcontextprotocol/core/src/exports/public/index.ts"
15+
],
1316
"@modelcontextprotocol/eslint-config": ["./node_modules/@modelcontextprotocol/eslint-config/tsconfig.json"],
1417
"@modelcontextprotocol/vitest-config": ["./node_modules/@modelcontextprotocol/vitest-config/tsconfig.json"],
1518
"@modelcontextprotocol/examples-shared": ["./node_modules/@modelcontextprotocol/examples-shared/src/index.ts"]

0 commit comments

Comments
 (0)