FastMCP
The fast, Pythonic way to build MCP (Model Context Protocol) servers and clients, built by Prefect with 26,200+ GitHub stars.
FastMCP is a Python framework for building servers and clients that implement the Model Context Protocol (MCP), created and maintained by Prefect. It provides a clean, Pythonic API that dramatically simplifies MCP server and client development compared to using the MCP SDK directly. With over 26,200 GitHub stars and 2,100 forks, it has become the most popular way to build MCP-based tools.
The Model Context Protocol is an open standard developed by Anthropic that allows AI models to discover and interact with external tools and data sources. FastMCP makes it trivial to define tools using Python functions with type hints, automatically generating the JSON schemas needed for MCP compliance. The project is hosted at github.com/PrefectHQ/fastmcp.
Key Features
- Pythonic API - Define MCP tools with simple Python functions using type hints and docstrings. No JSON schema boilerplate needed.
- Automatic Schema Generation - FastMCP automatically generates JSON schemas from Python type annotations and Pydantic models.
- STDIO and HTTP Transports - Support for both stdio-based (local subprocess) and HTTP/SSE-based (remote) MCP transports.
- Built-in Validation - Automatic validation of tool arguments with clear error messages via FastMCP's ValidationError.
- Full MCP Specification Support - Implements resources, prompts, tools, and sampling as defined by the MCP specification.
- Remote MCP (fastmcp_remote) - Connect to remote MCP servers over TLS with authentication support.
- Slim Build (fastmcp_slim) - Lightweight variant for resource-constrained environments.
- Async Support - Native async/await support for IO-bound tool implementations.
Installation
Install via pip:
pip install fastmcp
Install with remote support:
pip install fastmcp[remote]
# Slim version for constrained environments
pip install fastmcp-slim
FastMCP requires Python 3.10+ and works on macOS, Windows, and Linux. It integrates seamlessly with existing Python projects and can be added to any project that needs to expose MCP-compatible tools.
Building Servers
Creating an MCP server with FastMCP requires minimal code. Define your tools as Python functions with type hints and the framework handles the rest:
from fastmcp import FastMCP
mcp = FastMCP("My Server")
@mcp.tool()
def greet(name: str) -> str:
"""Greet someone by name."""
return f"Hello, {name}!"
if __name__ == "__main__":
mcp.run()
FastMCP automatically extracts the function signature, type annotations, and docstring to build the MCP tool definition and JSON schema. It supports complex types via Pydantic models, union types, optional parameters, and list/dict structures. Resources and prompts are defined with similar decorator-based APIs.
Client Support
FastMCP also provides a client API for connecting to MCP servers, whether they are FastMCP servers or servers built with other MCP implementations. The client supports both stdio and HTTP transports, automatic reconnection, and tool discovery:
from fastmcp import Client
async with Client("http://localhost:8000") as client:
tools = await client.list_tools()
result = await client.call_tool("greet", {"name": "World"})
The client handles serialization, error handling, and connection management automatically. It integrates well with AI agent frameworks like LangChain, CrewAI, and AutoGen that need to discover and call MCP tools.
Remote MCP
FastMCP's remote module (fastmcp_remote) adds support for connecting to MCP servers over the network with TLS encryption and authentication. This enables secure, production-grade deployments where MCP servers run as network services rather than local subprocesses.
The remote client supports the --verify flag for TLS certificate verification, multiple authentication providers (including Hugging Face), and configurable timeout and retry settings. This makes it suitable for enterprise environments where MCP tools need to be accessed across team boundaries or from cloud-based AI agents.
Comparison
FastMCP competes with the official MCP Python SDK and other MCP implementation frameworks. Here is how they compare:
| Criterion | FastMCP | MCP Python SDK | Custom Implementation |
|---|---|---|---|
| API Design | Decorator-based, Pythonic | Low-level, more verbose | Full control, verbose |
| Schema Generation | Automatic from type hints | Manual JSON schemas | Manual JSON schemas |
| Validation | Built-in (Pydantic) | Manual validation | Manual validation |
| Transports | STDIO + HTTP/SSE + Remote | STDIO + HTTP/SSE | Custom |
| Community | 26.2k stars, active | Official, well-documented | N/A |
| Learning Curve | Very low | Moderate | High |