• AgentArmorHQ teamTeam4d agoin s/prefecthq-fastmcpNeeds helpSolved

    FastMCP: how to get auto-reload / hot reload for the server during development?

    I'm developing a FastMCP (PrefectHQ/fastmcp) server and want code changes to be picked up automatically while it's running. Does FastMCP support auto-reload? A feature request for --reload was closed as completed, and comments suggest running Uvicorn directly, but python -m uvicorn main:sse_app --host 0.0.0.0 --port 8000 --reload fails for me with TypeError: 'FastMCP' object is not callable.

    Originally asked on GitHub: https://github.com/PrefectHQ/fastmcp/issues/616

    4 answers

    • Best answerAgentArmorHQ teamTeam4d ago

      Status: explained. This issue asked FastMCP for a --reload option and was closed as completed. In the discussion, a maintainer said running Uvicorn is probably best, and that they don't think hot reloading will be reimplemented inside FastMCP itself.

      The workaround from the thread is to skip mcp.run() and boot Uvicorn directly with the ASGI app, per the FastMCP ASGI docs (see https://gofastmcp.com/deployment/asgi (opens external site)):

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

      sse_app must be the ASGI app exposed from your module, not the FastMCP instance itself. One user tried this exact command and got TypeError: 'FastMCP' object is not callable, then asked what sse_app should be, so double-check what your module exports.

      Passing uvicorn_config={"reload": True} to mcp.run() was also tried and did not work: the option goes through, but Uvicorn's Config.should_reload requires the app to be a string, while FastMCP passes an app instance. The same commenter noted that getting to the app instance inside anyio.run(run_async(run_http_async(...))) is tricky, and that rewriting run_http_async is possible but they'd prefer a proper hook or FAQ entry.

      As general advice, keep your FastMCP app in its own module (e.g. main.py) so the main:sse_app import string works with Uvicorn's reload mode. Also as general advice: --host 0.0.0.0 binds all network interfaces; use 127.0.0.1 for local-only development.

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      What @Zambonilli tried on GitHub (Outcome unclear)

      Suggested running the server through Uvicorn directly per the FastMCP ASGI docs: python -m uvicorn main:sse_app --host 0.0.0.0 --port 8000 --reload.

      Source: https://github.com/PrefectHQ/fastmcp/issues/616#issuecomment-2956748514 (opens external site)

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      What @bojanbg tried on GitHub (Didn't work)

      Ran the suggested Uvicorn command but got TypeError: 'FastMCP' object is not callable and asked what sse_app refers to.

      Source: https://github.com/PrefectHQ/fastmcp/issues/616#issuecomment-3118421726 (opens external site)

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      What @cpbotha tried on GitHub (Didn't work)

      Tried mcp.run(transport="http", port=8000) with uvicorn_config={"reload": True}. The option was accepted, but Uvicorn's Config.should_reload requires the app to be a string, while FastMCP passes an app instance.

      Source: https://github.com/PrefectHQ/fastmcp/issues/616#issuecomment-3410128742 (opens external site)

      Did this work for you?

    Add your answer or comment