Community编程与开发github.com

mcp-builder

用于构建高质量 MCP(模型上下文协议)服务器的指南,使 LLM 能够通过精心设计的工具与外部服务交互。在构建 MCP 服务器以集成外部 API 或服务时使用,支持 Python (FastMCP) 或 Node/TypeScript (MCP SDK)。

mcp-builder 是什么?

mcp-builder 是一份全面的指南,用于创建高质量的 MCP(模型上下文协议)服务器,使 LLM 能够通过结构良好的工具与外部服务交互。该指南采用四阶段流程:深入研究和规划、实现、审查与测试,以及创建评估。它涵盖了关键的 MCP 设计原则,如 API 覆盖与工作流工具的平衡、工具命名与可发现性、上下文管理以及可操作错误消息。 该指南强烈推荐 TypeScript(使用 @modelcontextprotocol/server v2 SDK)作为主要语言,同时也为现有项目提供 Python(FastMCP)和 TypeScript v1 的支持。实施阶段包括详细的项目设置、核心基础设施(API 客户端、错误处理、分页)、工具实现(输入输出模式、注释)以及特定语言的构建和测试步骤。 最后阶段指导用户创建10个复杂、只读、可验证的评估问题,以 XML 格式输出,确保 MCP 服务器的有效性。整个指南提供了大量参考文件链接,包括 MCP 协议规范、SDK 文档、语言实现指南以及评估模板,使其成为构建生产级 MCP 服务器的自包含资源。

兼容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/anthropics/skills/tree/main/skills/mcp-builder

Installed? Explore more 编程与开发 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

MCP 服务器开发指南

概述

创建 MCP(模型上下文协议)服务器,使 LLM 能够通过精心设计的工具与外部服务交互。MCP 服务器的质量取决于它如何使 LLM 完成实际任务。


流程

🚀 高级工作流

创建一个高质量的 MCP 服务器涉及四个主要阶段:

阶段 1:深入研究和规划

1.1 理解现代 MCP 设计

API 覆盖 vs. 工作流工具: 在全面的 API 端点覆盖与专门的工作流工具之间取得平衡。工作流工具对于特定任务可能更方便,而全面覆盖则赋予智能体组合操作的灵活性。性能因客户端而异——有些客户端受益于结合基本工具执行代码,而其他客户端则更适合更高级的工作流。如果不确定,优先考虑全面的 API 覆盖。

工具命名和可发现性: 清晰、描述性的工具名称有助于智能体快速找到正确的工具。使用一致的前缀(例如,github_create_issue、github_list_repos)和面向操作的命名。

上下文管理: 智能体受益于简洁的工具描述以及过滤/分页结果的能力。设计能够返回专注、相关数据的工具。某些客户端支持代码执行,这可以帮助智能体高效地过滤和处理数据。

可操作错误消息: 错误消息应引导智能体找到解决方案,并提供具体的建议和后续步骤。

1.2 学习 MCP 协议文档

浏览 MCP 规范: 从站点地图开始,找到相关页面:https://modelcontextprotocol.io/sitemap.xml

