with one click
fastmcp
Build, test, and deploy Python MCP servers.
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Menu
Build, test, and deploy Python MCP servers.
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Based on SOC occupation classification
Query and edit a SiYuan knowledge base via its API.
Create, read, edit Excel .xlsx spreadsheets and CSVs.
Create, read, edit Excel .xlsx spreadsheets and CSVs.
Curate LLM training data: dedupe, filter, PII redaction.
Scrape sites with stealth browsing and Cloudflare bypass.
Clean training loops with built-in distributed support.
| name | fastmcp |
| description | Build, test, and deploy Python MCP servers. |
| version | 1.0.0 |
| author | Hermes Agent |
| license | MIT |
| platforms | ["linux","macos","windows"] |
| metadata | {"hermes":{"tags":["MCP","FastMCP","Python","Tools","Resources","Prompts","Deployment"],"homepage":"https://gofastmcp.com","related_skills":["native-mcp","mcporter"]}} |
| prerequisites | {"commands":["python3"]} |
使用 FastMCP 用 Python 构建 MCP 服务器,在本地进行验证,将其安装到 MCP 客户端中,进而作为 HTTP 接口部署。
当需要执行以下任务时,可使用此技能:
如果服务器已存在且仅需接入 Hermes,则可使用 native-mcp。若目标是临时通过 CLI 访问现有的 MCP 服务器而非从头构建,则应使用 mcporter。
首先需要在工作环境中安装 FastMCP:
pip install fastmcp
fastmcp version
对于 API 模板,如果尚未安装 httpx,请先进行安装:
pip install httpx
templates/api_wrapper.py - 支持认证头信息的 REST API 封装工具templates/database_server.py - 只读 SQLite 查询服务器templates/file_processor.py - 文本文件检测与搜索服务器scripts/scaffold_fastmcp.py - 复制示例模板并替换服务器名称占位符references/fastmcp-cli.md - FastMCP CLI 工作流程、安装要求及部署检查项首先确定最基础且实用的功能范围:
相比功能繁多但工具定义模糊的庞大服务器,更应优先选择结构简洁、具备清晰名称、文档说明及数据结构的轻量级服务器。
可直接复制模板,或使用搭建辅助工具:
python ~/.hermes/skills/mcp/fastmcp/scripts/scaffold_fastmcp.py \
--template api_wrapper \
--name "Acme API" \
--output ./acme_server.py
可用模板:
需完整翻译输入内容,不得提前终止。
python ~/.hermes/skills/mcp/fastmcp/scripts/scaffold_fastmcp.py --list
如需手动复制,请将 __SERVER_NAME__ 替换为实际的服务器名称。
在添加资源或提示词之前,先从 @mcp.tool 函数开始构建。
工具设计的规则如下:
优秀的工具示例包括:
get_customersearch_ticketsdescribe_tablesummarize_text_file较差的工具示例则有:
runprocessdo_thing当客户端需要获取诸如架构定义、政策文档或生成的报告等稳定的只读内容时,再添加 @mcp.resource。
当服务器需要为某种已知工作流程提供可重复使用的提示词模板时,再添加 @mcp.prompt。
切勿将每份文档都转化为提示词。建议采用以下方式:
可使用 FastMCP CLI 在本地对服务器进行验证:
fastmcp inspect acme_server.py:mcp
fastmcp list acme_server.py --json
fastmcp call acme_server.py search_resources query=router limit=5 --json
为实现高效的迭代式调试,建议在本地运行服务器:
fastmcp run acme_server.py:mcp
要在本地测试 HTTP 传输功能:
fastmcp run acme_server.py:mcp --transport http --host 127.0.0.1 --port 8000
fastmcp list http://127.0.0.1:8000/mcp --json
fastmcp call http://127.0.0.1:8000/mcp search_resources query=router --json
在确认服务器正常运行之前,务必对每个新工具至少执行一次真实的 fastmcp call 操作。
FastMCP 可将服务器注册到支持 MCP 的客户端中:
fastmcp install claude-code acme_server.py
fastmcp install claude-desktop acme_server.py
fastmcp install cursor acme_server.py -e .
可使用 fastmcp discover 命令来查看机器上已配置的命名 MCP 服务器。
若目标是与 Hermes 集成,可选择以下任一方式:
~/.hermes/config.yaml 文件中使用 native-mcp 技能来配置服务器;或对于托管式服务,FastMCP 文档中提供了关于 Prefect Horizon 最直接的部署指南。在部署之前:
fastmcp inspect acme_server.py:mcp
请确保该代码仓库中包含以下内容:
requirements.txt 或 pyproject.toml 文件对于常规的 HTTP 托管场景,建议先在本地验证 HTTP 传输功能,之后再将其部署到任何能够开放服务器端口的兼容 Python 的平台上。
适用于将 REST 或 HTTP API 转换为 MCP 工具的场景。
推荐的初始功能模块包括:
实现注意事项:
可从 templates/api_wrapper.py 文件开始实现。
适用于需要提供安全的数据查询与查看功能的场景。
推荐的初始功能模块包括:
list_tablesdescribe_table实现注意事项:
SELECT 类型的 SQL 查询可从 templates/database_server.py 文件开始实现。
适用于需要按需检查或转换文件的服务器场景。
推荐的初始功能模块包括:
实现注意事项:
可从 templates/file_processor.py 文件开始实现。
在交付 FastMCP 服务器之前,请确认满足以下所有条件:
fastmcp inspect <file.py:mcp> 命令能够正常执行fastmcp list <server spec> --json 命令能够正常执行fastmcp call 调用请在当前激活的环境中安装对应包:
pip install fastmcp
fastmcp version
fastmcp inspect 命令执行失败请检查以下内容:
<file.py:object> 中的 FastMCP 实例名称是否正确;请执行以下操作:
fastmcp list server.py --json
fastmcp call server.py your_tool_name --json
这通常是由于名称不匹配、缺少必需参数,或是返回值不可序列化所导致的。
虽然服务器构建部分可能是正确的,但 Hermes 的配置可能存在问题。请加载 native-mcp 技能,并在 ~/.hermes/config.yaml 中配置服务器,之后再重启 Hermes。
如需了解 CLI 详情、目标安装以及部署检查的相关内容,请参阅 references/fastmcp-cli.md。