Python MCP Server with HOT Reload 🔥 #602
CNSeniorious000
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Pre-submission Checklist
What would you like to share?
Introducing
mcp-hmr, which is a Python library that provide drop-in replacement formcp runwith fine-grained on-demand hot reload.That's it. No config needed. Works with both the official Python SDK and FastMCP v2.
Demo
mcp-inspector-demo.mov
Notice how the server updates instantly without dropping the connection to the client. This is the magic of the underlying HMR library.
Why?
MCP development typically involves frequent iteration on tools, resources, and prompts. Traditional reloaders (like
--reloadflags) restart the entire process on every file change, forcing:With
mcp-hmr, only the changed modules and their dependents reload. Everything else stays running. For servers with expensive initialization (loading models, connecting to databases, etc.), this saves significant time.How it works
Under the hood,
mcp-hmruses:hmr- Runtime dependency tracking and reactive module reloadingFastMCP.mount- Hot swapping of the underlyingFastMCP/mcp.server.FastMCPinstancesThe reloading is fine-grained (only affected modules rerun) and on-demand (only triggered by actual changes).
Usage
If your server instance is
appinmain.py:Or using file path:
Both formats work. The server will automatically reload on code changes while maintaining the connection to your MCP client.
Example
See the full example in the repo.
Run with:
When modifying the
echotool orgreetresource in your editor, the changes take effect immediately without restarting the connection.Relevant Links
Built on top of
hmr, which also powersuvicorn-hmrfor FastAPI/Starlette applications.Just like Vite and Vitest bring HMR to JavaScript,
hmrbrings fine-grained hot reloading to Python. The goal is to make Python development as smooth as modern frontend tooling.Beta Was this translation helpful? Give feedback.
All reactions