With FastMCP.from_fastapi, how to pass lifespan to FastAPI app since it is already created? #559
-
In https://gofastmcp.com/deployment/asgi#fastapi-integration, we can see how to mount the FastMCP app under a path of our FastAPI app. Problem is, when we leverage https://gofastmcp.com/patterns/fastapi to create our MCP Server from an existing FastAPI app, it is too late to pass the lifespan context from the FastMCP app to the FastAPI app (chicken and egg problem). Is there any way to benefit from the ASGI FastAPI integration when we also use Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Did you figure it out? The docs warn:
I'm having difficulty understanding this without an example, am I doing it correctly?
|
Beta Was this translation helpful? Give feedback.
Yes I managed to have something working properly:
With
create_mcp_server
defined as:By doing so my app is both a regular FastAPI app exposing REST endpoints and a FastMCP app expo…