
FastMCP
Author: PrefectHQ
Description: 🚀 The fast, Pythonic way to build MCP (Model Context Protocol) servers and clients. FastMCP is a Python framework that lets you expose Python functions as MCP tools (with automatic schema/validation/docs), connect to MCP servers as a client (URL-based connection with transport negotiation/auth/protocol lifecycle), and build interactive "Apps" (UIs rendered in-conversation). Installation (recommended): `uv pip install fastmcp`. Docs: https://gofastmcp.com. Maintained by Prefect (PrefectHQ).
Stars: 23.5k
Forks: 1.8k
License: Apache License 2.0
Category: Open Source
Overview
Installation
uv pip install fastmcpadd
Add two numbers (example MCP tool registered with @mcp.tool)
FAQs
How do I migrate from the official MCP Python SDK's bundled FastMCP v1.0 to the PrefectHQ FastMCP v3.x without breaking existing servers?
Start by pinning the standalone PrefectHQ package version explicitly in requirements.txt, then update imports from `mcp.server.fastmcp` to `fastmcp`. Test thoroughly in development environments because interface divergence means decorators, method signatures, and config patterns differ between v1.0 and v3.x. Run existing test suites against the new version before deploying to production.
How does FastMCP's OAuth 2.1 implementation work with identity providers like Google and GitHub for securing MCP tool endpoints?
FastMCP's OAuth 2.1 implementation handles token exchange through provider-specific configuration objects. Developers register credentials with identity providers, specifying callback URLs and scopes. FastMCP manages authorization code flow, redirecting users to consent screens, exchanging codes for access tokens, and attaching tokens to tool invocations. This secures endpoints by validating bearer tokens before executing functions, enabling user-scoped permissions without custom middleware.
What are the performance implications of using FastMCP's OpenAPI-to-MCP auto-conversion compared to building MCP tools manually?
FastMCP's OpenAPI auto-conversion adds minimal runtime overhead since it generates standard MCP tool definitions at initialization, not per-request. Complex validation through Pydantic can add 2-5ms per call for nested objects. Manual MCP tools let you strip validation layers and optimize input parsing, potentially reducing latency by 30-40% in high-throughput scenarios where microsecond differences compound across thousands of calls.
How do I use FastMCP's proxy and mounting capabilities to compose multiple MCP servers into a single endpoint?
FastMCP's proxy mode accepts server configurations through runtime API calls or initialization parameters, forwarding tool requests to registered servers via namespace routing. Use `FastMCP.mount()` to attach child servers at path prefixes, creating a unified interface where tools appear under assigned namespaces. This enables dynamic server discovery without redeploying the proxy, composing heterogeneous tool sets into one client-facing endpoint.
What is the providers-and-transforms architecture introduced in FastMCP v3.0 and how does it enable horizontal scaling?
The providers-and-transforms architecture decouples data sources from processing logic, enabling stateless FastMCP servers. Providers expose external systems like databases or APIs, while transforms apply filtering, aggregation, or enrichment. Each request carries complete context, so multiple instances handle requests without shared memory. Horizontal scaling works because no instance holds session state, allowing load balancers to distribute traffic across replicas independently accessing the same providers.
How do I handle large payloads in FastMCP to avoid exceeding the LLM's context window when building data-heavy MCP servers?
Implement chunking by splitting large responses into multiple MCP resources or tool calls, letting LLMs request specific segments. Use Pydantic validators to enforce payload limits, returning truncated previews with URIs for full data. Consider streaming via FastMCP's async support or pagination parameters that enable iterative fetching in manageable batches.