How acnet-ai/mcp-factory works
Project type and purpose
• This is an open-source Python “factory framework” (library + CLI tool) for creating, configuring, mounting, and running MCP (Model Context Protocol) servers.
• It provides programmatic API (MCPFactory, ManagedServer), a YAML-based configuration system, a project-scaffolding mode, and a CLI front-end.
File structure
• Top-level modules:
• mcp_factory/cli – CLI commands, helpers, error filters
• mcp_factory/config – configuration manager and schema
• mcp_factory/factory.py – MCPFactory core
• mcp_factory/server.py – ManagedServer
• mcp_factory/auth.py – authentication providers
• mcp_factory/middleware.py – server middleware hooks
• mcp_factory/mounting – multi-server mounting (models, mounter, registry)
• mcp_factory/project – project builder, template, validator, publisher
• Configuration files & examples:
• examples/… YAML configs and demo scripts
• docs/architecture – detailed architecture docs
• Tests are organized by unit, integration, e2e; CI workflows and code coverage in .github and .codecov.yml
README for additional insights
• Core components listed: MCPFactory, ManagedServer, Configuration System, Project Builder
• Operation modes: dict-based, file-based, project-scaffold, direct server creation
• Auth: JWT or OAuth2 with 4 permission levels
• Management tools: decorator + auto-registration of 20+ native tools
a. Main components to include:
• CLI Layer (mcp-factory commands)
• Factory Core (MCPFactory)
• Config Manager & Schema (YAML/dict loader + validator)
• Authentication Provider (JWT/OAuth2)
• Project Builder / Publisher (scaffolding + template engine)
• ManagedServer (tool registration, middleware pipeline, HTTP transport)
• Mounting System (Mounter, Registry, multi-server management)
• Management Tools Registry (20+ tools with permission levels)
• File System / Workspace Root (generated project structures, config files)
• External Dependencies (FastMCP, YAML files, environment variables, external auth server)
b. Relationships & interactions:
• CLI → invokes MCPFactory or ManagedServer entrypoints
• MCPFactory → uses Config Manager to parse & validate configuration
• Config Manager → supplies config to Factory or direct server
• Factory.create_server → orchestrates Project Builder + Publisher → writes to workspace
• Factory.create_server → instantiates ManagedServer + mounts configured tools
• ManagedServer → registers tools (decorator-based) into Tools Registry
• ManagedServer → applies Middleware chain on incoming requests
• ManagedServer → consults Auth Provider for permission checks
• Mounter / Registry → manages multiple ManagedServer instances within one process
• HTTP Transport Layer → exposes server endpoints to clients
• External auth server (if OAuth2) ←→ Auth Provider
c. Architectural patterns & design principles:
• Factory Pattern (MCPFactory) for abstracting server creation
• Builder / Template Pattern (Project Builder) for scaffolding file structure
• Decorator Pattern (@server.tool) for registering tools
• Plugin Architecture (middleware, management tools, custom components)
• Separation of concerns: CLI, config, auth, factory, server, project, mounting
d. Key technologies & libraries:
• Python ≥3.10
• Click or Typer (for CLI commands in mcp_factory/cli)
• PyYAML (configuration loading)
• FastMCP (underlying server library, native tools)
• Jinja2 or built-in template engine (project scaffolding)
• JWT / OAuth2 libraries (auth)
Essential details to capture
• Permission levels on the Tools Registry boundary
• Workspace directory as the persistent store for scaffolded projects and config files