然后使用 .md 后缀获取特定页面的 markdown 格式(例如,https://modelcontextprotocol.io/specification/draft.md)。

需要查阅的关键页面:

  • 规范概述和架构
  • 传输机制(可流式 HTTP、stdio)
  • 工具、资源和提示定义

1.3 学习框架文档

推荐技术栈:

  • 语言:TypeScript(高质量的 SDK 支持,在许多执行环境中有良好的兼容性,例如 MCPB。此外,AI 模型擅长生成 TypeScript 代码,受益于其广泛使用、静态类型和良好的 linting 工具)
  • 传输:用于远程服务器的可流式 HTTP,使用无状态 JSON(比有状态会话和流式响应更易于扩展和维护)。用于本地服务器的 stdio。

加载框架文档:

对于 TypeScript(推荐):

TypeScript SDK 有两个主要版本。在编写代码之前选择一个:

  • v2 (@modelcontextprotocol/server):当前稳定版本。用于新服务器。
  • v1 (@modelcontextprotocol/sdk):仅接收错误和安全修复。仅在项目的 package.json 已依赖 @modelcontextprotocol/sdk 时使用它,或使用 npx @modelcontextprotocol/codemod@latest v1-to-v2 . 迁移该项目。

如果项目已使用 v1,请用一两句话告诉用户,v2 (@modelcontextprotocol/server) 是当前稳定版本,v1 仅接收错误和安全修复,并且 npx @modelcontextprotocol/codemod@latest v1-to-v2 . 可以迁移项目。然后继续使用 v1,除非用户要求迁移。

不要在一个项目中同时使用两者:v1 代码示例(从 @modelcontextprotocol/sdk/... 导入)不适用于 v2。

  • TypeScript SDK (v2):使用 WebFetch 加载 https://raw.githubusercontent.com/modelcontextprotocol/typescript-sdk/main/README.md;完整文档索引为 https://ts.sdk.modelcontextprotocol.io/v2/llms.txt
  • ⚡ TypeScript 指南 (v2) - TypeScript 模式和示例
  • 仅限 v1 项目:https://raw.githubusercontent.com/modelcontextprotocol/typescript-sdk/v1.x/README.md 和 TypeScript 指南 (v1)

对于 Python:

  • Python SDK:使用 WebFetch 加载 https://raw.githubusercontent.com/modelcontextprotocol/python-sdk/main/README.md
  • 🐍 Python 指南 - Python 模式和示例

1.4 规划你的实现

理解 API: 查阅服务的 API 文档,识别关键端点、身份验证要求和数据模型。根据需要,使用网络搜索和 WebFetch。

工具选择: 优先考虑全面的 API 覆盖。列出要实现的端点,从最常见的操作开始。


阶段 2:实现

2.1 设置项目结构

请参阅特定语言的项目设置指南:

2.2 实现核心基础设施

创建共享工具:

  • 带有身份验证的 API 客户端
  • 错误处理辅助工具
  • 响应格式化(JSON/Markdown)
  • 分页支持

2.3 实现工具

对于每个工具:

输入模式:

  • 使用 Zod (TypeScript) 或 Pydantic (Python)
  • 包括约束条件和清晰描述
  • 在字段描述中添加示例

输出模式:

  • 尽可能定义 outputSchema 以获取结构化数据
  • 在工具响应中使用 structuredContent(TypeScript SDK 功能)
  • 帮助客户端理解和处理工具输出

工具描述:

  • 功能的简洁摘要
  • 参数描述
  • 返回类型模式

实现:

  • 对 I/O 操作使用 async/await
  • 使用可操作消息进行正确的错误处理
  • 在适用时支持分页
  • 使用现代 SDK 时,同时返回文本内容和结构化数据

注解:

  • readOnlyHint:true/false
  • destructiveHint:true/false
  • idempotentHint:true/false
  • openWorldHint:true/false

阶段 3:审查和测试

3.1 代码质量

审查以下内容:

  • 无重复代码(DRY 原则)
  • 一致的错误处理
  • 完整的类型覆盖
  • 清晰的工具描述

3.2 构建和测试

TypeScript:

  • 运行 npm run build 验证编译
  • v2 项目:针对构建的服务器运行 v2 指南 中的自检脚本
  • 使用 MCP Inspector 测试:npx @modelcontextprotocol/inspector

Python:

  • 验证语法:python -m py_compile your_server.py
  • 使用 MCP Inspector 测试

有关详细的测试方法 and 质量检查清单,请参阅特定语言的指南。


阶段 4:创建评估

实现 MCP 服务器后,创建全面的评估来测试其有效性。

加载 ✅ 评估指南 获取完整的评估指导。

4.1 理解评估目的

使用评估来测试 LLM 是否能够有效使用你的 MCP 服务器回答真实的、复杂的问题。

4.2 创建 10 个评估问题

要创建有效的评估,请遵循评估指南中概述的流程:

  1. 工具检查:列出可用工具并理解其能力
  2. 内容探索:使用只读操作探索可用数据
  3. 问题生成:创建 10 个复杂、真实的问题
  4. 答案验证:亲自解决每个问题以验证答案

4.3 评估要求

确保每个问题:

  • 独立:不依赖于其他问题
  • 只读:仅需要非破坏性操作
  • 复杂:需要多次工具调用和深入探索
  • 真实:基于人类关心的真实用例
  • 可验证:单一的、清晰的答案,可以通过字符串比较验证
  • 稳定:答案不会随时间变化

4.4 输出格式

创建具有以下结构的 XML 文件:

<evaluation>
  <qa_pair>
    <question>寻找关于带有动物代号的人工智能模型发布的讨论。一个模型需要一个使用 ASL-X 格式的特定安全指定。对于以斑点野猫命名的模型,正在确定的 X 是多少?</question>
    <answer>3</answer>
  </qa_pair>
<!-- 更多 qa_pairs... -->
</evaluation>

参考文件

📚 文档库

在开发过程中根据需要加载这些资源:

核心 MCP 文档(首先加载)

  • MCP 协议:从站点地图 https://modelcontextprotocol.io/sitemap.xml 开始,然后使用 .md 后缀获取特定页面
  • 📋 MCP 最佳实践 - 通用 MCP 指南,包括:
    • 服务器和工具命名约定
    • 响应格式指南(JSON vs Markdown)
    • 分页最佳实践
    • 传输选择(可流式 HTTP vs stdio)
    • 安全和错误处理标准

SDK 文档(在阶段 1/2 期间加载)

  • Python SDK:从 https://raw.githubusercontent.com/modelcontextprotocol/python-sdk/main/README.md 获取
  • TypeScript SDK (v2):从 https://raw.githubusercontent.com/modelcontextprotocol/typescript-sdk/main/README.md 获取;完整文档索引在 https://ts.sdk.modelcontextprotocol.io/v2/llms.txt
  • TypeScript SDK (v1,仅限现有 v1 项目):从 https://raw.githubusercontent.com/modelcontextprotocol/typescript-sdk/v1.x/README.md 获取

特定语言实现指南(在阶段 2 期间加载)

  • 🐍 Python 实现指南 - 完整的 Python/FastMCP 指南,包括:

    • 服务器初始化模式
    • Pydantic 模型示例
    • 使用 @mcp.tool 注册工具
    • 完整的可工作示例
    • 质量检查清单
  • ⚡ TypeScript 实现指南 (SDK v2) - 针对 @modelcontextprotocol/server 的完整 TypeScript 指南,包括:

    • 项目设置和服务器工厂
    • 工具设计:Zod 4 模式、输出格式、分页、错误处理
    • 一个完整的示例,同时提供 stdio 和可流式 HTTP,以及 bearer 身份验证
    • 资源、提示和通知
    • 验证构建服务器的自检脚本
    • 高级功能的 SDK 示例链接
    • v1 到 v2 转换表、迁移步骤和质量检查清单
  • ⚡ TypeScript 实现指南 (SDK v1) - 针对现有 @modelcontextprotocol/sdk 项目的等效指南

评估指南(在阶段 4 期间加载)

  • ✅ 评估指南 - 完整的评估创建指南,包括:
    • 问题创建指导
    • 答案验证策略
    • XML 格式规范
    • 示例问题和答案
    • 使用提供的脚本进行评估

Individual skills in this repo

This repo contains 19 individual skills — each has its own dedicated page.

academy-guide

Stop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials, and use cases from Claude Academy (academy.claude.com), Anthropic's learning hub. Trigger on: "how do I", "how can I", "getting started with", "what can Claude do", "teach me", "learn to use"; questions about artifacts, projects, skills, plugins, connectors, MCP; requests about rolling Claude out to a team, class, or organization; and any ask for training materials, onboarding content, or learning resources. Use it when the user is learning how to use a feature or product — not when they are mid-task and just want the task done. This skill composes with other skills: after consulting product documentation to answer how a Claude feature works, also check here for a matching course or tutorial — a docs-grounded answer and an Academy recommendation belong together. Only recommend on a strong match; never invent Academy content.

algorithmic-art

Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code, generative art, algorithmic art, flow fields, or particle systems. Create original algorithmic art rather than copying existing artists

anthropics/template-skill

Replace with description of the skill and when Claude should use it.

brand-guidelines

Applies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.

canvas-design

Create beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists

claude-api

|-

discernment-nudge

After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals, or emails, estimates or projections, analysis or interpretation of data, factual claims they may rely on, or a multi-step argument — invoke this skill BEFORE finalizing your reply and then, if it applies, append 2-3 short follow-up questions, each tied to something specific in what you just produced, that help the user check key facts, probe the reasoning or assumptions, and notice missing context. Do this at most once per conversation. Skip it when the user asked a trivial how-to or simple lookup, wants a purely educational explanation, asked you only to format, convert, or assemble a file from content they provided, is writing code they will run, is doing creative writing or casual chat, or already asked you to double-check, cite, or review — the skill file explains these boundaries and the exact output format.

doc-coauthoring

Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision docs, or similar structured content. This workflow helps users efficiently transfer context, refine content through iteration, and verify the doc works for readers. Trigger when user mentions writing docs, creating proposals, drafting specs, or similar documentation tasks.

docx

Use this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include: any mention of

frontend-design

Guidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.

internal-comms

A set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill whenever asked to write some sort of internal communications (status reports, leadership updates, 3P updates, company newsletters, FAQs, incident reports, project updates, etc.).

pdf

Use this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple PDFs into one, splitting PDFs apart, rotating pages, adding watermarks, creating new PDFs, filling PDF forms, encrypting/decrypting PDFs, extracting images, and OCR on scanned PDFs to make them searchable. If the user mentions a .pdf file or asks to produce one, use this skill.

pptx

Use this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or presentations; reading, parsing, or extracting text from any .pptx or .potx file (even if the extracted content will be used elsewhere, like in an email or summary); editing, modifying, or updating existing presentations; combining or splitting slide files; working with templates (.potx), layouts, speaker notes, or comments. Trigger whenever the user mentions \

skill-creator

Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill

slack-gif-creator

Knowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like

theme-factory

Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with colors/fonts that you can apply to any artifact that has been creating, or can generate a new theme on-the-fly.

webapp-testing

Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.

web-artifacts-builder

Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn/ui). Use for complex artifacts requiring state management, routing, or shadcn/ui components - not for simple single-file HTML/JSX artifacts.

xlsx

Use this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like \

相关技能