MCP SSE server: "Received request before initialization was complete" after redeploy
I serve a FastMCP SSE server (modelcontextprotocol/python-sdk, April 2025) with uvicorn. On first run, the MCP Inspector lists tools fine, but after I reload the server with the same command, the next tools/list or tools/call times out and the server logs 'RuntimeError: Received request before initialization was complete'. What causes this and what are the workarounds?
Originally asked on GitHub: https://github.com/modelcontextprotocol/python-sdk/issues/423
6 answers
Still open upstream as of the thread's last comment (May 2025). The error means the server received a JSON-RPC request (
tools/list,tools/call, ...) for a session that never completed the requiredinitializehandshake. Commenters traced this to clients/proxies that sendinitializetwice, or post to a session that died when the server was restarted.What worked in the thread:
-
Python client: call
initialize()explicitly. If you connect withmcp.client.sse.sse_client+ClientSession, addawait session.initialize()right after creating theClientSessionand before any tool call. One commenter confirmed this reliably fixed the error. -
Use
mcp-proxyinstead of supergateway. Per a commenter, supergateway sends its owninitializemessage on launch and then forwards the client's real one, so the server receivesinitializetwice. The same example worked flawlessly withmcp-proxy. A later comment noted the double-initialization bug was patched in supergateway 2.7.0, but another user still saw the error after a server reload even with 2.7.0, because some clients (anything-llm, fastagent) don't re-initialize the session after a disconnect. -
Temporary server-side patch. Monkeypatch
ServerSession._received_requestto swallow theRuntimeError:
pythonfrom mcp.server.fastmcp import FastMCP from mcp.server.session import ServerSession old = ServerSession._received_request async def _received_request(self, *args, **kwargs): try: return await old(self, *args, **kwargs) except RuntimeError: pass ServerSession._received_request = _received_requestThe author of this patch warned it is not a long-term fix, since it hides other
RuntimeErrors. A follow-up comment confirmed the error no longer appeared with it.Did this work for you?-
What @wilson-urdaneta tried on GitHub (Worked)
Added an explicit
await session.initialize()right after creating theClientSessionin a Python SSE client before calling tools; the error stopped occurring.Did this work for you?What @mheubi tried on GitHub (Worked)
Switched from supergateway to
mcp-proxy; the same FastMCP example then worked flawlessly, confirming supergateway was sending a secondinitializeagainst the protocol spec.Did this work for you?What @folkvir tried on GitHub (Worked)
Monkeypatched
ServerSession._received_requestto catch and ignore theRuntimeError; a follow-up comment confirmed the error no longer appeared.Did this work for you?What @Nedomas tried on GitHub (Partly worked)
Upgraded to supergateway 2.7.0, which patched the double-initialization bug; a later comment still got the error after reloading the server with that version.
Did this work for you?What a GitHub user tried on GitHub (Didn't work)
Reproduced with the FastMCP BMI/weather example under
uv run uvicorn main:app --port=8001 --host=0.0.0.0 --timeout-graceful-shutdown 5: the Inspector listed tools on first run, but after reloading the server, listing tools timed out with 'Received request before initialization was complete'.Source: https://github.com/modelcontextprotocol/python-sdk/issues/423 (opens external site)
Did this work for you?
Related questions
- MCP python-sdk simple-chatbot: 'Attempted to exit cancel scope in a different task than it was entered in'
- Why is my MCP resource template (greeting://{name}) not available in Claude Desktop?
- How to disable TLS certificate verification (verify=False) in MCP streamablehttp_client?
- anyio.ClosedResourceError in MCP StreamableHTTP message router on fast-failing requests?
- Python MCP SDK streamable HTTP: 'Error in message router' ClosedResourceError after 307 redirect