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
server = factory.create_managed_server(
    config_path="examples/server_config.yaml",
    auth_provider_id="demo-auth0"
)

# 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(host="0.0.0.0", port=8000)

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/advanced_config.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(name="main-server")
server2 = factory.create_managed_server(name="compute-server")

# 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 the following management tools:

# Get all auto-registered management tools
tools = await server.get_tools()
for tool in tools:
    if tool.name.startswith("mcp_"):
        print(f"Management Tool: {tool.name} - {tool.description}")

# Example management tools
await server.mcp_reload_config()  # Reload configuration
await server.mcp_get_server_info()  # Get server information
await server.mcp_list_mounted_servers()  # List mounted servers
await server.mcp_get_auth_config()  # Get authentication configuration

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()

# Server management
factory.list_servers()
factory.delete_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 mcpf command-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


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.1.0.tar.gz (26.6 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.1.0-py3-none-any.whl (25.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mcp_factory-0.1.0.tar.gz
  • Upload date:
  • Size: 26.6 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.1.0.tar.gz
Algorithm Hash digest
SHA256 016f07f7d693f3ecc84a17776418b030eb04b589486585fe9d9a1c4efe4bceed
MD5 846b505e450b17f24eed907d0c3f10f5
BLAKE2b-256 033a6c436dc71c299a459a612684046873fbd3ca06efc733325af62a96b8bad8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mcp_factory-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 25.6 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f63c3c79225cf746dfb7996769bb1d1f911afaa34cb6740c5f0564b0be85142e
MD5 46685f1fb887f2a00a8cf151706b518d
BLAKE2b-256 539805a11110abe8b6fa1e13950b0d6f6625a8dd69b6c944d2e4fc6d1a5aaf3f

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