MCP Builder
Purpose: Scaffold production-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Produces a complete project structure with tool definitions, transport wiring, handler implementations, input validation, error handling, and an evaluation test harness.
I. When to Use
- Starting a new MCP server to integrate an external API or service
- Adding MCP tool access to an existing service
- Need a working scaffold with transport, validation, and tests from the start
- Building for either Python (FastMCP) or TypeScript (MCP SDK) targets
II. Agent-Centric Design Principles
MCP tools are used by AI agents, not humans. Design accordingly:
- Build for workflows, not API endpoints -- consolidate related operations (e.g.,
schedule_event that checks availability AND creates the event)
- Optimize for limited context -- return high-signal information, not exhaustive data dumps; offer concise vs. detailed response formats
- Actionable error messages -- errors should guide agents toward correct usage ("Try filter='active_only' to reduce results")
- Natural task subdivisions -- tool names reflect how humans think about tasks, with consistent prefixes for discoverability
- Evaluation-driven development -- create realistic eval scenarios early; let agent feedback drive tool improvements
III. Workflow
Phase 1: Research and Planning
- Study the target API -- read all available documentation (endpoints, auth, rate limits, pagination, error codes, data models)
- Select high-value tools -- prioritize operations that enable complete workflows, not just individual API calls
- Plan shared utilities -- identify common patterns (API request helpers, pagination, error formatting, auth token management)
- Design input/output schemas -- Pydantic models for Python, Zod schemas for TypeScript; include constraints and descriptive field docs
Phase 2: Scaffold Generation
For each target language, generate the project structure:
Python (FastMCP):
{server_name}/
server.py # MCP server with @mcp.tool registrations
models.py # Pydantic input validation models
utils.py # Shared API request helpers, error formatting
requirements.txt # Dependencies (mcp, pydantic, httpx)
tests/
test_tools.py # Unit tests for each tool handler
eval.xml # Evaluation questions for agent testing
TypeScript (MCP SDK):
{server_name}/
src/
index.ts # MCP server with registerTool calls
schemas.ts # Zod input validation schemas
utils.ts # Shared helpers
package.json
tsconfig.json
tests/
tools.test.ts # Unit tests
eval.xml # Evaluation questions
Phase 3: Tool Implementation
For each tool in the tools list:
- Define input schema with proper constraints (min/max length, regex, ranges) and descriptive field docs with examples
- Write comprehensive docstring -- one-line summary, detailed purpose, parameter types with examples, return schema, usage examples
- Implement handler using shared utilities, async/await for I/O, proper error handling, response format options (JSON/Markdown)
- Add tool annotations --
readOnlyHint, destructiveHint, idempotentHint, openWorldHint
Phase 4: Transport Wiring
Configure the selected transport:
- stdio (default): reads from stdin, writes to stdout; suitable for CLI tool integration and local development
- sse: HTTP server with Server-Sent Events; suitable for remote deployment and multi-client scenarios
Phase 5: Test Harness
- Unit tests for each tool handler with mocked API responses
- Build verification --
python -m py_compile server.py or npm run build
- Evaluation harness -- 10 realistic questions that test whether an agent can accomplish real tasks using the tools
IV. Quality Checklist
V. Output
- Complete MCP server project scaffold at the specified location
- Contents: project structure, tool handler implementations, input validation schemas, shared utilities, transport configuration, test suite, evaluation harness
- Ready to run:
python server.py (Python) or npm run build && node dist/index.js (TypeScript)
VI. Examples
Scenario 1: "Build an MCP server for the GitHub API" with tools=[list_repos, search_code, get_pull_request, create_issue] and transport=stdio --> Python scaffold with 4 tool handlers, Pydantic models for each input, shared GitHub API client with auth token management, pagination helper, Markdown response formatter, 10 eval questions testing real GitHub workflows.
Scenario 2: "Scaffold an MCP server for our internal inventory API" with server_name=inventory-mcp and transport=sse --> TypeScript scaffold with SSE transport, Zod schemas, placeholder tool stubs ready for implementation, HTTP server configuration, CORS setup for remote access.
Scenario 3: "Create an MCP server that wraps our Postgres database" with tools=[query, list_tables, describe_table] --> Python scaffold with read-only tool annotations, SQL injection prevention in input validation, result truncation at 25K characters, connection pooling in shared utilities.
VII. Edge Cases
- No tools specified: generate a minimal scaffold with one example tool (
hello_world) as a template; include comments showing how to add more
- Target API requires OAuth flow: scaffold includes token refresh logic in shared utilities; document the manual auth setup step in README
- Server needs both stdio and SSE: scaffold both transport configurations; use environment variable to select at runtime
- Very large API surface (50+ endpoints): do not scaffold all 50; select the 8-12 highest-value workflow tools and document the rest as future additions
VIII. Anti-Patterns
- Wrapping every API endpoint as a separate tool -- consolidate into workflow-level tools that complete tasks, not individual HTTP calls
- Returning raw API responses without formatting -- agents have limited context; parse and summarize responses
- Skipping input validation -- unvalidated inputs produce cryptic API errors that agents cannot recover from
- Testing by running the server directly in the main process -- MCP servers block on stdin; use the evaluation harness or run in tmux
- Hardcoding API keys in the scaffold -- use environment variables; never commit credentials
IX. Related Skills
hooks-reference -- after building the server, use this skill to wire PostToolUse hooks that observe or validate MCP tool calls in live sessions
tool-intercept-logger -- instrument MCP tool calls with OTEL-compatible logging once the server is running in production
build-sweep -- if the MCP server is part of a Go workspace, use build-sweep to keep it green alongside other modules
1---2name: mcp-builder3description: Scaffolds new MCP servers with tool definitions, transport wiring, handler structure, and test harness for Python (FastMCP) or TypeScript (MCP SDK). Use when: 'build a new MCP server', 'scaffold an MCP integration', 'create tools for an external API', 'set up MCP transport and handlers'.4---56# MCP Builder78**Purpose:** Scaffold production-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Produces a complete project structure with tool definitions, transport wiring, handler implementations, input validation, error handling, and an evaluation test harness.910---1112## I. When to Use1314- Starting a new MCP server to integrate an external API or service15- Adding MCP tool access to an existing service16- Need a working scaffold with transport, validation, and tests from the start17- Building for either Python (FastMCP) or TypeScript (MCP SDK) targets1819---2021## II. Agent-Centric Design Principles2223MCP tools are used by AI agents, not humans. Design accordingly:24251. **Build for workflows, not API endpoints** -- consolidate related operations (e.g., `schedule_event` that checks availability AND creates the event)262. **Optimize for limited context** -- return high-signal information, not exhaustive data dumps; offer concise vs. detailed response formats273. **Actionable error messages** -- errors should guide agents toward correct usage ("Try filter='active_only' to reduce results")284. **Natural task subdivisions** -- tool names reflect how humans think about tasks, with consistent prefixes for discoverability295. **Evaluation-driven development** -- create realistic eval scenarios early; let agent feedback drive tool improvements3031---3233## III. Workflow3435### Phase 1: Research and Planning36371. **Study the target API** -- read all available documentation (endpoints, auth, rate limits, pagination, error codes, data models)382. **Select high-value tools** -- prioritize operations that enable complete workflows, not just individual API calls393. **Plan shared utilities** -- identify common patterns (API request helpers, pagination, error formatting, auth token management)404. **Design input/output schemas** -- Pydantic models for Python, Zod schemas for TypeScript; include constraints and descriptive field docs4142### Phase 2: Scaffold Generation4344For each target language, generate the project structure:4546**Python (FastMCP):**47```48{server_name}/49 server.py # MCP server with @mcp.tool registrations50 models.py # Pydantic input validation models51 utils.py # Shared API request helpers, error formatting52 requirements.txt # Dependencies (mcp, pydantic, httpx)53 tests/54 test_tools.py # Unit tests for each tool handler55 eval.xml # Evaluation questions for agent testing56```5758**TypeScript (MCP SDK):**59```60{server_name}/61 src/62 index.ts # MCP server with registerTool calls63 schemas.ts # Zod input validation schemas64 utils.ts # Shared helpers65 package.json66 tsconfig.json67 tests/68 tools.test.ts # Unit tests69 eval.xml # Evaluation questions70```7172### Phase 3: Tool Implementation7374For each tool in the tools list:75761. **Define input schema** with proper constraints (min/max length, regex, ranges) and descriptive field docs with examples772. **Write comprehensive docstring** -- one-line summary, detailed purpose, parameter types with examples, return schema, usage examples783. **Implement handler** using shared utilities, async/await for I/O, proper error handling, response format options (JSON/Markdown)794. **Add tool annotations** -- `readOnlyHint`, `destructiveHint`, `idempotentHint`, `openWorldHint`8081### Phase 4: Transport Wiring8283Configure the selected transport:8485- **stdio** (default): reads from stdin, writes to stdout; suitable for CLI tool integration and local development86- **sse**: HTTP server with Server-Sent Events; suitable for remote deployment and multi-client scenarios8788### Phase 5: Test Harness89901. **Unit tests** for each tool handler with mocked API responses912. **Build verification** -- `python -m py_compile server.py` or `npm run build`923. **Evaluation harness** -- 10 realistic questions that test whether an agent can accomplish real tasks using the tools9394---9596## IV. Quality Checklist9798- [ ] Every tool has a comprehensive docstring with examples99- [ ] Input validation catches malformed requests with actionable error messages100- [ ] No duplicated code between tool handlers (shared utilities extracted)101- [ ] Pagination is handled (not left to the caller)102- [ ] Character/token limits respected (truncation at 25,000 characters)103- [ ] All external calls have error handling with retry for transient failures104- [ ] Tool annotations set correctly (readOnly, destructive, idempotent, openWorld)105- [ ] Transport configured and tested (stdio or sse)106- [ ] Build passes without errors107- [ ] Evaluation harness with 10 questions created108109---110111## V. Output112113- Complete MCP server project scaffold at the specified location114- Contents: project structure, tool handler implementations, input validation schemas, shared utilities, transport configuration, test suite, evaluation harness115- Ready to run: `python server.py` (Python) or `npm run build && node dist/index.js` (TypeScript)116117---118119## VI. Examples120121**Scenario 1:** "Build an MCP server for the GitHub API" with tools=[list_repos, search_code, get_pull_request, create_issue] and transport=stdio --> Python scaffold with 4 tool handlers, Pydantic models for each input, shared GitHub API client with auth token management, pagination helper, Markdown response formatter, 10 eval questions testing real GitHub workflows.122123**Scenario 2:** "Scaffold an MCP server for our internal inventory API" with server_name=inventory-mcp and transport=sse --> TypeScript scaffold with SSE transport, Zod schemas, placeholder tool stubs ready for implementation, HTTP server configuration, CORS setup for remote access.124125**Scenario 3:** "Create an MCP server that wraps our Postgres database" with tools=[query, list_tables, describe_table] --> Python scaffold with read-only tool annotations, SQL injection prevention in input validation, result truncation at 25K characters, connection pooling in shared utilities.126127---128129## VII. Edge Cases130131- No tools specified: generate a minimal scaffold with one example tool (`hello_world`) as a template; include comments showing how to add more132- Target API requires OAuth flow: scaffold includes token refresh logic in shared utilities; document the manual auth setup step in README133- Server needs both stdio and SSE: scaffold both transport configurations; use environment variable to select at runtime134- Very large API surface (50+ endpoints): do not scaffold all 50; select the 8-12 highest-value workflow tools and document the rest as future additions135136---137138## VIII. Anti-Patterns139140- Wrapping every API endpoint as a separate tool -- consolidate into workflow-level tools that complete tasks, not individual HTTP calls141- Returning raw API responses without formatting -- agents have limited context; parse and summarize responses142- Skipping input validation -- unvalidated inputs produce cryptic API errors that agents cannot recover from143- Testing by running the server directly in the main process -- MCP servers block on stdin; use the evaluation harness or run in tmux144- Hardcoding API keys in the scaffold -- use environment variables; never commit credentials145146---147148## IX. Related Skills149150- `hooks-reference` -- after building the server, use this skill to wire PostToolUse hooks that observe or validate MCP tool calls in live sessions151- `tool-intercept-logger` -- instrument MCP tool calls with OTEL-compatible logging once the server is running in production152- `build-sweep` -- if the MCP server is part of a Go workspace, use build-sweep to keep it green alongside other modules