About MCP Hot Update Server Demo
MCP Hot Update Server Demo is a FastMCP example that loads utility functions from JSON and updates registered tools without restarting. It is aimed at demonstrating dynamic tool management; its use of exec() requires additional safeguards for production.
Key features
- 01Load utility functions dynamically
- 02Manage tools with JSON configuration
- 03Update tools without restarting
- 04Error handling and logging
Use cases
- 01Test dynamic MCP tool registration
- 02Change utility functions through JSON
- 03Explore hot updates during development
MCP support
The server loads functions defined in JSON configuration and registers them as MCP tools. It uses exec() to run the supplied code.
Configuration
Local server config is the same for every client. Copy it into your client’s MCP config file.
We haven’t collected a package or remote endpoint for this server. Follow the instructions in the project README.
Tools
Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.
Details
From the project READMEMCP Hot Update Server Demo
中文文档 | DeepWiki for this Repository
This is a hot update server example based on the FastMCP framework, allowing dynamic loading and updating of utility functions without restarting the server.
Features
- Supports dynamic loading of utility functions
- Manage tools via JSON configuration files
- Real-time hot update capability
- Detailed error handling and logging
Key Code
exec(tool_code, globals(), local_namespace)
if inspect.isfunction(obj) and obj.__name__ in local_namespace:
if found_func is not None:
# Handle potential duplicate function definition if needed
pass # Or log a warning, raise an error, etc.
found_func = obj
if found_func:
# Add the tool to MCP using the database name
mcp.tool(
name=tool_name, description=tool_description
)(found_func)
print(f"Successfully registered tool '{tool_name}'")
🚀 Quick Start
1️⃣ Environment Setup
Make sure you have Python 3.7+ installed. Then, install the required library:
$ pip install fastmcp
fastmcp: Python implementation library for MCP.
2️⃣ Run MCP Server
$ python server.py
- The
tools.jsonfile format is as follows:
[
{
"name": "Tool Name",
"description": "Tool Description",
"code": "def function_name(params):\n # Function implementation\n return result"
}
]
Security Notes
⚠️ Important Security Warning:
- The current implementation uses
exec()to execute code read from the JSON file - Additional security measures are required for production environments:
- Code signature verification
- Sandbox environment restrictions
- Code review mechanisms
- Access control
Development Suggestions
- Test all utility functions in the development environment
- Ensure the JSON file format is correct
- Add appropriate error handling
- Implement a code review process
- Consider adding version control mechanisms
Workflow
graph TD
A[Start Server] --> B[Load tools.json]
B --> C{Parse JSON}
C -->|Success| D[Iterate Tool List]
C -->|Failure| E[Output Error Log]
D --> F[Execute Tool Code]
F --> G{Code Execution}
G -->|Success| H[Register to MCP]
G -->|Failure| I[Output Error Log]
H --> J[Server Running]
J --> K[Wait for New Requests]
Comments
New to MCP?
From what the protocol is to installing your first server, these answers cover most first questions.
An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.