-
Notifications
You must be signed in to change notification settings - Fork 671
Server is Shutdown when hot reload (FastMCP + FastAPI) #296
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
The low-level MCP server does not have the ability to shut down gracefully, and a new server is started for every SSE connection - that is why it is hanging. I have a branch in flight that will solve this for a different purpose. |
Actually this is more challenging to fix without modifying the low level server - however unfortunately it is not a FastMCP issue, as much as I would like to solve it as well. |
I am seeing the same issue + discussion in the mcp python repo, modelcontextprotocol/python-sdk#514. This pull request was one of the proposed solutions, modelcontextprotocol/python-sdk#586. Cross posting in case it's helpful for others. |
Thanks @jlowin @westonplatter a lot. I think i will wait for next release |
Ah ha! Found a work around solution per @mattmess1221's comment. I was able to change the file, see the fastapi mcp app reboot, and reconnect to it using MCP Inspector # where my fastapi app is located in app/main.py as app
UVICORN_TIMEOUT_GRACEFUL_SHUTDOWN=0 uvicorn app.main:app --reload Using |
@westonplatter while we wait for low-level improvements, #323 allows you to pass a graceful timeout shutdown param directly without the env var, and defaults it to 0. Hopefully that helps! |
downgrade uvicorn pip install uvicorn==0.21.1 |
Description
I added FastAPI into my code to perform reload when something changed.
My server.py:
Start server command:
uvicorn app.server:app --host 0.0.0.0 --port 8000 --reload
Everything fine till I perform save file server.py, this time server will reload and shutdown
Example Code
Version Information
Additional Context
No response
The text was updated successfully, but these errors were encountered: