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
20 changes: 14 additions & 6 deletions examples/servers/typescript/everything-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1284,13 +1284,21 @@ app.post('/mcp', async (req, res) => {
const meta = params._meta;
const metaVersion = meta?.['io.modelcontextprotocol/protocolVersion'];

// A request that carries no `_meta` and names a legacy session-era revision
// in the header is legacy traffic; it is served by the session path below
// instead of being rejected for missing per-request metadata.
// An initialize request negotiates its version in params and may carry the
// optional RequestParams `_meta` field. Route session-era versions through
// the stateful transport even when that metadata is present.
const isLegacyInitializeRequest =
isInitializeRequest(body) &&
typeof params.protocolVersion === 'string' &&
LEGACY_SESSION_PROTOCOL_VERSIONS.includes(params.protocolVersion);

// A non-initialize request that carries no `_meta` and names a legacy
// session-era revision in the header is also legacy traffic.
const isLegacySessionEraRequest =
meta === undefined &&
reqVersion !== undefined &&
LEGACY_SESSION_PROTOCOL_VERSIONS.includes(reqVersion);
isLegacyInitializeRequest ||
(meta === undefined &&
reqVersion !== undefined &&
LEGACY_SESSION_PROTOCOL_VERSIONS.includes(reqVersion));

if (!sessionId && (reqVersion || meta) && !isLegacySessionEraRequest) {
// Missing Transport Header Validation Check
Expand Down
31 changes: 31 additions & 0 deletions src/scenarios/server/all-scenarios.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,37 @@ describe('Server Scenarios', () => {
expect(nonFailures.length).toBe(checks.length);
}

it('accepts request metadata on a stateful initialize', async () => {
const response = await fetch(serverUrl, {
method: 'POST',
headers: {
Accept: 'application/json, text/event-stream',
'Content-Type': 'application/json'
},
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'initialize',
params: {
protocolVersion: '2025-11-25',
capabilities: {},
clientInfo: { name: 'metadata-test', version: '1.0.0' },
_meta: {}
}
})
});

const sessionId = response.headers.get('mcp-session-id');
expect(response.status).toBe(200);
expect(sessionId).toBeTruthy();
expect(await response.text()).toContain('"protocolVersion":"2025-11-25"');

await fetch(serverUrl, {
method: 'DELETE',
headers: { 'mcp-session-id': sessionId! }
});
});

for (const scenarioName of scenarios) {
it(`${scenarioName}`, async () => {
await expectScenarioToPass(scenarioName);
Expand Down
Loading