mcp-builder
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMCP Builder
MCP 构建器
Build a working MCP server from a description of the tools you need. Produces a deployable Python server using FastMCP.
根据你所需工具的描述构建可运行的MCP服务器。使用FastMCP生成可部署的Python服务器。
Workflow
工作流程
Step 1: Define What to Expose
步骤1:定义要暴露的内容
Ask what the server needs to provide:
- Tools — Functions Claude can call (API wrappers, calculations, file operations)
- Resources — Data Claude can read (database records, config, documents)
- Prompts — Reusable prompt templates with parameters
A brief like "MCP server for querying our customer database" is enough.
明确服务器需要提供的内容:
- 工具 — Claude可调用的函数(API封装器、计算、文件操作)
- 资源 — Claude可读取的数据(数据库记录、配置、文档)
- 提示词 — 带参数的可复用提示词模板
类似“用于查询客户数据库的MCP服务器”这样的简短描述就足够了。
Step 2: Scaffold the Server
步骤2:搭建服务器框架
bash
pip install fastmcpCopy and customise :
assets/basic-server.pypython
from fastmcp import FastMCPbash
pip install fastmcp复制并自定义:
assets/basic-server.pypython
from fastmcp import FastMCPMUST be at module level for FastMCP Cloud
MUST be at module level for FastMCP Cloud
mcp = FastMCP("My Server")
@mcp.tool()
async def search_customers(query: str) -> str:
"""Search customers by name or email."""
# Implementation here
return f"Found customers matching: {query}"
@mcp.resource("customers://{customer_id}")
async def get_customer(customer_id: str) -> str:
"""Get customer details by ID."""
return f"Customer {customer_id} details"
if name == "main":
mcp.run()
undefinedmcp = FastMCP("My Server")
@mcp.tool()
async def search_customers(query: str) -> str:
"""Search customers by name or email."""
# Implementation here
return f"Found customers matching: {query}"
@mcp.resource("customers://{customer_id}")
async def get_customer(customer_id: str) -> str:
"""Get customer details by ID."""
return f"Customer {customer_id} details"
if name == "main":
mcp.run()
undefinedStep 3: Add Companion CLI Scripts (Optional)
步骤3:添加配套CLI脚本(可选)
For Claude Code terminal use, add scripts alongside the MCP server:
my-mcp-server/
├── src/index.ts # MCP server (for Claude.ai)
├── scripts/
│ ├── search.ts # CLI version of search tool
│ └── _shared.ts # Shared auth/config
├── SCRIPTS.md # Documents available scripts
└── package.jsonCLI scripts provide file I/O, batch processing, and richer output that MCP can't.
See and for TypeScript templates.
assets/SCRIPTS-TEMPLATE.mdassets/script-template.ts对于Claude Code终端使用,在MCP服务器旁添加脚本:
my-mcp-server/
├── src/index.ts # MCP server (for Claude.ai)
├── scripts/
│ ├── search.ts # CLI version of search tool
│ └── _shared.ts # Shared auth/config
├── SCRIPTS.md # Documents available scripts
└── package.jsonCLI脚本提供MCP不支持的文件I/O、批量处理和更丰富的输出。请查看和获取TypeScript模板。
assets/SCRIPTS-TEMPLATE.mdassets/script-template.tsStep 4: Test Locally
步骤4:本地测试
bash
undefinedbash
undefinedRun server directly
Run server directly
python server.py
python server.py
With FastMCP dev mode (auto-reload)
With FastMCP dev mode (auto-reload)
fastmcp dev server.py
fastmcp dev server.py
HTTP mode for remote clients
HTTP mode for remote clients
python server.py --transport http --port 8000
python server.py --transport http --port 8000
Test with MCP Inspector
Test with MCP Inspector
fastmcp dev server.py --with-editable .
undefinedfastmcp dev server.py --with-editable .
undefinedStep 5: Deploy
步骤5:部署
FastMCP Cloud (simplest):
bash
fastmcp deploy server.py --name my-serverDocker (self-hosted):
See for Dockerfile patterns.
references/cloud-deployment.mdCloudflare Workers (edge):
See the cloudflare-worker-builder skill for Workers-based MCP servers.
FastMCP Cloud(最简方式):
bash
fastmcp deploy server.py --name my-serverDocker(自托管):
请查看获取Dockerfile示例。
references/cloud-deployment.mdCloudflare Workers(边缘部署):
请查看cloudflare-worker-builder技能获取基于Workers的MCP服务器构建方法。
Critical Patterns
关键模式
Module-Level Server Instance
模块级服务器实例
FastMCP Cloud requires the server instance at module level:
python
undefinedFastMCP Cloud要求服务器实例位于模块级别:
python
undefinedCORRECT
CORRECT
mcp = FastMCP("My Server")
@mcp.tool()
def my_tool(): ...
mcp = FastMCP("My Server")
@mcp.tool()
def my_tool(): ...
WRONG — Cloud can't find the server
WRONG — Cloud can't find the server
def create_server():
mcp = FastMCP("My Server")
return mcp
undefineddef create_server():
mcp = FastMCP("My Server")
return mcp
undefinedType Annotations Required
必须使用类型注解
FastMCP uses type annotations to generate tool schemas:
python
@mcp.tool()
async def search(
query: str, # Required parameter
limit: int = 10, # Optional with default
tags: list[str] = [] # Complex types supported
) -> str:
"""Docstring becomes the tool description."""
...FastMCP使用类型注解生成工具 schema:
python
@mcp.tool()
async def search(
query: str, # Required parameter
limit: int = 10, # Optional with default
tags: list[str] = [] # Complex types supported
) -> str:
"""Docstring becomes the tool description."""
...Error Handling
错误处理
Return errors as strings, don't raise exceptions:
python
@mcp.tool()
async def get_data(id: str) -> str:
try:
result = await fetch_data(id)
return json.dumps(result)
except NotFoundError:
return f"Error: No data found for ID {id}"将错误以字符串形式返回,不要抛出异常:
python
@mcp.tool()
async def get_data(id: str) -> str:
try:
result = await fetch_data(id)
return json.dumps(result)
except NotFoundError:
return f"Error: No data found for ID {id}"Asset Files
资源文件
- — Minimal FastMCP server template
assets/basic-server.py - — Server with storage and middleware
assets/self-contained-server.py - — Tool patterns and type annotations
assets/tools-examples.py - — Resource URI patterns
assets/resources-examples.py - — Prompt template patterns
assets/prompts-examples.py - — MCP client usage
assets/client-example.py - — CLI companion docs template
assets/SCRIPTS-TEMPLATE.md - — TypeScript CLI script template
assets/script-template.ts
- — 最小化FastMCP服务器模板
assets/basic-server.py - — 包含存储和中间件的服务器模板
assets/self-contained-server.py - — 工具模式与类型注解示例
assets/tools-examples.py - — 资源URI模式示例
assets/resources-examples.py - — 提示词模板模式示例
assets/prompts-examples.py - — MCP客户端使用示例
assets/client-example.py - — CLI配套文档模板
assets/SCRIPTS-TEMPLATE.md - — TypeScript CLI脚本模板
assets/script-template.ts
Reference Files
参考文件
- — 30+ documented errors with fixes
references/common-errors.md - — FastMCP CLI reference
references/cli-commands.md - — Deployment patterns (Cloud, Docker, Workers)
references/cloud-deployment.md - — Auth, middleware, storage backends
references/production-patterns.md - — FastAPI mount, OpenAPI import
references/integration-patterns.md - — Lifespan, dependency injection
references/context-features.md
- — 30+个带修复方案的已记录错误
references/common-errors.md - — FastMCP CLI参考文档
references/cli-commands.md - — 部署模式(Cloud、Docker、Workers)
references/cloud-deployment.md - — 认证、中间件、存储后端
references/production-patterns.md - — FastAPI挂载、OpenAPI导入
references/integration-patterns.md - — 生命周期、依赖注入
references/context-features.md