fastmcp icon indicating copy to clipboard operation
fastmcp copied to clipboard

Add --reload

Open sosoxuc opened this issue 7 months ago • 5 comments

Enhancement Description

Add --reload to automatically use changed code

Use Case

No response

Proposed Implementation


sosoxuc avatar May 28 '25 14:05 sosoxuc

This would be really helpful: it's already supported by lower-level frameworks like Starlette and Uvicorn.

dkmiller avatar May 31 '25 18:05 dkmiller

A workaround is to follow the ASGI docs and boot from uvicorn directly in the cli.

python -m uvicorn main:sse_app --host 0.0.0.0 --port 8000 --reload

Zambonilli avatar Jun 09 '25 19:06 Zambonilli

A workaround is to follow the ASGI docs and boot from uvicorn directly in the cli.

python -m uvicorn main:sse_app --host 0.0.0.0 --port 8000 --reload

Doesn't work for me, I get TypeError: 'FastMCP' object is not callable. What is sse_app in your example?

bojanbg avatar Jul 25 '25 15:07 bojanbg

I agree that using uvicorn is probably best (I don’t think we will attempt to reimplement hot reloading in FMCP) but I think we could do more to surface this in a FAQ!

jlowin avatar Jul 25 '25 18:07 jlowin

Starting from the normal mcp.run(transport="http", port=8000) it's a bit tricky to get to the app instance (for uvicorn.run) which gets created e.g. inside of anyio.run(run_async(run_http_async(...)))

I also tried passing in uvicorn_config={"reload": True} to mcp.run() -- this does go through, but the uvicorn.Config.should_reload property requires app to be a string not an app instance.

We can obviously just redo the whole run_http_async e.g., but it would indeed be great to have a more convenient hook and/or FAQ for reloading in FastMCP.

cpbotha avatar Oct 16 '25 10:10 cpbotha