Skip to content

Commit 00d83d5

Browse files
feat(core): deprecate sessionId on base Transport/BaseContext; legacySessionId() helper (SEP-2567)
1 parent 2358111 commit 00d83d5

4 files changed

Lines changed: 39 additions & 2 deletions

File tree

docs/migration.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,24 @@ import { JSONRPCError, ResourceReference, isJSONRPCError } from '@modelcontextpr
573573
import { JSONRPCErrorResponse, ResourceTemplateReference, isJSONRPCErrorResponse } from '@modelcontextprotocol/server';
574574
```
575575

576+
### `sessionId` deprecated (SEP-2567)
577+
578+
`ctx.sessionId` and `Transport.sessionId` are deprecated. Sessions are extension-track per SEP-2567; 2026-06+ clients will not send `Mcp-Session-Id`. The fields remain (optional, as before) but will be `undefined` for stateless clients.
579+
580+
**Do not key application state on `sessionId`.** Key on the validated principal instead:
581+
582+
```ts
583+
// Before (silently shares state across stateless clients)
584+
const prefs = perSession.get(ctx.sessionId);
585+
586+
// After
587+
const principal = ctx.http?.authInfo?.token;
588+
if (!principal) throw new ProtocolError(ProtocolErrorCode.InvalidRequest, 'auth required');
589+
const prefs = perPrincipal.get(principal);
590+
```
591+
592+
Use `legacySessionId(transport)` for an explicit-intent read where session-mode compat is needed.
593+
576594
### Request handler context types
577595

578596
The `RequestHandlerExtra` type has been replaced with a structured context type hierarchy using nested groups:

packages/core/src/exports/public/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export { deserializeMessage, ReadBuffer, serializeMessage } from '../../shared/s
7070

7171
// Transport types (NOT normalizeHeaders)
7272
export type { FetchLike, Transport, TransportSendOptions } from '../../shared/transport.js';
73-
export { createFetchWithInit } from '../../shared/transport.js';
73+
export { createFetchWithInit, legacySessionId } from '../../shared/transport.js';
7474
export { InMemoryTransport } from '../../util/inMemory.js';
7575

7676
// URI Template

packages/core/src/shared/context.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ export type NotificationOptions = {
112112
export type BaseContext = {
113113
/**
114114
* The session ID from the transport, if available.
115+
* @deprecated Sessions are extension-track per SEP-2567; 2026-06+ clients will not
116+
* send `Mcp-Session-Id`. Key application state on `ctx.http?.authInfo`, not session-id.
115117
*/
116118
sessionId?: string;
117119

@@ -265,7 +267,11 @@ export type RequestEnv = {
265267
/** Abort signal for the inbound request. If omitted, a fresh controller is created. */
266268
signal?: AbortSignal;
267269

268-
/** Transport session identifier (legacy `Mcp-Session-Id`). */
270+
/**
271+
* Transport session identifier (legacy `Mcp-Session-Id`).
272+
* @deprecated Sessions are extension-track per SEP-2567. Populate `ext.sessionId` for
273+
* compat modules that need it; new code should not depend on this.
274+
*/
269275
sessionId?: string;
270276

271277
/**

packages/core/src/shared/transport.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ export interface Transport {
118118

119119
/**
120120
* The session ID generated for this connection.
121+
* @deprecated Sessions are extension-track per SEP-2567; 2026-06+ clients will not
122+
* send `Mcp-Session-Id`. Key application state on `ctx.http?.authInfo`, not session-id.
123+
* Read via {@linkcode legacySessionId} for an explicit signal.
121124
*/
122125
sessionId?: string | undefined;
123126

@@ -132,3 +135,13 @@ export interface Transport {
132135
*/
133136
setSupportedProtocolVersions?: ((versions: string[]) => void) | undefined;
134137
}
138+
139+
/**
140+
* Read `sessionId` from a transport if it exposes one. Explicit-intent helper for
141+
* SEP-2567: sessions are extension-track and `undefined` for 2026-06+ clients.
142+
* Prefer keying application state on `ctx.http?.authInfo`; use this only when interoperating
143+
* with pre-2026-06 clients that send `Mcp-Session-Id`.
144+
*/
145+
export function legacySessionId(t: Transport | undefined): string | undefined {
146+
return t?.sessionId;
147+
}

0 commit comments

Comments
 (0)