Main
先从 README 的最小 server 示例跑通,再把每个工具拆成可测试、带清晰 docstring 的 Python 函数。
把工具的 schema/返回值当作 API:保持契约稳定,对破坏性变更做版本化管理。
尽早补齐生产化要素(超时、限流、鉴权),并准备一个 staging 环境复核不同 MCP 客户端的兼容性。
优先按文档里的 server/client/app 模式扩展,不要手写一堆协议胶水。
README (excerpt)
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()Why FastMCP
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.
Source-backed notes
- README 给出最小 server 示例:
FastMCP("Demo")、@mcp.tool、以及mcp.run()启动。 - README 推荐用
uv pip install fastmcp安装,并链接到独立文档站点。 - README 描述 FastMCP 用于抽象 MCP 的 schema/生命周期细节,减少手写协议逻辑。
FAQ
- FastMCP 是 server 还是 client?:README 同时提到 server/client 模式;建议先从 server 落地开始。
- 必须用 uv 吗?:README 推荐 uv;但作为 Python 依赖也可以按团队习惯使用 pip/虚拟环境。
- 怎么保证工具行为可预测?:把 schema 当作契约,加测试,并对破坏性改动做版本化发布。