Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Guides creation of high-quality MCP servers in TypeScript or Python (FastMCP) to connect LLMs with external services.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
SKILL.md
1---2name: mcp-builder3description: Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).4license: Complete terms in LICENSE.txt5---67# MCP Server Development Guide89## Overview1011Create MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. The quality of an MCP server is measured by how well it enables LLMs to accomplish real-world tasks.1213---1415# Process1617## π High-Level Workflow1819Creating a high-quality MCP server involves four main phases:2021### Phase 1: Deep Research and Planning2223#### 1.1 Understand Modern MCP Design2425**API Coverage vs. Workflow Tools:**26Balance comprehensive API endpoint coverage with specialized workflow tools. Workflow tools can be more convenient for specific tasks, while comprehensive coverage gives agents flexibility to compose operations. Performance varies by clientβsome clients benefit from code execution that combines basic tools, while others work better with higher-level workflows. When uncertain, prioritize comprehensive API coverage.2728**Tool Naming and Discoverability:**29Clear, descriptive tool names help agents find the right tools quickly. Use consistent prefixes (e.g., `github_create_issue`, `github_list_repos`) and action-oriented naming.3031**Context Management:**32Agents benefit from concise tool descriptions and the ability to filter/paginate results. Design tools that return focused, relevant data. Some clients support code execution which can help agents filter and process data efficiently.3334**Actionable Error Messages:**35Error messages should guide agents toward solutions with specific suggestions and next steps.3637#### 1.2 Study MCP Protocol Documentation3839**Navigate the MCP specification:**4041Start with the sitemap to find relevant pages: `https://modelcontextprotocol.io/sitemap.xml`4243Then fetch specific pages with `.md` suffix for markdown format (e.g., `https://modelcontextprotocol.io/specification/draft.md`).4445Key pages to review:46- Specification overview and architecture47- Transport mechanisms (streamable HTTP, stdio)48- Tool, resource, and prompt definitions4950#### 1.3 Study Framework Documentation5152**Recommended stack:**53- **Language**: TypeScript (high-quality SDK support and good compatibility in many execution environments e.g. MCPB. Plus AI models are good at generating TypeScript code, benefiting from its broad usage, static typing and good linting tools)54- **Transport**: Streamable HTTP for remote servers, using stateless JSON (simpler to scale and maintain, as opposed to stateful sessions and streaming responses). stdio for local servers.5556**Load framework documentation:**5758- **MCP Best Practices**: [π View Best Practices](./reference/mcp_best_practices.md) - Core guidelines5960**For TypeScript (recommended):**61- **TypeScript SDK**: Use WebFetch to load `https://raw.githubusercontent.com/modelcontextprotocol/typescript-sdk/main/README.md`62- [β‘ TypeScript Guide](./reference/node_mcp_server.md) - TypeScript patterns and examples6364**For Python:**65- **Python SDK**: Use WebFetch to load `https://raw.githubusercontent.com/modelcontextprotocol/python-sdk/main/README.md`66- [π Python Guide](./reference/python_mcp_server.md) - Python patterns and examples6768#### 1.4 Plan Your Implementation6970**Understand the API:**71Review the service's API documentation to identify key endpoints, authentication requirements, and data models. Use web search and WebFetch as needed.7273**Tool Selection:**74Prioritize comprehensive API coverage. List endpoints to implement, starting with the most common operations.7576---7778### Phase 2: Implementation7980#### 2.1 Set Up Project Structure8182See language-specific guides for project setup:83- [β‘ TypeScript Guide](./reference/node_mcp_server.md) - Project structure, package.json, tsconfig.json84- [π Python Guide](./reference/python_mcp_server.md) - Module organization, dependencies8586#### 2.2 Implement Core Infrastructure8788Create shared utilities:89- API client with authentication90- Error handling helpers91- Response formatting (JSON/Markdown)92- Pagination support9394#### 2.3 Implement Tools9596For each tool:9798**Input Schema:**99- Use Zod (TypeScript) or Pydantic (Python)100- Include constraints and clear descriptions101- Add examples in field descriptions102103**Output Schema:**104- Define `outputSchema` where possible for structured data105- Use `structuredContent` in tool responses (TypeScript SDK feature)106- Helps clients understand and process tool outputs107108**Tool Description:**109- Concise summary of functionality110- Parameter descriptions111- Return type schema112113**Implementation:**114- Async/await for I/O operations115- Proper error handling with actionable messages116- Support pagination where applicable117- Return both text content and structured data when using modern SDKs118119**Annotations:**120- `readOnlyHint`: true/false121- `destructiveHint`: true/false122- `idempotentHint`: true/false123- `openWorldHint`: true/false124125---126127### Phase 3: Review and Test128129#### 3.1 Code Quality130131Review for:132- No duplicated code (DRY principle)133- Consistent error handling134- Full type coverage135- Clear tool descriptions136137#### 3.2 Build and Test138139**TypeScript:**140- Run `npm run build` to verify compilation141- Test with MCP Inspector: `npx @modelcontextprotocol/inspector`142143**Python:**144- Verify syntax: `python -m py_compile your_server.py`145- Test with MCP Inspector146147See language-specific guides for detailed testing approaches and quality checklists.148149---150151### Phase 4: Create Evaluations152153After implementing your MCP server, create comprehensive evaluations to test its effectiveness.154155**Load [β Evaluation Guide](./reference/evaluation.md) for complete evaluation guidelines.**156157#### 4.1 Understand Evaluation Purpose158159Use evaluations to test whether LLMs can effectively use your MCP server to answer realistic, complex questions.160161#### 4.2 Create 10 Evaluation Questions162163To create effective evaluations, follow the process outlined in the evaluation guide:1641651. **Tool Inspection**: List available tools and understand their capabilities1662. **Content Exploration**: Use READ-ONLY operations to explore available data1673. **Question Generation**: Create 10 complex, realistic questions1684. **Answer Verification**: Solve each question yourself to verify answers169170#### 4.3 Evaluation Requirements171172Ensure each question is:173- **Independent**: Not dependent on other questions174- **Read-only**: Only non-destructive operations required175- **Complex**: Requiring multiple tool calls and deep exploration176- **Realistic**: Based on real use cases humans would care about177- **Verifiable**: Single, clear answer that can be verified by string comparison178- **Stable**: Answer won't change over time179180#### 4.4 Output Format181182Create an XML file with this structure:183184```xml185<evaluation>186<qa_pair>187<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>188<answer>3</answer>189</qa_pair>190<!-- More qa_pairs... -->191</evaluation>192```193194---195196# Reference Files197198## π Documentation Library199200Load these resources as needed during development:201202### Core MCP Documentation (Load First)203- **MCP Protocol**: Start with sitemap at `https://modelcontextprotocol.io/sitemap.xml`, then fetch specific pages with `.md` suffix204- [π MCP Best Practices](./reference/mcp_best_practices.md) - Universal MCP guidelines including:205- Server and tool naming conventions206- Response format guidelines (JSON vs Markdown)207- Pagination best practices208- Transport selection (streamable HTTP vs stdio)209- Security and error handling standards210211### SDK Documentation (Load During Phase 1/2)212- **Python SDK**: Fetch from `https://raw.githubusercontent.com/modelcontextprotocol/python-sdk/main/README.md`213- **TypeScript SDK**: Fetch from `https://raw.githubusercontent.com/modelcontextprotocol/typescript-sdk/main/README.md`214215### Language-Specific Implementation Guides (Load During Phase 2)216- [π Python Implementation Guide](./reference/python_mcp_server.md) - Complete Python/FastMCP guide with:217- Server initialization patterns218- Pydantic model examples219- Tool registration with `@mcp.tool`220- Complete working examples221- Quality checklist222223- [β‘ TypeScript Implementation Guide](./reference/node_mcp_server.md) - Complete TypeScript guide with:224- Project structure225- Zod schema patterns226- Tool registration with `server.registerTool`227- Complete working examples228- Quality checklist229230### Evaluation Guide (Load During Phase 4)231- [β Evaluation Guide](./reference/evaluation.md) - Complete evaluation creation guide with:232- Question creation guidelines233- Answer verification strategies234- XML format specifications235- Example questions and answers236- Running an evaluation with the provided scripts237