Skip to content

Commit b0d286d

Browse files
fix(sessionCompat): reject initialize POST that carries Mcp-Session-Id (v1 parity); ci: run dual-target server conformance
1 parent 284f01e commit b0d286d

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

.github/workflows/conformance.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ jobs:
4848
cache-dependency-path: pnpm-lock.yaml
4949
- run: pnpm install
5050
- run: pnpm run build:all
51-
- run: pnpm run test:conformance:server
51+
- run: pnpm run test:conformance:server:dual

packages/server/src/server/sessionCompat.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,18 @@ export class SessionCompat {
146146
response: jsonError(400, -32_600, 'Invalid Request: Only one initialization request is allowed')
147147
};
148148
}
149+
// v1 parity: an initialize POST that already carries an Mcp-Session-Id is a
150+
// re-init against an existing session and is rejected (the v1 app pattern
151+
// routed it to the existing transport, which returned "Server already
152+
// initialized"). Without this check a confused/retrying client mints a new
153+
// session per retry in multi-session mode.
154+
if (req.headers.get('mcp-session-id') !== null) {
155+
this._onerror?.(new Error('Invalid Request: initialize must not carry Mcp-Session-Id'));
156+
return {
157+
ok: false,
158+
response: jsonError(400, -32_600, 'Invalid Request: Server already initialized')
159+
};
160+
}
149161
this._evictIdle();
150162
if (this._singleSession && this._sessions.size > 0) {
151163
this._onerror?.(new Error('Invalid Request: Server already initialized'));

0 commit comments

Comments
 (0)