How jlowin/fastmcp works
Project type and overall purpose
• FastMCP is an open-source Python framework/SDK for building Model Context Protocol (MCP) servers and clients.
• It provides a CLI (fastmcp) to bootstrap projects, install integrations, and run servers.
• Key internal modules: fastmcp.cli, fastmcp.client, fastmcp.server, plus utilities, tools, resources, and prompts.
File structure with a focus on the CLI
• src/fastmcp/cli/ contains the CLI entrypoints and subcommands:
• cli.py – core argument parsing and dispatcher
• run.py – “fastmcp run” command (bootstraps and launches a server)
• install/ – “fastmcp install” integrations (claude_code, claude_desktop, cursor, mcp_json)
• claude.py – utility for Claude-specific subcommands
• The CLI commands invoke:
• Core library (fastmcp.server to start HTTP/SSE or STDIO)
• Client library (fastmcp.client) for testing or in-memory transports
• Configuration management (fastmcp.mcp_config, fastmcp.settings)
• External dependencies (pip via UV, environment variables)
README for CLI-related insights
• Usage examples:
• fastmcp run server.py --transport http --host 0.0.0.0 --port 8000
• fastmcp install claude-code
• It describes three built-in transports and multiple subcommands.
Main components
A. User Shell
B. fastmcp CLI (src/fastmcp/cli/cli.py)
C. Subcommand Handlers
1. Run Handler (run.py)
2. Install Handlers (install/*.py)
3. Integration Helpers (claude.py)
D. Core Library Modules
1. Server (fastmcp.server.*)
2. Client (fastmcp.client.*)
3. Config & Settings (fastmcp.mcp_config, fastmcp.settings)
E. External Tools & Services
1. Python Interpreter & pip (via UV)
2. Network (HTTP, SSE)
3. File System (user’s code, config files)
Architectural patterns & principles
• Command Pattern: each CLI subcommand is a distinct handler class/function
• Dependency Injection: subcommands import and use core modules (server, client, utilities)
• Plugin/Extension Points: install subcommands allow external integrations to hook into the framework
• Separation of Concerns: CLI layer solely handles I/O & orchestration, delegating business logic to library modules
Detailed component list
• User Shell
• fastmcp CLI Entrypoint
• Argument Parser
• Command Registry
• Subcommands (grouped):
1. run.py
2. install/
– claude_code
– claude_desktop
– cursor
– mcp_json
3. claude.py
• Core Library
• fastmcp.server (transport modules: stdio, http, sse)
• fastmcp.client (transports, testing)
• fastmcp.mcp_config + fastmcp.settings
• External Services
• Python/pip (via UV)
• Network endpoints (if HTTP/SSE)
• File system (server.py, config files)
[BLUE] User Shell
↓ “fastmcp install claude-code”
[BLUE] CLI Parser → Command Registry
↳ “install” command → [BLUE] Install Handler (install/claude_code.py)
↔ [GRAY] pip/UV (executes pip install anthropic-sdk)
↔ [GREEN] fastmcp.mcp_config (updates config)
↳ “run” command → [BLUE] Run Handler (run.py)
→ [GRAY] FileSystem (reads server.py)
→ [GREEN] fastmcp.server (mcp.run())
→ [GRAY] Network (HTTP/SSE sockets)
↳ “claude” command → [BLUE] claude.py helper
↔ [GREEN] fastmcp.client.auth