MCP Server Builder
Tier: POWERFUL
Category: Engineering
Domain: AI / API Integration
Overview
Use this skill to design and ship production-ready MCP servers from API contracts instead of hand-written one-off tool wrappers. It focuses on fast scaffolding, schema quality, validation, and safe evolution.
The workflow supports both Python and TypeScript MCP implementations and treats OpenAPI as the source of truth.
Core Capabilities
- - Convert OpenAPI paths/operations into MCP tool definitions
- Generate starter server scaffolds (Python or TypeScript)
- Enforce naming, descriptions, and schema consistency
- Validate MCP tool manifests for common production failures
- Apply versioning and backward-compatibility checks
- Separate transport/runtime decisions from tool contract design
When to Use
- - You need to expose an internal/external REST API to an LLM agent
- You are replacing brittle browser automation with typed tools
- You want one MCP server shared across teams and assistants
- You need repeatable quality checks before publishing MCP tools
- You want to bootstrap an MCP server from existing OpenAPI specs
Key Workflows
1. OpenAPI to MCP Scaffold
- 1. Start from a valid OpenAPI spec.
- Generate tool manifest + starter server code.
- Review naming and auth strategy.
- Add endpoint-specific runtime logic.
CODEBLOCK0
Supports stdin as well:
CODEBLOCK1
2. Validate MCP Tool Definitions
Run validator before integration tests:
CODEBLOCK2
Checks include duplicate names, invalid schema shape, missing descriptions, empty required fields, and naming hygiene.
3. Runtime Selection
- - Choose Python for fast iteration and data-heavy backends.
- Choose TypeScript for unified JS stacks and tighter frontend/backend contract reuse.
- Keep tool contracts stable even if transport/runtime changes.
4. Auth & Safety Design
- - Keep secrets in env, not in tool schemas.
- Prefer explicit allowlists for outbound hosts.
- Return structured errors (
code, message, details) for agent recovery. - Avoid destructive operations without explicit confirmation inputs.
5. Versioning Strategy
- - Additive fields only for non-breaking updates.
- Never rename tool names in-place.
- Introduce new tool IDs for breaking behavior changes.
- Maintain changelog of tool contracts per release.
Script Interfaces
- Reads OpenAPI from stdin or
--input
- Produces manifest + server scaffold
- Emits JSON summary or text report
- Validates manifests and optional runtime config
- Returns non-zero exit in strict mode when errors exist
Common Pitfalls
- 1. Tool names derived directly from raw paths (
get__v1__users___id) - Missing operation descriptions (agents choose tools poorly)
- Ambiguous parameter schemas with no required fields
- Mixing transport errors and domain errors in one opaque message
- Building tool contracts that expose secret values
- Breaking clients by changing schema keys without versioning
Best Practices
- 1. Use
operationId as canonical tool name when available. - Keep one task intent per tool; avoid mega-tools.
- Add concise descriptions with action verbs.
- Validate contracts in CI using strict mode.
- Keep generated scaffold committed, then customize incrementally.
- Pair contract changes with changelog entries.
Reference Material
Architecture Decisions
Choose the server approach per constraint:
- - Python runtime: faster iteration, data pipelines, backend-heavy teams
- TypeScript runtime: shared types with JS stack, frontend-heavy teams
- Single MCP server: easiest operations, broader blast radius
- Split domain servers: cleaner ownership and safer change boundaries
Contract Quality Gates
Before publishing a manifest:
- 1. Every tool has clear verb-first name.
- Every tool description explains intent and expected result.
- Every required field is explicitly typed.
- Destructive actions include confirmation parameters.
- Error payload format is consistent across all tools.
- Validator returns zero errors in strict mode.
Testing Strategy
- - Unit: validate transformation from OpenAPI operation to MCP tool schema.
- Contract: snapshot
tool_manifest.json and review diffs in PR. - Integration: call generated tool handlers against staging API.
- Resilience: simulate 4xx/5xx upstream errors and verify structured responses.
Deployment Practices
- - Pin MCP runtime dependencies per environment.
- Roll out server updates behind versioned endpoint/process.
- Keep backward compatibility for one release window minimum.
- Add changelog notes for new/removed/changed tool contracts.
Security Controls
- - Keep outbound host allowlist explicit.
- Do not proxy arbitrary URLs from user-provided input.
- Redact secrets and auth headers from logs.
- Rate-limit high-cost tools and add request timeouts.
MCP 服务器构建器
层级: 强大
类别: 工程
领域: AI / API 集成
概述
使用此技能,从 API 契约设计和交付生产级 MCP 服务器,而非手动编写一次性工具包装器。它专注于快速脚手架搭建、模式质量、验证和安全演进。
该工作流支持 Python 和 TypeScript 两种 MCP 实现,并将 OpenAPI 视为事实来源。
核心能力
- - 将 OpenAPI 路径/操作转换为 MCP 工具定义
- 生成入门级服务器脚手架(Python 或 TypeScript)
- 强制执行命名、描述和模式一致性
- 验证 MCP 工具清单以防范常见生产故障
- 应用版本控制和向后兼容性检查
- 将传输/运行时决策与工具契约设计分离
使用场景
- - 需要将内部/外部 REST API 暴露给 LLM 代理
- 正在用类型化工具替换脆弱的浏览器自动化
- 希望一个 MCP 服务器在团队和助手之间共享
- 在发布 MCP 工具前需要可重复的质量检查
- 希望从现有 OpenAPI 规范引导 MCP 服务器
关键工作流
1. OpenAPI 到 MCP 脚手架
- 1. 从有效的 OpenAPI 规范开始。
- 生成工具清单 + 入门级服务器代码。
- 审查命名和认证策略。
- 添加端点特定的运行时逻辑。
bash
python3 scripts/openapitomcp.py \
--input openapi.json \
--server-name billing-mcp \
--language python \
--output-dir ./out \
--format text
也支持标准输入:
bash
cat openapi.json | python3 scripts/openapitomcp.py --server-name billing-mcp --language typescript
2. 验证 MCP 工具定义
在集成测试前运行验证器:
bash
python3 scripts/mcpvalidator.py --input out/toolmanifest.json --strict --format text
检查内容包括重复名称、无效模式形状、缺失描述、空必填字段和命名规范。
3. 运行时选择
- - 选择 Python 用于快速迭代和数据密集型后端。
- 选择 TypeScript 用于统一 JS 栈和更紧密的前端/后端契约复用。
- 即使传输/运行时发生变化,也要保持工具契约稳定。
4. 认证与安全设计
- - 将密钥保存在环境变量中,而非工具模式中。
- 优先为出站主机使用显式白名单。
- 返回结构化错误(code、message、details)以便代理恢复。
- 避免没有明确确认输入的破坏性操作。
5. 版本控制策略
- - 仅对非破坏性更新使用新增字段。
- 切勿原地重命名工具名称。
- 对破坏性行为变更引入新的工具 ID。
- 为每个版本维护工具契约的变更日志。
脚本接口
- - python3 scripts/openapitomcp.py --help
- 从标准输入或 --input 读取 OpenAPI
- 生成清单 + 服务器脚手架
- 输出 JSON 摘要或文本报告
- - python3 scripts/mcp_validator.py --help
- 验证清单和可选的运行时配置
- 严格模式下存在错误时返回非零退出码
常见陷阱
- 1. 直接从原始路径派生的工具名称(getv1users_id)
- 缺少操作描述(代理选择工具不当)
- 没有必填字段的模糊参数模式
- 将传输错误和领域错误混合在一个不透明的消息中
- 构建暴露密钥值的工具契约
- 在不进行版本控制的情况下更改模式键来破坏客户端
最佳实践
- 1. 尽可能使用 operationId 作为规范工具名称。
- 每个工具保持单一任务意图;避免巨型工具。
- 使用动作动词添加简洁描述。
- 在 CI 中使用严格模式验证契约。
- 提交生成的脚手架,然后逐步定制。
- 将契约变更与变更日志条目配对。
参考资料
架构决策
根据约束条件选择服务器方法:
- - Python 运行时:更快的迭代、数据管道、后端密集型团队
- TypeScript 运行时:与 JS 栈共享类型、前端密集型团队
- 单一 MCP 服务器:最简单的运维、更大的影响范围
- 拆分领域服务器:更清晰的职责归属和更安全的变更边界
契约质量门禁
在发布清单之前:
- 1. 每个工具都有清晰的动词优先名称。
- 每个工具描述都解释意图和预期结果。
- 每个必填字段都明确类型化。
- 破坏性操作包含确认参数。
- 所有工具的错误负载格式保持一致。
- 验证器在严格模式下返回零错误。
测试策略
- - 单元测试:验证从 OpenAPI 操作到 MCP 工具模式的转换。
- 契约测试:快照 tool_manifest.json 并在 PR 中审查差异。
- 集成测试:针对预发布 API 调用生成的工具处理器。
- 弹性测试:模拟 4xx/5xx 上游错误并验证结构化响应。
部署实践
- - 按环境锁定 MCP 运行时依赖。
- 在版本化端点/进程后面推出服务器更新。
- 至少保持一个发布窗口的向后兼容性。
- 为新增/移除/更改的工具契约添加变更日志说明。
安全控制
- - 保持出站主机白名单显式。
- 不要代理用户输入中的任意 URL。
- 从日志中编辑密钥和认证头。
- 对高成本工具进行速率限制并添加请求超时。