构建高质量 MCP(模型上下文协议)服务器的指南,使 LLM 能够通过精心设计的工具与外部服务交互。在使用 Python (FastMCP) 或 Node/TypeScript (MCP SDK) 构建 MCP 服务器以集成外部 API 或服务时使用。
npx skills add https://github.com/LeastBit/Claude_skills_zh-CN --skill mcp-builder
创建 MCP(模型上下文协议)服务器,使 LLM 能够通过精心设计的工具与外部服务交互。MCP 服务器的质量取决于它能多好地使 LLM 完成实际任务。
创建高质量的 MCP 服务器包含四个主要阶段:
API 覆盖 vs. 工作流工具:
在全面的 API 端点覆盖与专用工作流工具之间取得平衡。工作流工具对于特定任务可能更方便,而全面覆盖则给予代理灵活组合操作的能力。不同客户端的性能表现各异——某些客户端受益于结合基本工具的代码执行,而另一些则更适合使用高级工作流。当不确定时,优先考虑全面的 API 覆盖。
工具命名与可发现性:
清晰、描述性的工具名称有助于代理快速找到正确的工具。使用一致的前缀(例如 github_create_issue、github_list_repos)和面向动作的命名。
上下文管理:
代理受益于简洁的工具描述以及过滤/分页结果的能力。设计返回聚焦、相关数据的工具。某些客户端支持代码执行,这可以帮助代理高效地过滤和处理数据。
可操作的错误消息:
错误消息应引导代理找到解决方案,提供具体的建议和下一步操作。
浏览 MCP 规范:
从站点地图开始查找相关页面:https://modelcontextprotocol.io/sitemap.xml
然后使用 .md 后缀获取特定页面的 markdown 格式(例如 https://modelcontextprotocol.io/specification/draft.md)。
需要查阅的关键页面:
推荐技术栈:
加载框架文档:
TypeScript(推荐):
https://raw.githubusercontent.com/modelcontextprotocol/typescript-sdk/main/README.mdPython:
https://raw.githubusercontent.com/modelcontextprotocol/python-sdk/main/README.md理解 API:
查阅服务的 API 文档以识别关键端点、认证要求和数据模型。根据需要使用网络搜索和 WebFetch。
工具选择:
优先考虑全面的 API 覆盖。列出要实现的端点,从最常用的操作开始。
参阅特定语言指南了解项目设置:
创建共享工具:
对于每个工具:
输入模式:
输出模式:
outputSchemastructuredContent(TypeScript SDK 特性)工具描述:
实现:
注解:
readOnlyHint:true/falsedestructiveHint:true/falseidempotentHint:true/falseopenWorldHint:true/false审查以下方面:
TypeScript:
npm run build 验证编译npx @modelcontextprotocol/inspectorPython:
python -m py_compile your_server.py参阅特定语言指南了解详细的测试方法和质量检查清单。
实现 MCP 服务器后,创建全面的评估来测试其有效性。
加载 ✅ 评估指南 获取完整的评估指南。
使用评估来测试 LLM 能否有效地使用您的 MCP 服务器回答真实、复杂的问题。
要创建有效的评估,请遵循评估指南中概述的流程:
确保每个问题:
创建具有以下结构的 XML 文件:
<evaluation>
<qa_pair>
<question>查找关于以动物代号命名的 AI 模型发布的讨论。有一个模型需要使用 ASL-X 格式的特定安全级别。以一种斑点野猫命名的模型被确定为什么数字 X?</question>
<answer>3</answer>
</qa_pair>
<!-- 更多 qa_pairs... -->
</evaluation>
在开发过程中根据需要加载这些资源:
https://modelcontextprotocol.io/sitemap.xml 的站点地图开始,然后使用 .md 后缀获取特定页面https://raw.githubusercontent.com/modelcontextprotocol/python-sdk/main/README.md 获取https://raw.githubusercontent.com/modelcontextprotocol/typescript-sdk/main/README.md 获取@mcp.tool 注册工具server.registerTool 注册工具Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).
Automatically creates user-facing changelogs from git commits by analyzing commit history, categorizing changes, and transforming technical commits into clear, customer-friendly release notes. Turns hours of manual changelog writing into minutes of automated generation.
Use when implementation is complete, all tests pass, and you need to decide how to integrate the work - guides completion of development work by presenting structured options for merge, PR, or cleanup
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).
React Native and Expo best practices for building performant mobile apps. Use when building React Native components, optimizing list performance, implementing animations, or working with native modules. Triggers on tasks involving React Native, Expo, mobile performance, or native platform APIs.
React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.
Next.js best practices - file conventions, RSC boundaries, data patterns, async APIs, metadata, error handling, route handlers, image/font optimization, bundling
Use when starting feature work that needs isolation from current workspace or before executing implementation plans - creates isolated git worktrees with smart directory selection and safety verification
Take leastbit/mcp-builder from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.
The instructions reference npx.
Without those the skill loads but fails at the first command.