🔥 PrefectHQ/fastmcp:快速、Pythonic 的 MCP 服务器与客户端构建框架
英文标题:🔥 PrefectHQ/fastmcp
FastMCP 是用于构建 MCP(模型上下文协议)服务器与客户端的 Python 框架,已纳入官方 MCP Python SDK。该框架日下载量达百万次,支撑了跨语言 70% 的 MCP 服务器。它提供三大支柱:Servers(将 Python 函数暴露为工具/资源/提示)、Clients(连接任意 MCP 服务器)以及 Apps(在对话中直接渲染交互界面)。同时推出企业 MCP 网关 Prefect Horizon,用于生产环境的部署、安全与治理。对开发者而言,FastMCP 让协议细节自动化,从原型到生产开箱即得最佳实践。
733.1 KB
816.9 KB
806.4 KB
42.5 KB
36.5 KB
34.4 KB
51.3 KB
中文
模型上下文协议(MCP) 将大语言模型(LLM)连接到工具和数据。FastMCP 为你提供了从原型到生产所需的一切:
python from fastmcp import FastMCP
mcp = FastMCP("Demo 🚀")
@mcp.tool def add(a: int, b: int) -> int: """Add two numbers""" return a + b
if name == "main": mcp.run()
构建一个高效的 MCP 应用比看上去要难。FastMCP 为你打理这一切。用一个 Python 函数声明一个工具,其模式、验证和文档就会自动生成。通过一个 URL 连接到服务器,传输协商、认证和协议生命周期都会自动管理。你只需专注于业务逻辑,MCP 部分就能正常工作:使用 FastMCP,最佳实践已内置。
正因如此,FastMCP 成为了使用 MCP 的标准框架。 FastMCP 1.0 已于 2024 年被纳入官方 MCP Python SDK。今天,这个独立维护的项目每日下载量达百万次,而某种版本的 FastMCP 支撑了跨所有语言 70% 的 MCP 服务器。
FastMCP 有三大支柱:
| 
Servers
将工具、资源和提示暴露给 LLM。 | 
Apps
让你的工具直接在对话中渲染交互界面。 | 
Clients
连接到任意 MCP 服务器——本地或远程,编程式或命令行。 |
|---|---|---|
Servers 将你的 Python 函数封装成符合 MCP 规范的工具、资源和提示。Clients 以完整协议支持连接到任意服务器。而 Apps 则为你的工具提供直接嵌入对话的交互界面。
使用 Horizon 在生产环境中运行 FastMCP
FastMCP 是构建 MCP 服务器的标准方式。Prefect Horizon 则是企业级 MCP 网关,可安全地运行它们。
由 FastMCP 团队构建的 Horizon 封装了我们在交付全球最流行 MCP 框架过程中积累的最佳实践。
通过 GitHub 部署 FastMCP 服务器,支持分支预览与即时回滚。为公司使用的每个 MCP 创建私有注册表。通过 SSO 和工具级 RBAC 保障访问安全。获取全 MCP 技术栈的审计日志、可观测性和治理能力。将已批准的工具重新组合成面向团队和 Agent 的专用端点。
从 FastMCP 开始。通过 Horizon 扩展 →
我们推荐使用 uv 安装 FastMCP:
uv add fastmcp
完整的安装说明,包括验证和升级,请参阅安装指南。
正在升级? 我们提供了以下指南:
注意
若在从 FastMCP 3.2 或更早版本通过pip升级后立即出现import fastmcp失败,请运行pip install --force-reinstall fastmcp。详见故障排除了解原因(uv不受影响)。
FastMCP 的完整文档可在 gofastmcp.com 获取,包括详细指南、API 参考和高级模式。
文档也提供 llms.txt 格式,这是一种 LLM 可以轻松使用的简单 Markdown 标准:
llms.txt本质上是一个站点地图,列出了文档中所有页面。llms-full.txt包含整个文档。注意,这可能超出你 LLM 的上下文窗口。
社区: 加入我们的 Discord 服务器 与其他 FastMCP 开发者交流,分享你的构建成果。
我们欢迎贡献!请参阅贡献指南 了解环境设置、测试要求和 PR 规范。
English / 原文
The Model Context Protocol (MCP) connects LLMs to tools and data. FastMCP gives you everything you need to go from prototype to production:
from fastmcp import FastMCP
mcp = FastMCP("Demo 🚀")
@mcp.tool
def add(a: int, b: int) -> int:
"""Add two numbers"""
return a + b
if __name__ == "__main__":
mcp.run()
Building an effective MCP application is harder than it looks. FastMCP handles all of it. Declare a tool with a Python function, and the schema, validation, and documentation are generated automatically. Connect to a server with a URL, and transport negotiation, authentication, and protocol lifecycle are managed for you. You focus on your logic, and the MCP part just works: with FastMCP, best practices are built in.
That's why FastMCP is the standard framework for working with MCP. FastMCP 1.0 was incorporated into the official MCP Python SDK in 2024. Today, the actively maintained standalone project is downloaded a million times a day, and some version of FastMCP powers 70% of MCP servers across all languages.
FastMCP has three pillars:

Servers
Expose tools, resources, and prompts to LLMs. | 
Apps
Give your tools interactive UIs rendered directly in the conversation. | 
Clients
Connect to any MCP server — local or remote, programmatic or CLI.
---|---|---
Servers wrap your Python functions into MCP-compliant tools, resources, and prompts. Clients connect to any server with full protocol support. And Apps give your tools interactive UIs rendered directly in the conversation.
Ready to build? Start with the installation guide or jump straight to the quickstart.
Run FastMCP in production with Horizon
FastMCP is the standard way to build MCP servers. Prefect Horizon is the enterprise MCP gateway for running them safely.
Built by the FastMCP team, Horizon packages the best practices we've learned shipping the world's most popular MCP framework.
Deploy FastMCP servers from GitHub with branch previews and instant rollback. Create a private registry of every MCP your company uses. Secure access with SSO and tool-level RBAC. Get audit logs, observability, and governance across your MCP stack. Remix approved tools into purpose-built endpoints for teams and agents.
Start with FastMCP. Scale with Horizon →
We recommend installing FastMCP with uv:
For full installation instructions, including verification and upgrading, see the Installation Guide.
Upgrading? We have guides for:
Note
If import fastmcp fails right after a pip upgrade from FastMCP 3.2 or earlier, run pip install --force-reinstall fastmcp. See Troubleshooting for why this happens (uv is unaffected).
FastMCP's complete documentation is available at gofastmcp.com , including detailed guides, API references, and advanced patterns.
Documentation is also available in llms.txt format, which is a simple markdown standard that LLMs can consume easily:
llms.txtis essentially a sitemap, listing all the pages in the documentation.llms-full.txtcontains the entire documentation. Note this may exceed the context window of your LLM.
Community: Join our Discord server to connect with other FastMCP developers and share what you're building.
We welcome contributions! See the Contributing Guide for setup instructions, testing requirements, and PR guidelines.