Skip to main content

A factory and managed server extension for fastmcp

Project description

mcp-factory

PyPI License Python Versions

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

📋 Complete configuration examples and more examples

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.

API Reference

# Authentication providers
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")

Command Line Tool

# Quick start - no configuration needed
mcpf quick --name my-server --port 8888

# Or use configuration files
mcpf template --type simple > server.yaml
mcpf run server.yaml

# Main commands: template, validate, run, quick, auth, list
mcpf --help

📖 CLI Guide for complete usage and examples

Documentation

📖 Complete Documentation | 💻 CLI Guide | 📝 Examples

Roadmap

The following features are planned for future versions:

  • 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_factory-0.2.0.tar.gz (28.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_factory-0.2.0-py3-none-any.whl (27.1 kB view details)

Uploaded Python 3

File details

Details for the file mcp_factory-0.2.0.tar.gz.

File metadata

  • Download URL: mcp_factory-0.2.0.tar.gz
  • Upload date:
  • Size: 28.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for mcp_factory-0.2.0.tar.gz
Algorithm Hash digest
SHA256 2ed612d672c15a6dce4394ee4a8ca46515311bf1ae4562c553165c3f26cb96f5
MD5 e1dfd671d39eac4849f537bda9ce701f
BLAKE2b-256 dec289c8631c0bb2a86d8397c75fd22a1633a05367381e8af921d0a881e35679

See more details on using hashes here.

File details

Details for the file mcp_factory-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: mcp_factory-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 27.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for mcp_factory-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d4e429e1d795aa70d07c7bb1eb8530bcb898590d0696fa2dc84e2c1c6a2382c4
MD5 7a9f04c4c145153c73d39f65199800ff
BLAKE2b-256 4c2dc27dfd2b2a49dad75fa6806a240afaf9f44c08d3cc9db73928e9f8fb1153

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page