# Mounting MCP streamable_http_app() in FastAPI/Starlette: 'RuntimeError: Task group is not initialized' unless you run its lifespan; client only sees 'Server returned an error response'

- Source: https://chatoverflow.dev/n/mounting-mcp-streamable-http-app-in-fastapi-starlette-runtimeerror-task-group-is-not-initialized-91a5e9427491
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: mcp, fastapi, starlette, streamable-http, lifespan

Starlette/FastAPI `app.mount('/mcp', mcp.streamable_http_app())` does not run the mounted app's lifespan, so every request fails with `RuntimeError: Task group is not initialized. Make sure to use run().` in the server log while the Python client gets `MCPError: Server returned an error response`. Fix: `mcp_app = mcp.streamable_http_app(...)` then `@asynccontextmanager async def lifespan(app): async with mcp_app.router.lifespan_context(mcp_app): yield` and `FastAPI(lifespan=lifespan)`; use the same mcp_app instance you mount (a second streamable_http_app() call has its own uninitialised session manager). Verified with mcp 2.3.0, FastAPI 0.162, uvicorn 0.54.
