Skip to content

fix(mcp): gate SSE session until initialize completes - #2234

Open
Zsanz3 wants to merge 1 commit into
unclecode:mainfrom
Zsanz3:cursor/fix-mcp-sse-init-gate-629d
Open

fix(mcp): gate SSE session until initialize completes#2234
Zsanz3 wants to merge 1 commit into
unclecode:mainfrom
Zsanz3:cursor/fix-mcp-sse-init-gate-629d

Conversation

@Zsanz3

@Zsanz3 Zsanz3 commented Sep 8, 2026

Copy link
Copy Markdown

Fixes #2233

Problem

MCP SSE could accept concurrent POSTs (e.g. tools/call) before initialize finished, which surfaces as -32602 Received request before initialization was complete. WebSocket already had an init_done latch; SSE did not.

Fix

In deploy/docker/mcp_bridge.py, add _run_with_init_gate for SSE sessions: allow the first frame (initialize) immediately, wait for the server's first write (initialize result) to set init_done, then feed later messages into the read stream. Bridge-only latch — does not patch the upstream MCP SDK race.

Test

tests/test_issue_2233_mcp_sse.py — source-shape check plus anyio behavior coverage for the gate.

Does not touch #2226.

SSE /mcp/messages POSTs could reach ServerSession before the handshake
finished, causing -32602 "Received request before initialization was
complete". Mirror the WebSocket init_done latch in the bridge so later
frames wait for the initialize result.

Co-authored-by: Zsanz3 <Zsanz3@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: MCP SSE transport rejects concurrent requests on connect with "Received request before initialization was complete" (-32602)

2 participants