Agent skill

MCP Server Builder

by jnMetaCode in jnMetaCode/superpowers-zh

Methodology for designing, implementing and testing Model Context Protocol servers in TypeScript or Python, covering tool design, error handling and security, in Chinese.

MITAuto-check passedAgent Workflows

SKILL.md written in Chinese; this summary is our English description.

Install MCP Server Builder

skills CLI
$ npx skills add jnMetaCode/superpowers-zh --skill mcp-builder -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install jnMetaCode/superpowers-zh mcp-builder --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/jnMetaCode/superpowers-zh.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/mcp-builder .claude/skills/mcp-builder && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
mcp-builder
GitHub stars
8.3k
Token cost
~1.4k tokens
SKILL.md length
250 words
Files
1
Skills in repo
21
Repo updated
First seen
Licence
MIT

At a glance

Methodology for designing, implementing and testing Model Context Protocol servers in TypeScript or Python, covering tool design, error handling and security, in Chinese.

  • Works in 10 steps: 协议核心概念 → 项目结构规范 → Tool 设计原则 → …
  • Building a new MCP server so an assistant can reach an external service
  • SKILL.md covers 1. 协议核心概念, 2. 项目结构规范, 3. Tool 设计原则 and 4. 输入验证和错误处理, plus 6 more sections
  • Calls npx; needs API_KEY

What it does

The skill starts with the three MCP primitives and how to choose between them: tools for actions with side effects, resources for read-only data identified by URIs, and prompts for predefined interaction templates. It gives project layouts for TypeScript with `@modelcontextprotocol/sdk` and `zod`, and for Python with `mcp` and `pydantic`.

Tool design rules cover verb-first snake_case names, typed and described parameters, defaults for optional ones, enums instead of boolean switches, and descriptions that state purpose, return value and limits. Errors follow four principles: never crash the server, return actionable messages, set `isError: true`, and separate error types. Further sections cover connection pooling, timeouts and graceful shutdown, unit tests that keep business logic apart from MCP registration, integration tests with linked in-memory transports, and the MCP Inspector for interactive debugging. A security section on least privilege and separated read and write tools is cut off in the excerpt.

When your agent uses it

  • Building a new MCP server so an assistant can reach an external service
  • Reviewing MCP tool names, schemas and descriptions for clarity
  • Adding tests and an Inspector workflow to an existing MCP server

Example prompts

  • “Build an MCP server in TypeScript with a search_issues tool and tests that cover failure paths.”
  • “帮我把这个 Python MCP 服务器的错误处理改成返回 isError 和可操作的提示。”
  • “Review my MCP tool descriptions and tell me which names are too vague for a model to pick correctly.”

Requirements

  • Node.js or Python for the server project

Workflow steps

10 steps, taken from the step headings in SKILL.md.

  1. 协议核心概念
  2. 项目结构规范
  3. Tool 设计原则
  4. 输入验证和错误处理
  5. 资源管理和生命周期
  6. 测试策略
  7. 安全考虑
  8. 部署和分发
  9. 调试技巧
  10. 构建检查清单

What it can do on your machine

Read from SKILL.md and the folder at commit fe34019. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • npx

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md. Its commands use npx, which can reach the network depending on how they are called.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names these keys or tokens, usually read from environment variables:

    • API_KEY

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

MCP Server Builder loads about 1.4k tokens when it runs. Until then it costs about 23 tokens; SKILL.md has 250 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~23
When it runs · the whole SKILL.md, loaded when a task matches
~1.4k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from jnMetaCode/superpowers-zh at commit fe34019, republished under its MIT licence (© jnMetaCode). 250 words, ~1,392 tokens.

