[Bug]: MCP SSE transport rejects concurrent requests on connect with "Received request before initialization was complete" (-32602)
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 66/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- python
- Ambito
- api, backend-api-design
Direzione di ricerca
Start with /app/mcp_bridge.py, comparing the /mcp/ws initialization gate with the SSE /mcp/sse and /mcp/messages flow through SseServerTransport. Reproduce with parallel tools/call requests during the initialize handshake and inspect the resulting session behavior. Done means concurrent SSE requests no longer fail with the pre-initialization -32602 response.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
crawl4ai version
0.9.2 (Docker server, unclecode/crawl4ai:latest)
Expected Behavior
When an MCP client (such as OpenCode, Claude Code, or multi-agent runtimes) connects over SSE (/mcp/sse) and issues tool calls, inbound requests arriving while initialization is completing should either be briefly buffered/queued or await initialization before processing, similar to how /mcp/ws gates incoming traffic.
Current Behavior
When a client establishes an SSE connection and dispatches tool calls concurrently (e.g. parallel fan-out upon connecting), the requests hit /mcp/messages/?session_id=... before the initialize -> notifications/initialized handshake has completed inside mcp.server.session.ServerSession.
This causes mcp/server/session.py to raise:
WARNING - Failed to validate request: Received request before initialization was complete
The client receives:
{"jsonrpc": "2.0", "id": 1, "error": {"code": -32602, "message": "Invalid request parameters"}}
The error code -32602 misleads clients into reporting that tool call parameters are malformed, when in reality the arguments were never validated because the transport rejected the uninitialized session state.
Context & Contrast with WebSocket
In /app/mcp_bridge.py, the WebSocket handler (/mcp/ws) explicitly mitigates this race condition by synchronizing on initialization:
# /app/mcp_bridge.py (WebSocket handler)
first = adapter.validate_python(await ws.receive_json())
await c2s_send.send(first)
await init_done.wait() # <-- explicitly waits for server readiness
while True:
data = await ws.receive_json()
await c2s_send.send(adapter.validate_python(data))
However, the SSE transport (/mcp/sse + /mcp/messages) directly passes through Starlette to SseServerTransport:
sse = SseServerTransport(f"{base}/messages/")
Without any gating on incoming POST requests during the handshake window, any concurrent requests arriving in the first ~100–500ms get rejected.
Upstream References
This is a known race condition in the underlying Python SDK:
- modelcontextprotocol/python-sdk #2583: "Race condition between SSE session init and tools/call rejection (-32602)"
- modelcontextprotocol/python-sdk #423: "MCP SSE Server: Received request before initialization was complete"
Suggested Fix
A minimal fix in mcp_bridge.py for the SSE transport:
- Wrap or intercept incoming POST messages to
/mcp/messagesto await session initialization (with a small timeout, e.g. 2.0s) before feeding them to the read stream writer, OR - Provide an
init_doneevent per SSE session matching the WebSocket pattern.
Steps to Reproduce
- Connect an MCP client over SSE (
/mcp/sse). - Immediately upon receiving the
endpointSSE event, dispatch 3+ paralleltools/callrequests in under 50ms alongsideinitialize. - Observe
Received request before initialization was completein Docker logs and-32602returned to the client.
Environment
- Docker container
unclecode/crawl4ai:latest(0.9.2) - Python 3.12 (inside container)
- Client: OpenCode / Claude Code via SSE transport
- Lingua principale
- Python
- Stelle
- 84.5k
- Fork
- 8.7k
- Merge medio
- 3g 20h
- PR unite (30g)
- 15
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di unclecode/crawl4ai
-
🐞 Bug 🩺 Needs Triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
unclecode/crawl4ai#2319 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
[Bug]: Reusing BFSDeepCrawlStrategy leaks the previous crawl's max_pages budget into a fresh runAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
unclecode/crawl4ai#2309 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 84/100
unclecode/crawl4ai#2147 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
unclecode/crawl4ai#2123 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
🐞 Bug 🩺 Needs Triage
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di unclecode/crawl4ai
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
kornia/kornia#5263 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
approved correction metadata
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
acl-org/acl-anthology#10133 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
BasedHardware/omi#20084 ·
I maintainer di solito rispondono entro 1 giorno
-
bug needs-acceptance wg/evaluation-quality
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
vllm-project/semantic-router#4424 ·
I maintainer di solito rispondono entro 1 giorno