-
Notifications
You must be signed in to change notification settings - Fork 317
New lifespan for every session? #166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Can you please provide an MRE? I am not sure if that is behavior caused by FastMCP or MCP (or both, if a FastMCP client is dynamically invoking a low level server). FastMCP's only interaction with the lifespan object is to pass it directly to the low-level server. |
Run via sse, set a breakpoint in the lifespan context manager and then open MCP Inspector and connect. The breakpoint will not hit after running the server. The breakpoint will hit when you connect, and every time you press i.e. it looks like the lifespan is only used when a user connects and is not actually for server startup / shutdown? |
I may have lied about it not hitting after starting the server, I am seeing it hit when starting the server and for each connection.
It looks like mcp_server.run() is calling run for every sse session and every call to run invokes the lifespan context manager again. It looks like this is the intended behavior, I would have expected it to be called a server session or something similar instead of a server but it seems like if we want to share things, like connections to databases, across sessions the |
It seems like maybe the server is invoking a new lifespan for every sse connection?
I think it should only be invoking the lifespan once but providing the yielded objects in the context to each request?
The text was updated successfully, but these errors were encountered: