FastMCP
jlowin / fastmcp
用 Python 快速搭 MCP 服务器:装饰器声明 tools、resources 与 prompts,自动生成 schema,支持 stdio/HTTP、认证、组合与测试。Build MCP servers quickly in Python: decorators declare tools, resources and prompts, schemas are generated, with stdio/HTTP transports, auth, composition and testing.
为什么选Why choose it
- 把函数变成 MCP tool 只需一个装饰器。One decorator turns a function into an MCP tool.
- stdio 与 HTTP 两种传输都覆盖,客户端接入简单。Both stdio and HTTP transports are covered, simplifying client integration.
- 测试与组合能力比手写 JSON-RPC 省事。Testing and composition beat hand-written JSON-RPC.
不适合Not for
不是 MCP 客户端;仍要 Claude、Cursor 或其他 host 来连。Not an MCP client; you still need Claude, Cursor or another host.
生产要自己加鉴权、限流、审计与网络隔离。Production needs your own auth, rate limits, audit and network isolation.
工具描述写不好,模型仍然不会正确调用。Poor tool descriptions still cause bad model calls.
最小上手Minimum setup
- pip install fastmcp,写一个 add(a,b) tool 并用内存客户端测。pip install fastmcp, write an add(a, b) tool and test it with the in-memory client.
- 再起 HTTP 传输,确认 host 能列出 tools 与调用。Then start HTTP transport and confirm a host can list and call the tool.
- 加日志、超时与错误返回,再考虑鉴权。Add logging, timeouts and error returns before thinking about auth.
依赖与成本Dependencies and cost
Python 3.10+;stdio 无需网络,HTTP 部署要 ASGI 服务器与反向代理;生产要身份与审计。Python 3.10+; stdio needs no network, HTTP needs an ASGI server and reverse proxy; production needs identity and audit.
许可与使用边界License and usage boundaries
Apache-2.0;MCP 规范与客户端各自条款,商用前核对。Apache-2.0; the MCP specification and clients carry their own terms.
开源不等于可商用:GPL / AGPL 有传染性;代码许可、模型许可、生成内容许可要分开看。上线前读仓库 LICENSE 与模型卡,必要时让法务确认。Open source is not automatically commercial-use friendly: GPL / AGPL are copyleft; code, model and output licenses are separate. Read the LICENSE and model card before launch, and involve legal when needed.
替代与相邻Alternatives and neighbors
- OpenAI Agents SDK — 先试这个Start here,轻量的 agent 运行时:agent、handoff、guardrail、trace 四个核心概念。A lightweight agent runtime with four core ideas: agents, handoffs, guardrails and traces.
- Google ADK — 生产可用Production,Google 的代码优先 Python agent 工具包:把工具、会话、记忆、评测与部署放进同一套抽象,可用 Gemini 或其它模型。Google’s code-first Python agent toolkit, bringing tools, sessions, memory, evaluation and deployment into one abstraction, usable with Gemini or other models.
- LangGraph — 生产可用Production,把 agent 写成有状态图:节点、边、检查点、人工确认与回滚都能显式表达。Write an agent as a stateful graph: nodes, edges, checkpoints, human approval and rollback are explicit.
下一步Next steps
- 打开 GitHub,先读 README、LICENSE、最近 release 与 issue。Open GitHub and read the README, LICENSE, latest release and issues first.
- 按“部署依赖 / 显存 / 数据 / 网络 / 权限”列一张上手清单。Make an onboarding checklist for deployment dependencies, VRAM, data, network and permissions.
- 用一个小样本跑通,再决定是否进生产;不要直接上生产数据。Run a small sample first, then decide on production; never start with production data.
GitHub 仓库 ↗GitHub repository ↗ 文档 ↗Docs ↗ 加入对比Add to compare