MCP 生成
- 作者仓库星标 0
- 作者更新于 实时读取
- 作者仓库 skills-registry
- 领域
- AI 智能
- 兼容 Agent
-
- Claude Code
- Cursor
- Cline
- Codex
- Windsurf
- Gemini CLI
- +20
- 信任分
- 88 / 100 · 社区维护
- 作者 / 版本 / 许可
- @tomevault-io · 未声明 license
- Token 消耗评级
- 低消耗
- 接入复杂程度
- 需手动接入
- 是否需要外部 API Key
- 不需要
- 兼容的系统
- Windows
- 底层运行要求
- Node.js · Python
- 文件与系统权限
-
- 只读
- 允许写入 / 修改
- Shell 执行
- 读取环境变量
- 网络行为
- 仅限本地
- 安装命令数
- 26 条
档案由构建时根据 SKILL.md 与安装命令自动衍生,可能与作者实际意图存在差异。
需要注意: 未限定 allowed-tools,默认拥有全部工具权限。
---
name: mcp-server-builder
description: > Use when this capability is needed. Build an MCP server that extends Claude Code with new tool…
category: AI 智能
runtime: Node.js / Python
---
# mcp-server-builder 输出预览
## PART A: 任务判断
- 适用问题:提示词、Agent 工作流、模型评估或自动化推理。
- 输入要求:目标材料、限制条件、期望输出和验收方式。
- 证据边界:围绕“STEP 1: Define the Server Scope / 1.1 Identify Capabilities / 1.2 Agent-Centric Design Principles”读取原文规则,不把推断写成作者承诺。
## PART B: 执行结果
- **01** 任务判断:确认你的需求是否属于提示词、Agent 工作流、模型评估或自动化推理,并标出输入、限制和预期结果。
- **02** 执行计划:优先按“STEP 1: Define the Server Scope / 1.1 Identify Capabilities / 1.2 Agent-Centric Design Principles”拆成步骤,说明每一步会读取什么、修改什么、产出什么。
- **03** 交付结果:给出可复制的命令、文件改动、检查清单或内容草稿,并说明如何继续迭代。
- **04** 风险边界:结合 读取文件、写入/修改文件、执行终端命令、读取环境变量、主要在本地完成、通常不需要额外 API Key 给出执行前确认项。
## Running Rules
- 读取文件、写入/修改文件、执行终端命令、读取环境变量;主要在本地完成;通常不需要额外 API Key。
- 先小样例验证,再放大到真实任务。
- 交付时同时给结果、检查口径和下一步迭代建议。 原文没有稳定的斜杠命令要求。安装验证后通常全局生效,直接在对话里点名这个 Skill 并描述任务即可。
告诉 Agent 目标文件或材料、期望结果、不可改范围、是否允许联网或执行命令。本 Skill 的权限画像是:读取文件、写入/修改文件、执行终端命令、读取环境变量。
先用一个小任务确认它会围绕“STEP 1: Define the Server Scope / 1.1 Identify Capabilities / 1.2 Agent-Centric Design Principles”工作;涉及文件或命令时,先看 diff、日志、预览或测试结果。
检查最终产物是否包含明确结果、必要证据和下一步动作;如果输出泛泛而谈,就补充输入、边界和验收标准后重跑。
---
name: mcp-server-builder
description: > Use when this capability is needed. Build an MCP server that extends Claude Code with new tool…
category: AI 智能
source: tomevault-io/skills-registry
---
# mcp-server-builder
## 什么时候使用
- 把 AI / Agent方向的常用动作沉淀成 Agent 可调用的技能 适合处理AI Agent、提示词、模型评估与自动化推理,核心价值是把输入、判断、执行、验证和交付边界固定下来,避免 Agent 泛泛回答。 把任务拆成可执行、可检查…
- 面向提示词、Agent 工作流、模型评估或自动化推理,优先处理能明确输入、步骤和验收标准的工作。
## 需要提供什么
- 目标材料、目录范围、期望结果和不可改动内容。
- 是否允许联网、执行命令、读写文件或调用外部服务。
## 执行规则
- 围绕「STEP 1: Define the Server Scope / 1.1 Identify Capabilities / 1.2 Agent-Centric Design Principles」组织步骤,不把推断写成作者事实。
- 读取文件、写入/修改文件、执行终端命令、读取环境变量;主要在本地完成;通常不需要额外 API Key。
- 先跑小样例,确认结果可检查后再扩大任务范围。
## 输出要求
- 给出最终产物、关键证据、验证方式和下一步动作。
- 信息不足时标记 unknown,不编造命令、平台或依赖。 作者原文负责流程事实;仓库文件负责来源和命令;流狐只补充适用场景、限制和质量判断。
skill "mcp-server-builder" {
输入层 -> 用户目标 + 目标文件 + 禁止范围 + 验收标准
上下文层 -> STEP 1: Define the Server Scope / 1.1 Identify Capabilities / 1.2 Agent-Centric Design Principles
规则层 -> SKILL.md 触发条件 / 执行顺序 / 输出格式
运行层 -> Node.js / Python | 读取文件、写入/修改文件、执行终端命令、读取环境变量 | 主要在本地完成
安全层 -> 通常不需要额外 API Key + 小任务验证 + diff / 日志复核
输出层 -> 可复制结果 + 检查清单 + 下一步迭代
} MCP Server Builder
Build an MCP server that extends Claude Code with new tools, resources, or prompts.
Server Purpose: $ARGUMENTS
STEP 1: Define the Server Scope
Before writing code, define what the MCP server will expose:
1.1 Identify Capabilities
| MCP Primitive | Use When | Examples |
|---|---|---|
| Tools | Claude needs to perform actions or retrieve computed data | Query a database, create a ticket, run a deployment |
| Resources | Claude needs to read structured data | Config files, API schemas, documentation |
| Prompts | Claude needs reusable prompt templates | Code review checklist, incident response template |
1.2 Agent-Centric Design Principles
MCP servers are consumed by AI agents, not humans. Design accordingly:
Build for workflows, not endpoints — Group related operations into tools that match how an agent thinks about a task. One tool that "creates a PR with tests" beats three tools for "create branch", "commit files", "open PR".
Optimize for limited context — Return only what the agent needs. A tool that returns a 10,000-line log is worse than one that returns the 20 relevant lines with context.
Make errors actionable — Instead of
"Error: 403", return"Permission denied: the API token lacks 'write:issues' scope. Add this scope at https://...". The agent should be able to fix the problem from the error message alone.Provide discovery — Include a tool that lists available resources or explains what the server can do. Agents need to understand capabilities at runtime.
Idempotent where possible — Agents may retry tools. Design create/update operations to be safe to call multiple times with the same input.
1.3 Define Tool Signatures
For each tool, define:
Tool: <name>
Description: <what it does — this is what Claude reads to decide whether to use it>
Input: <parameters with types and descriptions>
Output: <what it returns>
Side effects: <what it changes in the external system>
Error cases: <what can go wrong and what the error message should say>
Description quality matters. Claude selects tools based on their descriptions. A vague description like "manage issues" produces poor tool selection. Be specific: "Create a new GitHub issue with title, body, labels, and assignee. Returns the issue URL and number."
STEP 2: Choose SDK and Scaffold
Option A: Python with FastMCP
FastMCP is the recommended Python SDK — minimal boilerplate, decorator-based.
# Initialize project
mkdir mcp-server-<name> && cd mcp-server-<name>
python -m venv .venv && source .venv/bin/activate # or .venv/Scripts/activate on Windows
pip install fastmcp
Scaffold:
# server.py
from fastmcp import FastMCP
mcp = FastMCP(
name="<server-name>",
description="<what this server does>",
)
@mcp.tool()
def example_tool(param: str) -> str:
"""Description that Claude reads to decide when to use this tool.
Args:
param: What this parameter controls
"""
# Implementation here
return "result"
@mcp.resource("resource://{name}")
def example_resource(name: str) -> str:
"""Provides access to <what>."""
return "resource content"
if __name__ == "__main__":
mcp.run()
Option B: Node.js / TypeScript SDK
mkdir mcp-server-<name> && cd mcp-server-<name>
npm init -y
npm install @modelcontextprotocol/sdk
npm install -D typescript @types/node
npx tsc --init
Scaffold:
// src/index.ts
import { McpServer, ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
const server = new McpServer({
name: "<server-name>",
version: "1.0.0",
});
server.tool(
"example-tool",
"Description that Claude reads to decide when to use this tool",
{ param: { type: "string", description: "What this parameter controls" } },
async ({ param }) => {
// Implementation here
return { content: [{ type: "text", text: "result" }] };
}
);
const transport = new StdioServerTransport();
await server.connect(transport);
STEP 3: Implement Tools
3.1 Tool Implementation Checklist
For each tool:
- Description is specific and tells Claude WHEN to use it (not just what it does)
- All parameters have types, descriptions, and sensible defaults where applicable
- Return values are concise — only what the agent needs for next steps
- Errors include actionable remediation instructions
- Side effects are documented in the description
- Tool is idempotent or clearly marked as non-idempotent
3.2 Input Validation
Validate inputs and return helpful messages:
@mcp.tool()
def create_issue(title: str, body: str, labels: list[str] | None = None) -> str:
"""Create a GitHub issue in the current repository.
Args:
title: Issue title (required, max 256 chars)
body: Issue body in markdown
labels: Optional list of label names (must already exist in repo)
"""
if not title.strip():
return "Error: title is required and cannot be empty."
if len(title) > 256:
return f"Error: title is {len(title)} chars, max is 256. Shorten the title."
# ... implementation
3.3 Error Handling Pattern
try:
result = external_api.call(params)
return format_result(result)
except AuthenticationError:
return (
"Error: Authentication failed. Check that your API token is set in the "
"environment variable EXAMPLE_API_TOKEN and has the required scopes: "
"read:data, write:data. Generate a token at https://example.com/settings/tokens"
)
except RateLimitError as e:
return f"Error: Rate limited. Retry after {e.retry_after} seconds."
except Exception as e:
return f"Error: Unexpected failure — {type(e).__name__}: {e}"
3.4 Output Formatting
Return structured, scannable output:
# BAD: Wall of text
return json.dumps(full_api_response)
# GOOD: Curated summary
return f"""Issue created successfully.
- URL: {issue.html_url}
- Number: #{issue.number}
- Labels: {', '.join(issue.labels)}
Next: assign the issue with the assign-issue tool, or link it to a PR."""
STEP 4: Implement Resources (if needed)
Resources provide read-only data that Claude can reference:
@mcp.resource("config://settings")
def get_settings() -> str:
"""Current project settings including API endpoints and feature flags."""
settings = load_settings()
# Return only what's relevant, not the entire config
return yaml.dump({
"api_base": settings["api_base"],
"features": settings["features"],
"environment": settings["environment"],
})
Resource Design Rules
- URI scheme matters — Use descriptive schemes:
docs://,config://,schema:// - Keep payloads small — Resources are loaded into context. A 50KB resource wastes tokens.
- Provide templates for parameterized access —
docs://{topic}is better than dumping all docs at once
STEP 5: Configure for Claude Code
5.1 Register in .mcp.json
Add the server to the project's .mcp.json:
{
"mcpServers": {
"<server-name>": {
"command": "python",
"args": ["path/to/server.py"],
"env": {
"EXAMPLE_API_TOKEN": "${EXAMPLE_API_TOKEN}"
}
}
}
}
For Node.js:
{
"mcpServers": {
"<server-name>": {
"command": "node",
"args": ["path/to/dist/index.js"]
}
}
}
5.2 Environment Variables
NEVER hardcode credentials in the server. Use environment variables:
import os
API_TOKEN = os.environ.get("EXAMPLE_API_TOKEN")
if not API_TOKEN:
raise RuntimeError(
"EXAMPLE_API_TOKEN environment variable is required. "
"Set it in .mcp.json env block or your shell profile."
)
STEP 6: Test the Server
6.1 Manual Testing
# Test with MCP Inspector (if available)
npx @modelcontextprotocol/inspector python server.py
# Or test directly by running the server and sending JSON-RPC
echo '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' | python server.py
6.2 Automated Tests
Write tests for each tool:
# test_server.py
import pytest
from server import mcp
@pytest.fixture
def client():
"""Create a test client for the MCP server."""
return mcp.test_client()
def test_example_tool_happy_path(client):
result = client.call_tool("example-tool", {"param": "test"})
assert "expected output" in result
def test_example_tool_missing_param(client):
result = client.call_tool("example-tool", {})
assert "Error:" in result
def test_example_tool_error_is_actionable(client):
result = client.call_tool("example-tool", {"param": "invalid"})
# Error messages MUST tell the agent how to fix the problem
assert any(word in result.lower() for word in ["try", "check", "use", "set"])
6.3 Evaluation-Driven Development
Beyond unit tests, evaluate how well Claude uses your tools:
- Discovery test — Ask Claude "what tools do you have for X?" Does it find your tool?
- Selection test — Give Claude a task that should use your tool. Does it pick the right one?
- Error recovery test — Trigger an error. Can Claude fix the problem from the error message?
- Workflow test — Give Claude a multi-step task. Does it chain your tools correctly?
If Claude struggles with any of these, improve the tool descriptions and error messages — don't blame the model.
STEP 7: Document and Ship
7.1 README
Create a README with:
- What the server does (one paragraph)
- Prerequisites (API keys, services, permissions)
- Installation and configuration steps
- List of tools with descriptions
- Example usage scenarios
7.2 Version and Maintain
- Pin dependency versions in
requirements.txtorpackage.json - Follow semantic versioning — breaking tool signature changes = major version bump
- Test after Claude Code updates — MCP protocol may evolve
MUST DO
- Always validate all tool inputs and return actionable error messages
- Always keep tool descriptions specific enough for Claude to select correctly
- Always use environment variables for credentials — never hardcode
- Always test each tool with both happy path and error cases
- Always keep resource payloads small — curate, don't dump
- Always make tools idempotent where the external system allows it
MUST NOT DO
- MUST NOT return raw API responses — curate the output for agent consumption
- MUST NOT use vague tool descriptions — "manages data" tells Claude nothing
- MUST NOT expose credentials in error messages or logs
- MUST NOT create tools with overlapping purposes — Claude will pick randomly between them
- MUST NOT return more than ~2KB per tool call unless the agent specifically needs bulk data
- MUST NOT skip error handling — an unhandled exception crashes the MCP server
Source: abhayla/claude-best-practices — distributed by TomeVault.
先判断是否适合
作者设计意图
作者的方法与取舍
边界和复核