Download SKILL.mdSave it as .claude/skills/mcp-builder/SKILL.md (or your agent's skills folder).
name
mcp-builder
description
在构建 MCP 服务器或 MCP 工具时使用 —— 系统化的生产级 MCP 构建方法论,覆盖工具设计、错误处理、传输层选择与测试,让 AI 助手连接外部能力
version
1.0.0
license
MIT

MCP 服务器构建

系统化设计、实现、测试和部署 Model Context Protocol 服务器的方法论。

1. 协议核心概念

MCP 定义三种原语:

  • Tools(工具):AI 助手主动调用的函数,有副作用。如搜索、创建、删除操作。
  • Resources(资源):AI 助手只读访问的数据源,用 URI 标识。如 users://{id}/profile。
  • Prompts(提示词模板):预定义交互模板,引导用户触发工作流。

选择原则: 执行操作 → Tool | 读取数据 → Resource | 引导交互 → Prompt

2. 项目结构规范

TypeScript
my-mcp-server/
├── src/
│   ├── index.ts          # 入口,注册 tools/resources
│   ├── tools/             # 按功能拆分
│   ├── resources/
│   └── lib/               # 客户端封装、校验逻辑
├── tests/
├── package.json
└── tsconfig.json

关键依赖:@modelcontextprotocol/sdk + zod

Python
my-mcp-server/
├── src/my_mcp_server/
│   ├── server.py
│   ├── tools/
│   └── lib/
├── tests/
└── pyproject.toml

关键依赖:mcp + pydantic

3. Tool 设计原则

命名
  • snake_case 格式,动词开头:search_users、create_issue、delete_file
  • 名称自解释,AI 助手靠名称选工具,模糊命名导致误调用
参数
  • 每个参数有类型约束和 .describe() 描述
  • 可选参数给默认值,减少 AI 决策负担
  • 用枚举代替布尔开关
typescript
server.tool("search_issues", {
  query: z.string().describe("搜索关键词"),
  status: z.enum(["open", "closed", "all"]).default("open").describe("状态筛选"),
  limit: z.number().min(1).max(100).default(20).describe("返回上限"),
}, async ({ query, status, limit }) => { /* ... */ });
描述

说明用途 + 返回内容 + 限制,这是 AI 选择工具的关键依据:

typescript
server.tool("search_users",
  "根据姓名或邮箱搜索用户。返回 ID、姓名、邮箱列表。模糊匹配,最多 50 条。",
  schema, handler);
输出
  • 结构化数据 → JSON,人类可读内容 → Markdown
  • 始终用 content: [{ type: "text", text: "..." }] 格式返回

4. 输入验证和错误处理

用 Zod/Pydantic 做 Schema 级校验,业务级校验放 handler 开头:

typescript
server.tool("get_user", { id: z.string() }, async ({ id }) => {
  try {
    const user = await db.getUser(id);
    if (!user) {
      return {
        content: [{ type: "text", text: `用户 ${id} 不存在,请检查 ID。` }],
        isError: true,
      };
    }
    return { content: [{ type: "text", text: JSON.stringify(user, null, 2) }] };
  } catch (err) {
    return {
      content: [{ type: "text", text: `查询失败:${err.message}` }],
      isError: true,
    };
  }
});

错误处理四原则:

  1. 永远不让服务器崩溃 — try/catch 包裹所有外部调用
  2. 返回可操作的错误信息 — 告诉 AI 问题是什么、能做什么
  3. 使用 isError: true — 让 AI 知道调用失败
  4. 区分错误类型 — 参数错误、权限不足、资源不存在、服务不可用

5. 资源管理和生命周期

typescript
// 资源注册
server.resource("user-profile", "users://{userId}/profile", async (uri) => {
  const profile = await db.getProfile(extractId(uri));
  return { contents: [{ uri: uri.href, mimeType: "application/json", text: JSON.stringify(profile) }] };
});

// 生命周期:先初始化 → 再 connect → 监听关闭信号
const db = await Database.connect(config.dbUrl);
await server.connect(new StdioServerTransport());
process.on("SIGINT", async () => { await db.disconnect(); await server.close(); process.exit(0); });

关键点:使用连接池、所有外部调用设超时、优雅关闭清理资源。

6. 测试策略

单元测试 — 业务逻辑与 MCP 注册分离
typescript
// tools/search.ts 导出纯函数
export async function searchUsers(query: string, limit: number) { /* ... */ }

// search.test.ts 独立测试
test("返回匹配结果", async () => {
  const results = await searchUsers("alice", 10);
  expect(results[0].name).toContain("Alice");
});
集成测试 — 用 SDK Client 做端到端验证
typescript
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
await server.connect(serverTransport);
const client = new Client({ name: "test", version: "1.0.0" });
await client.connect(clientTransport);
const result = await client.callTool("search_users", { query: "test" });
expect(result.isError).toBeFalsy();
MCP Inspector — 交互式调试
bash
npx @modelcontextprotocol/inspector node dist/index.js

在浏览器中查看所有 tools/resources,手动调用并查看结果。

测试要点: 每个 Tool 覆盖正常 + 异常路径、边界值、外部服务失败模拟。

7. 安全考虑

权限控制:

  • 最小权限原则,读写 Tool 分离
  • 危险操作要求确认参数(如 confirm: true)

输入安全:

  • SQL 注入 → 参数化查询,绝不拼接
  • 路径遍历 → 校验路径,禁止 ../
  • 命令注入 → 用 execFile 而非 exec

敏感数据:

  • 密钥通过环境变量传入,不硬编码
  • 日志不打印完整敏感信息
  • 返回数据做脱敏处理

沙箱: 文件操作限制目录、网络请求限制白名单、设置资源配额。

8. 部署和分发

npm 发布
json
{ "bin": { "mcp-server-myservice": "dist/index.js" }, "files": ["dist"] }

用户配置:

json
{ "mcpServers": { "myservice": { "command": "npx", "args": ["@yourorg/mcp-server-myservice"], "env": { "API_KEY": "xxx" } } } }
pip 发布
toml
[project.scripts]
mcp-server-myservice = "my_mcp_server.server:main"
Docker — 适用于复杂依赖或隔离场景
dockerfile
FROM node:20-slim
WORKDIR /app
COPY package*.json ./ && RUN npm ci --production
COPY dist ./dist
ENTRYPOINT ["node", "dist/index.js"]

9. 调试技巧

关键:MCP 用 stdio 通信,不能用 console.log,会破坏协议流。

typescript
// 错误
console.log("debug");
// 正确
console.error("[DEBUG]", info);
// 更好
server.sendLoggingMessage({ level: "info", data: "处理中" });

常见问题:

症状原因解决
启动无响应transport 未连接检查 server.connect()
Tool 不出现注册在 connect 之后先注册再 connect
AI 不调用 Tool描述不清晰改善名称和描述
参数总错Schema 不明确添加 .describe()
调用超时外部服务慢加超时和缓存

调试流程: Inspector 验证基本功能 → 手动调用确认输入输出 → 连接真实 AI 客户端观察调用模式 → 根据实际行为调整设计。

10. 构建检查清单

设计
  • 明确 Tools vs Resources vs Prompts 分工
  • Tool 命名 动词_名词,描述说明用途和返回内容
  • 参数简洁,可选参数有合理默认值
实现
  • 输入用 Zod/Pydantic 校验
  • 外部调用有 try/catch 和超时
  • 错误返回 isError: true 并附可操作信息
  • 不用 console.log(用 stderr 或 SDK 日志)
  • 敏感数据走环境变量
测试
  • 核心逻辑有单元测试
  • 有集成测试验证 MCP 协议交互
  • 用 MCP Inspector 手动验证过
  • 用真实 AI 客户端测试过
部署
  • README 含安装和配置说明
  • 提供客户端配置 JSON 示例
  • 遵循 semver,无硬编码密钥

© jnMetaCode, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in skills/mcp-builder of jnMetaCode/superpowers-zh.

Open the folder on GitHubat commit fe34019

Compare with similar skills

MCP Server Builder next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

MCP Server Builder compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
MCP Server Builder this skilljnMetaCode/superpowers-zh8.3k—~1.4kAutomated safety check: PassMIT
MCP DeveloperJeffallan/claude-skills12k—~1.5kAutomated safety check: PassMIT
MCP Scaffoldtimothywarner-org/claude-code224—~940Automated safety check: PassMIT
MCP SDK Auditawdr74100/figwright982—~4.1kAutomated safety check: PassMIT
Unifi MCP Tool Builderenuno/unifi-mcp-server282—~5.8kAutomated safety check: PassApache-2.0
Vscode MCP Tool Developmenttjx666/vscode-mcp106—~1.5kAutomated safety check: PassCustom licence

Similar skills

  • MCP Developer

    Jeffallan/claude-skills

    Builds and debugs MCP servers and clients in TypeScript or Python, from tool and resource definitions to transport setup and inspector-based protocol checks.

    12k GitHub stars~1.5k tokensUpdated 5 days ago
    Agent WorkflowsAuto-check passed
  • MCP Scaffold

    timothywarner-org/claude-code

    Scaffold production-ready Python MCP servers using FastMCP. An agent skill from timothywarner-org/claude-code.

    224 GitHub stars~940 tokensUpdated 2 mo ago
    Agent WorkflowsAuto-check passed
  • MCP SDK Audit

    awdr74100/figwright

    Upgrade @modelcontextprotocol/server (the MCP TypeScript SDK v2) and prove the wire contract survived.

    982 GitHub stars~4.1k tokensUpdated yesterday
    Agent WorkflowsAuto-check passed
  • Unifi MCP Tool Builder

    enuno/unifi-mcp-server

    Specialized guide for adding new MCP tools to the UniFi MCP Server following project standards, UniFi API patterns, and test-driven development practices.

    282 GitHub stars~5.8k tokensUpdated today
    Agent WorkflowsAuto-check passed
  • End-to-end workflow for adding, modifying, or debugging VSCode MCP tools in this repo — IPC zod schema and EventMap, bridge service registration, core ToolDefinition and tool constants, MCP/CLI…

    106 GitHub stars~1.5k tokensUpdated 2 mo ago
    Agent WorkflowsAuto-check passed
  • Development Assistant

    RobThePCGuy/Claude-Patent-Creator

    Guides through adding new features, MCP tools, analyzers, and extending the patent creator system.

    196 GitHub stars~1.3k tokensUpdated 2 days ago
    Agent WorkflowsAuto-check: notes

More from jnMetaCode/superpowers-zh

All 21 skills in this repo
  • Brainstorming Before Building

    jnMetaCode/superpowers-zh

    Turns a rough idea into an approved design before any code is written, sorting the request into spike, bounded or architectural and enforcing an approval gate.

    8.3k GitHub stars~1.8k tokensUpdated 4 days ago
    Auto-check passed
  • Chinese Commit Conventions

    jnMetaCode/superpowers-zh

    Reference for Chinese-language git commits and changelogs: Conventional Commits adapted for Chinese teams, with templates, breaking-change notes and issue links for several platforms.

    8.3k GitHub starsUsed in 1 repo~1.6k tokens
    Auto-check passed
  • Inline Plan Execution

    jnMetaCode/superpowers-zh

    Executes a written implementation plan task by task in the current session, with a progress ledger, test-first gates and one fresh-context review at the end.

    8.3k GitHub stars~2.5k tokensUpdated 4 days ago
    Auto-check passed
  • Git Worktree Isolation

    jnMetaCode/superpowers-zh

    Sets up an isolated workspace before feature work or plan execution, preferring native worktree tools and falling back to git worktree, with instructions in Chinese.

    8.3k GitHub starsUsed in 1 repo~982 tokens
    Auto-check passed
  • Agency Orchestrator Workflow Runner

    jnMetaCode/superpowers-zh

    Runs agency-orchestrator YAML workflows inside the current agent session, with the session's own model playing each role in turn and no API key needed.

    8.3k GitHub starsUsed in 1 repo~885 tokens
    Auto-check passed
  • Chinese Code Review Etiquette

    jnMetaCode/superpowers-zh

    Gives Chinese-language templates and priority labels for code review feedback, plus guidance on bilingual comments, commit messages and common team anti-patterns.

    8.3k GitHub stars~1.2k tokensUpdated 4 days ago
    Auto-check passed

Questions about MCP Server Builder

What does MCP Server Builder do?

Methodology for designing, implementing and testing Model Context Protocol servers in TypeScript or Python, covering tool design, error handling and security, in Chinese. The skill starts with the three MCP primitives and how to choose between them: tools for actions with side effects, resources for read-only data identified by URIs, and prompts for predefined interaction templates. It gives project layouts for TypeScript with `@modelcontextprotocol/sdk` and `zod`, and for Python with `mcp` and `pydantic`.

When should I use MCP Server Builder?

MCP Server Builder fits situations like: building a new MCP server so an assistant can reach an external service; reviewing MCP tool names, schemas and descriptions for clarity; adding tests and an Inspector workflow to an existing MCP server.

How do I install MCP Server Builder in Claude Code?

Run `npx skills add jnMetaCode/superpowers-zh --skill mcp-builder -a claude-code`. Or copy the skill folder (skills/mcp-builder in jnMetaCode/superpowers-zh) into .claude/skills/mcp-builder in your project. Claude Code loads it when a task matches its description.

How do I install MCP Server Builder in Codex?

Run `npx skills add jnMetaCode/superpowers-zh --skill mcp-builder -a codex`. Or copy the skill folder (skills/mcp-builder in jnMetaCode/superpowers-zh) into .agents/skills/mcp-builder in your project. Codex loads it when a task matches its description.

Can I use MCP Server Builder in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add jnMetaCode/superpowers-zh --skill mcp-builder -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/mcp-builder, .gemini/skills/mcp-builder, .github/skills/mcp-builder and .opencode/skills/mcp-builder in your project.

What does MCP Server Builder need to run?

Going by SKILL.md and its folder, MCP Server Builder needs the command-line tools its instructions call (npx) and credentials named API_KEY. Our summary lists: Node.js or Python for the server project.

Does MCP Server Builder access the network?

SKILL.md contains no URLs. Its commands use npx, which can reach the network depending on how they are called. This is read from the text; nothing was executed.

Is MCP Server Builder safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does MCP Server Builder use?

MCP Server Builder is published under the MIT licence (declared in SKILL.md). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does MCP Server Builder use?

About 1.4k tokens (SKILL.md is roughly 5.6k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to MCP Server Builder?

Skills that share tags, products or a category with MCP Server Builder: MCP Developer (Jeffallan/claude-skills, 12k stars), MCP Scaffold (timothywarner-org/claude-code, 224 stars), MCP SDK Audit (awdr74100/figwright, 982 stars) and Unifi MCP Tool Builder (enuno/unifi-mcp-server, 282 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains MCP Server Builder?

jnMetaCode (a GitHub user) maintains it in jnMetaCode/superpowers-zh, which has 8,270 GitHub stars. The repository holds 21 skills in this directory. The repository was last updated on October 4, 2026.

Source: jnMetaCode/superpowers-zh on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.