跳到正文
Skillpedia
连接器(MCP)28k · #9867

fastmcp-server

它能做什么

这项技能指导你用 FastMCP 库在 Python 中编写 MCP 服务器。适合想让 AI 工具以标准方式提供工具、资源或提示词的开发者。

适用场景

  • ✓当你想用 FastMCP 在 Python 中构建一个新 MCP 服务器的时候。
  • ✓当你需要为现有的 FastMCP 服务器添加工具、资源或提示词的时候。
  • ✓当你想审查 FastMCP 服务器的结构定义是否有问题的时候。

技能链接

https://github.com/PrefectHQ/fastmcp/blob/main/docs/.mintlify/skills/fastmcp-server/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/PrefectHQ/fastmcp/blob/main/docs/.mintlify/skills/fastmcp-server/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请帮我用 Python 构建一个小型 MCP 服务器,提供一个查询订单状态的工具。”

每周 5 个新技能,1 分钟读完。

工作原理

智能体检查项目中的 FastMCP 版本,阅读对应版本的文档,并编写服务器代码,其工具结构由 Python 类型提示和描述生成。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Authoring MCP servers with FastMCP

Find the current API

Check the project's installed FastMCP version and dependency constraints. Fetch the documentation index and read the relevant pages for that version. The index includes versioned documentation; select /v3/ pages for FastMCP 3 and unversioned pages for FastMCP 4. Read individual pages through their .md URLs instead of loading llms-full.txt. For APIs newer than the installed release, check that release's source or signatures. Preserve the project's dependency constraints unless an upgrade is part of the request. For a new project, check the current stable release before choosing a dependency.

Use the standalone fastmcp package. Its API differs from mcp.server.fastmcp in the Python MCP SDK.

Author the server

Choose the MCP interface to suit what the server exposes: tools for callable operations, resources for addressable content, and prompts for reusable message templates. FastMCP derives tool schemas from Python annotations and descriptions; use Literal or enums for finite choices and Field descriptions for parameter semantics. SDK wrappers need to preserve signatures and docstrings, for example with functools.wraps, or discovery loses that information. Inspect the schema the client receives, especially after transforms or custom discovery rendering: requiredness, enum values, and nested fields can disappear from a summary.

Let the intended client tasks guide tool boundaries, descriptions, and result shape. Give clients enough context to use results and recover from errors. The right granularity depends on the service; generated API tools, custom tools, and compositions can all be appropriate.

For paginated or bounded results, expose whether the answer is complete and how to continue. An upstream failure is not an empty result. Return useful recovery information through tool errors rather than a successful-looking payload. Use ToolError, ResourceError, or PromptError from fastmcp.exceptions for intentional client-facing messages. With mask_error_details=True, ordinary exceptions such as ValueError lose their messages; do not put sensitive backend details in the explicit error types, whose messages remain visible.

When using tool search or code mode, make exact named operations discoverable and explain the execution contract: what persists between calls and what becomes the result. A short fetch/filter/return example can prevent repeated empty outputs. Check the installed implementation before describing that behavior.

Look up FastMCP's relevant facilities as needed: context and dependencies, lifespan, authentication, composition, and transports. Use the project's runtime and hosting choices to determine configuration.

When clients need a repeatable workflow across the server's capabilities, consider shipping a skill alongside those capabilities. Put task selection, operation sequencing, and recovery guidance in the skill; keep tool descriptions focused on their individual contracts. Read the version-matched Skills Provider and Experimental Skills Extension docs from the index before implementing it. SkillsDirectoryProvider exposes skill files as resources; the experimental extension adds skills/list and skills/get discovery. Check the installed release and target host's support before selecting either interface. Discovery does not activate a skill: verify that the host reads and uses it in the intended workflow. The experimental extension currently requires directly registered providers and does not support mounted or transformed skill sources.

Verify the server through FastMCP's Client, which can connect directly to a server instance for in-process testing. Check a representative operation, its client-visible schema and result, and a meaningful failure. For composed or transformed servers, verify the public names and URIs through the outer server, including resource references returned by prompts. Namespace transforms change component names and resource URIs, but do not rewrite URI text inside prompt messages. When a prompt must work both standalone and mounted, direct the client to discover the resource template instead of hardcoding the child's URI. Exercise the chosen transport when connection or deployment behavior is part of the change.

Evaluate agent workflows

When the task includes evaluating how agents use the server, test a representative workflow using the proj

常见问题

它使用哪个包?

它使用独立的 fastmcp Python 包,其 API 与 MCP SDK 自带的封装不同。

智能体如何选择正确的 API 版本?

它会检查项目已安装的版本,并阅读该版本的文档。

工具结构是如何生成的?

FastMCP 根据 Python 注解和描述生成结构,因此清晰的类型提示和文档字符串很重要。

详情

作者的原始描述

Build, extend, or review MCP servers with Python FastMCP, using documentation matched to the project's version.

repo: PrefectHQ/fastmcp

热度

GitHub 星标
28k
排名
#9867
许可证
Apache-2.0
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能