---
name: mcp-server-builder
description: Use when building an MCP server so an LLM can use an external API or service: TypeScript or Python, tool design, testing, and evaluations.
---
# MCP Server Builder
## What this does
Guides you through building a high-quality MCP (Model Context Protocol) server that lets an LLM interact with an external service through well-designed tools. Quality is measured by how well the server helps an LLM complete real-world tasks.
## When to use
Use when integrating an external API or service via MCP, in Python (FastMCP) or Node/TypeScript (MCP SDK).
## How to run it
### Phase 1: Research and planning
1. Design principles:
- Balance full API coverage with workflow tools. When unsure, prioritize comprehensive API coverage.
- Use clear, consistent, action-oriented tool names with a prefix (e.g. `github_create_issue`, `github_list_repos`).
- Keep tool descriptions concise; support filtering and pagination; return focused data.
- Write error messages that guide the agent toward a fix with specific next steps.
2. Read the MCP spec. Start from `https://modelcontextprotocol.io/sitemap.xml`, then fetch specific pages with a `.md` suffix. Review the overview, transports (streamable HTTP, stdio), and tool/resource/prompt definitions.
3. Pick the stack. TypeScript is recommended. Use streamable HTTP (stateless JSON) for remote servers and stdio for local ones.
- TypeScript SDK has two versions: v2 (`@modelcontextprotocol/server`, current stable, use for new servers) and v1 (`@modelcontextprotocol/sdk`, bug and security fixes only). Use v1 only if the project's `package.json` already depends on it, and tell the user once that `npx @modelcontextprotocol/codemod@latest v1-to-v2 .` migrates it. Don't mix the two.
- Fetch the SDK README: TypeScript `https://raw.githubusercontent.com/modelcontextprotocol/typescript-sdk/main/README.md`; Python `https://raw.githubusercontent.com/modelcontextprotocol/python-sdk/main/README.md`.
4. Review the target service's API docs: endpoints, authentication, data models. List the endpoints to implement, starting with the most common.
### Phase 2: Implementation
1. Set up the project structure for the chosen language.
2. Build shared infrastructure: authenticated API client, error handling helpers, response formatting (JSON/Markdown), pagination.
3. For each tool:
- Input schema with Zod (TypeScript) or Pydantic (Python), with constraints, clear descriptions, and examples in field descriptions.
- Define `outputSchema` where possible and return `structuredContent` alongside text.
- Concise description covering functionality, parameters, and return type.
- Async I/O, actionable errors, pagination where applicable.
- Annotations: `readOnlyHint`, `destructiveHint`, `idempotentHint`, `openWorldHint`.
### Phase 3: Review and test
- Check for duplicated code, consistent error handling, full type coverage, and clear tool descriptions.
- TypeScript: `npm run build`. Python: `python -m py_compile your_server.py`.
- Test with MCP Inspector: `npx @modelcontextprotocol/inspector`.
### Phase 4: Evaluations
Create 10 questions to test whether an LLM can use the server. Use only read-only exploration of the data. Each question must be independent, read-only, complex (multiple tool calls), realistic, verifiable by string comparison with a single answer, and stable over time. Solve each yourself to verify the answer. Write them as XML:
xml
<evaluation>
<qa_pair>
<question>Find discussions about AI model launches with animal codenames. One model needed a specific safety designation that uses the format ASL-X. What number X was being determined for the model named after a spotted wild cat?</question>
<answer>3</answer>
</qa_pair>
</evaluation>
## Output
A working MCP server project (TypeScript or Python) that builds and passes Inspector testing, plus an XML file of 10 evaluation Q&A pairs. Note any assumptions, such as SDK version choice.
## Credit
Based on public content by anthropics, packaged by Orbit.