A factory and managed server extension for fastmcp
Project description
mcp-factory
A server factory based on fastmcp, supporting automatic registration of methods as tools, remote invocation, and permission-based management.
Features
- 🔧 Auto Tool Registration - Automatically register FastMCP native methods as callable tools
- 🚀 Remote Invocation - Provide MCP-based remote method invocation
- 🔐 Permission Control - Server management based on authentication mechanisms
- 🏭 Factory Pattern - Batch creation and management of server instances
- 🔄 Server Composition - Support secure server mounting and importing operations
- 🔁 Config Hot Reload - Update configuration without restarting
Installation
pip install mcp-factory # Using pip
# or
uv install mcp-factory # Using uv (recommended)
Quick Start
from mcp_factory import FastMCPFactory
# Create factory instance
factory = FastMCPFactory()
# Create authentication provider
factory.create_auth_provider(
provider_id="demo-auth0",
provider_type="auth0",
config={
"domain": "your-domain.auth0.com",
"client_id": "your-client-id",
"client_secret": "your-client-secret"
}
)
# Create server with configuration file
server = factory.create_managed_server(
config_path="config.yaml",
auth_provider_id="demo-auth0",
expose_management_tools=True
)
# Register custom tool
@server.tool(description="Calculate the sum of two numbers")
def add(a: int, b: int) -> int:
return a + b
# Start server
server.run()
Configuration
Minimal configuration example:
server:
name: "my-mcp-server"
instructions: "This is an example MCP server"
host: "0.0.0.0"
port: 8000
auth:
provider_id: "demo-auth0"
tools:
expose_management_tools: true
For complete configuration examples, please refer to examples/config.example.yaml
Advanced Features
Configuration Hot Reload
# Reload configuration from specified path
result = server.reload_config("new_config.yaml")
print(result) # Output: Server configuration reloaded (from new_config.yaml)
Server Composition
# Create two servers
server1 = factory.create_managed_server(config_path="main_config.yaml")
server2 = factory.create_managed_server(config_path="compute_config.yaml")
# Securely mount server
await server1.mount("compute", server2)
# Unmount server
server1.unmount("compute")
Auto-registered Management Tools
When setting expose_management_tools=True, the server automatically registers management tools:
# Get all auto-registered management tools
tools = await server.get_tools()
for tool in tools:
if tool.name.startswith("manage_"):
print(f"Management Tool: {tool.name} - {tool.description}")
# Example management tools
await server.manage_reload_config() # Reload configuration
await server.manage_get_server_info() # Get server information
await server.manage_list_mounted_servers() # List mounted servers
Note: MCP-Factory fully supports the native features of FastMCP, including lifecycle management (lifespan), tool serializers (tool_serializer), etc. Please refer to the FastMCP documentation for details.
Common APIs
# Authentication provider management
factory.create_auth_provider(provider_id="id", provider_type="auth0", config={})
factory.list_auth_providers()
factory.remove_auth_provider("id")
# Server management
factory.list_servers()
factory.delete_server("name")
factory.get_server("name")
For more examples and complete API documentation, please refer to the examples/ directory.
Roadmap
The following features are planned for future versions:
- Command Line Tool - Provide
mcpfcommand-line tool to simplify the creation and management of servers and authentication providers - More Authentication Providers - Add support for various authentication mechanisms such as OAuth2, JWT, etc.
- Multi-environment Configuration - Support configuration management for development, testing, production, and other environments
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mcp_factory-0.1.1.tar.gz.
File metadata
- Download URL: mcp_factory-0.1.1.tar.gz
- Upload date:
- Size: 27.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44afd484991e7aaad3223161287a8d6b6230561b9029b1384f63f4b4f593d662
|
|
| MD5 |
03aa79086ab001885f75cceae0318192
|
|
| BLAKE2b-256 |
25bd72cbfc8d7a0a77f0ea9e9785163986f04c419f6e3ef87a95d85fd33f530c
|
File details
Details for the file mcp_factory-0.1.1-py3-none-any.whl.
File metadata
- Download URL: mcp_factory-0.1.1-py3-none-any.whl
- Upload date:
- Size: 26.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6fb85d14379614c8ba7a6af26fc6a2a8b4b06b5c5c408d8d066df34640cf17e
|
|
| MD5 |
5ad3c683a7b9a856bd5043759e7a3576
|
|
| BLAKE2b-256 |
56d2afd97d6064d449d5808439c9953bf863729cab155f1aef42a86654c5296b
|