prefecthq--fastmcp
130 行
7.0 KiB
Markdown
130 行
7.0 KiB
Markdown
<!-- WEHUB_ZH_README -->
|
||
> [!NOTE]
|
||
> 本文档由 WeHub 基于上游 README 翻译整理,属于社区翻译,非官方中文文档。
|
||
> [English](./README.en.md) · [原始项目](https://github.com/PrefectHQ/fastmcp) · [上游 README](https://github.com/PrefectHQ/fastmcp/blob/HEAD/README.md)
|
||
> 原作者、版权与许可证归属以原始项目及本仓库 LICENSE 文件为准。
|
||
|
||
<div align="center">
|
||
|
||
<!-- omit in toc -->
|
||
|
||
<picture>
|
||
<source width="550" media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/PrefectHQ/fastmcp/main/docs/assets/brand/f-watercolor-waves-4-dark.png">
|
||
<source width="550" media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/PrefectHQ/fastmcp/main/docs/assets/brand/f-watercolor-waves-4.png">
|
||
<img width="550" alt="FastMCP Logo" src="https://raw.githubusercontent.com/PrefectHQ/fastmcp/main/docs/assets/brand/f-watercolor-waves-2.png">
|
||
</picture>
|
||
|
||
# FastMCP 🚀
|
||
|
||
<strong>快速行动,动手造物。</strong>
|
||
|
||
*由 [Prefect](https://www.prefect.io/)* 用 💙 打造*
|
||
|
||
[](https://gofastmcp.com)
|
||
[](https://discord.gg/uu8dJCgttd)
|
||
[](https://pypi.org/project/fastmcp)
|
||
[](https://github.com/PrefectHQ/fastmcp/actions/workflows/run-tests.yml)
|
||
[](https://github.com/PrefectHQ/fastmcp/blob/main/LICENSE)
|
||
|
||
<a href="https://trendshift.io/repositories/21461" target="_blank"><img src="https://trendshift.io/api/badge/repositories/21461" alt="prefecthq%2Ffastmcp | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
|
||
</div>
|
||
|
||
---
|
||
|
||
[模型上下文协议](https://modelcontextprotocol.io/)(Model Context Protocol,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()
|
||
```
|
||
|
||
## 为什么选择 FastMCP
|
||
|
||
构建一个高效的 MCP 应用比看起来更难。FastMCP 为你搞定这一切。用一个 Python 函数声明一个工具,schema、验证和文档会自动生成。用 URL 连接服务器,传输协商、认证和协议生命周期都会替你管理。你只需专注业务逻辑,MCP 部分自然就能工作:**有了 FastMCP,最佳实践已内置其中。**
|
||
|
||
**正因如此,FastMCP 是使用 MCP 的标准框架。** FastMCP 1.0 于 2024 年被并入官方 MCP Python SDK。如今,这个积极维护的独立项目每天下载量达一百万次,各语言中约 70% 的 MCP 服务器都由某个版本的 FastMCP 提供支持。
|
||
|
||
FastMCP 有三大支柱:
|
||
|
||
<table>
|
||
<tr>
|
||
<td align="center" valign="top" width="33%">
|
||
<a href="https://gofastmcp.com/servers/server">
|
||
<img src="https://raw.githubusercontent.com/PrefectHQ/fastmcp/main/docs/assets/images/servers-card.png" alt="Servers" />
|
||
<br /><strong>Servers</strong>
|
||
</a>
|
||
<br />向 LLM 暴露工具、资源和 prompts。
|
||
</td>
|
||
<td align="center" valign="top" width="33%">
|
||
<a href="https://gofastmcp.com/apps/overview">
|
||
<img src="https://raw.githubusercontent.com/PrefectHQ/fastmcp/main/docs/assets/images/apps-card.png" alt="Apps" />
|
||
<br /><strong>Apps</strong>
|
||
</a>
|
||
<br />为你的工具提供直接在对话中渲染的交互式 UI。
|
||
</td>
|
||
<td align="center" valign="top" width="33%">
|
||
<a href="https://gofastmcp.com/clients/client">
|
||
<img src="https://raw.githubusercontent.com/PrefectHQ/fastmcp/main/docs/assets/images/clients-card.png" alt="Clients" />
|
||
<br /><strong>Clients</strong>
|
||
</a>
|
||
<br />连接任意 MCP 服务器——本地或远程、编程或 CLI。
|
||
</td>
|
||
</tr>
|
||
</table>
|
||
|
||
**[Servers](https://gofastmcp.com/servers/server)** 将你的 Python 函数封装为符合 MCP 规范的工具、资源和 prompts。**[Clients](https://gofastmcp.com/clients/client)** 以完整协议支持连接任意服务器。而 **[Apps](https://gofastmcp.com/apps/overview)** 为你的工具提供直接在对话中渲染的交互式 UI。
|
||
|
||
准备好开始构建了吗?从[安装指南](https://gofastmcp.com/getting-started/installation) 入手,或直接跳到[快速入门](https://gofastmcp.com/getting-started/quickstart).
|
||
|
||
## 使用 Horizon 在生产环境运行 FastMCP
|
||
|
||
FastMCP 是构建 MCP 服务器的标准方式。**[Prefect Horizon](https://www.prefect.io/horizon?utm_source=github&utm_medium=readme&utm_campaign=readme_horizon&utm_content=readme_body)** 是用于安全运行它们的企业级 MCP 网关。
|
||
|
||
由 FastMCP 团队打造,Horizon 打包了我们在交付全球最受欢迎的 MCP 框架过程中积累的最佳实践。
|
||
|
||
从 GitHub 部署 FastMCP 服务器,支持分支预览和即时回滚。为公司使用的每个 MCP 创建私有注册表。通过 SSO 和工具级 RBAC 保障访问安全。在整个 MCP 技术栈上获取审计日志、可观测性和治理能力。将经批准的工具 remix 为面向团队与代理的专用端点。
|
||
|
||
从 FastMCP 起步。[用 Horizon 规模化扩展 →](https://www.prefect.io/horizon?utm_source=github&utm_medium=readme&utm_campaign=readme_horizon&utm_content=readme_cta)
|
||
|
||
## 安装
|
||
|
||
我们建议使用 [uv](https://docs.astral.sh/uv/): 安装 FastMCP:
|
||
|
||
```bash
|
||
uv pip install fastmcp
|
||
```
|
||
|
||
有关完整安装说明(包括验证与升级),请参阅 [**安装指南**](https://gofastmcp.com/getting-started/installation).
|
||
|
||
**需要升级?** 我们提供以下指南:
|
||
- [从 FastMCP v2 升级](https://gofastmcp.com/getting-started/upgrading/from-fastmcp-2)
|
||
- [从 MCP Python SDK 升级](https://gofastmcp.com/getting-started/upgrading/from-mcp-sdk)
|
||
- [从底层 SDK 升级](https://gofastmcp.com/getting-started/upgrading/from-low-level-sdk)
|
||
|
||
> [!NOTE]
|
||
> 如果在从 FastMCP 3.2 或更早版本升级 `pip` 后,`import fastmcp` 立即失败,请运行 `pip install --force-reinstall fastmcp`。关于原因请参阅[故障排除](https://gofastmcp.com/getting-started/installation#troubleshooting)(`uv` 不受影响)。
|
||
|
||
## 📚 文档
|
||
|
||
FastMCP 的完整文档可在 **[gofastmcp.com](https://gofastmcp.com)**, 获取,包括详细指南、API 参考和高级模式。
|
||
|
||
文档还提供 [llms.txt 格式](https://llmstxt.org/),,这是一种 LLM 易于消费的简单 Markdown 标准:
|
||
|
||
- [`llms.txt`](https://gofastmcp.com/llms.txt) 本质上是一份站点地图,列出文档中的所有页面。
|
||
- [`llms-full.txt`](https://gofastmcp.com/llms-full.txt) 包含完整文档。请注意,这可能会超出你的 LLM 上下文窗口。
|
||
|
||
**社区:** 加入我们的 [Discord 服务器](https://discord.gg/uu8dJCgttd),与其他 FastMCP 开发者交流并分享你的作品。
|
||
|
||
## 贡献
|
||
|
||
我们欢迎贡献!请参阅[贡献指南](https://gofastmcp.com/development/contributing) 了解环境搭建说明、测试要求和 PR 规范。
|