Skip to content

Commit f451229

Browse files
committed
test(mcp): update stateful MCP assertions for the stateless endpoint
The hub aggregate-MCP and Next handler tests still exercised the 2025 initialize/Mcp-Session-Id handshake. Serve them statelessly: the hub test lists tools with a single per-request POST, and both assert no session id is issued.
1 parent 15b75be commit f451229

2 files changed

Lines changed: 7 additions & 34 deletions

File tree

packages/hub/src/node/__tests__/initiate.test.ts

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -297,49 +297,20 @@ describe('initHub', () => {
297297
await hub.ready
298298
expect(hub.connectionMeta().mcp).toEqual({ path: '__mcp' })
299299

300+
// The endpoint is stateless: a single `tools/list` POST is answered per
301+
// request, with no `initialize` handshake and no `Mcp-Session-Id`.
300302
const origin = 'http://localhost:3000'
301-
const init = await hub.handler(new Request(`${origin}/__devframes/__mcp`, {
302-
method: 'POST',
303-
headers: {
304-
'content-type': 'application/json',
305-
'accept': 'application/json, text/event-stream',
306-
origin,
307-
},
308-
body: JSON.stringify({
309-
jsonrpc: '2.0',
310-
id: 1,
311-
method: 'initialize',
312-
params: { protocolVersion: '2025-03-26', capabilities: {}, clientInfo: { name: 'x', version: '0' } },
313-
}),
314-
}))
315-
expect(init.status).toBe(200)
316-
const sessionId = init.headers.get('mcp-session-id')
317-
expect(sessionId).toBeTruthy()
318-
await init.body?.cancel()
319-
320-
const initialized = await hub.handler(new Request(`${origin}/__devframes/__mcp`, {
321-
method: 'POST',
322-
headers: {
323-
'content-type': 'application/json',
324-
'accept': 'application/json, text/event-stream',
325-
'mcp-session-id': sessionId!,
326-
origin,
327-
},
328-
body: JSON.stringify({ jsonrpc: '2.0', method: 'notifications/initialized' }),
329-
}))
330-
await initialized.body?.cancel()
331-
332303
const list = await hub.handler(new Request(`${origin}/__devframes/__mcp`, {
333304
method: 'POST',
334305
headers: {
335306
'content-type': 'application/json',
336307
'accept': 'application/json, text/event-stream',
337-
'mcp-session-id': sessionId!,
338308
origin,
339309
},
340310
body: JSON.stringify({ jsonrpc: '2.0', id: 2, method: 'tools/list' }),
341311
}))
342312
expect(list.status).toBe(200)
313+
expect(list.headers.get('mcp-session-id')).toBeNull()
343314
const raw = await list.text()
344315
// Tools from both frames surface through the one aggregate endpoint.
345316
expect(raw).toContain('alpha-tool')

packages/next/test/handler.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ describe('createDevframeNextHandler', () => {
9898

9999
// The advertised endpoint answers MCP initialize through the route
100100
// handler when a loopback Origin (required by the route's gate) is
101-
// presented.
101+
// presented. A 2025-era `initialize` is served statelessly through the
102+
// SDK's default legacy path — answered per request with no
103+
// `Mcp-Session-Id`.
102104
const origin = 'http://localhost:3000'
103105
const initBody = JSON.stringify({
104106
jsonrpc: '2.0',
@@ -116,7 +118,7 @@ describe('createDevframeNextHandler', () => {
116118
body: initBody,
117119
}))
118120
expect(init.status).toBe(200)
119-
expect(init.headers.get('mcp-session-id')).toBeTruthy()
121+
expect(init.headers.get('mcp-session-id')).toBeNull()
120122
await init.body?.cancel()
121123

122124
// Without an Origin header the same request is rejected.

0 commit comments

Comments
 (0)