--- name: mcp-builder description: Guides building a working Model Context Protocol (MCP) server that exposes an API, database or internal tool to an AI assistant, from scoping the tools through implementation, testing and a written evaluation set. Use when a user says "build an MCP server for...", "let the assistant talk to our API", "wrap this database as tools", or "my MCP server is returning bad results". --- # MCP Server Builder Builds a Model Context Protocol server that an assistant can use reliably. A server that compiles is not finished; a server whose tools an assistant can pick correctly, and recover from errors with, is finished. ## When to use this - The user wants an assistant to read from or act on a system it cannot reach today: a REST API, a database, a file store, an internal service. - An existing server works but the assistant misuses its tools, times out, or gets confusing errors. - Do not use when a one-off script or a plain API call would do. MCP earns its cost when the capability will be reused. ## Procedure 1. **Scope with the user.** Ask: what system, what 3 to 8 tasks should the assistant accomplish, read-only or read and write, how authentication works, and which language (default to TypeScript with the official SDK, or Python with a high-level server library, whichever the user already uses). Get a sample of real API responses or a schema if possible. 2. **Design tools around tasks, not endpoints.** One tool per user-level job ("find_overdue_invoices"), not one per REST route. Give each a verb-first snake_case name, a description that says when to use it and when not to, and typed inputs with plain-language descriptions and defaults. Merge calls that are always made together. 3. **Keep outputs small and useful.** Return only the fields a person would need, add pagination (limit plus cursor) for any list, and offer a concise and a detailed mode where records are large. Include human-readable names beside IDs. 4. **Write errors the assistant can act on.** Every failure returns a message stating what went wrong and what to try next ("No customer with id 42. Use search_customers to find the id."). Validate inputs before calling the backend. Never return raw stack traces or secrets. 5. **Implement.** Read credentials from environment variables, never from source. Use the SDK's schema validation. Add timeouts and one retry for transient failures. Mark read-only tools as such, and for destructive tools require an explicit confirmation argument. Choose stdio transport for local use, HTTP for shared use. 6. **Test in layers.** First run each tool directly with good and bad inputs and read the output as the assistant would. Then connect the server to a real assistant client and ask natural-language questions. Fix descriptions and output shape when the wrong tool is picked; that is usually a naming or description problem. 7. **Write an evaluation set.** Produce ten questions that need two or more tool calls each, have a single verifiable answer, and are stable over time (avoid "latest" or "today"). Store question and expected answer in a file next to the server, run them, and record which pass. 8. **Document.** A short README with install steps, required environment variables, the tool list, and example prompts. ## Output format Deliver: the server source, the README, the evaluation file, and a closing summary: ``` Server: (, ) Tools: (read-only | writes) Auth: Evaluation: /10 passing - Known limits: ``` ## Guardrails - Do not guess API behavior. If a response shape is unknown, call the API or ask for a sample. - Never log or echo credentials. Do not commit secrets or example keys. - Default to least privilege: read-only credentials unless writes were requested. - Do not claim the evaluation passes without running it. - Tell the user plainly about anything left untested, such as write paths against a production system. - Keep the tool count small. If the list grows past about fifteen, group or remove tools; assistants choose worse as the menu grows. - Pin dependency versions and note the protocol SDK version used, so the server can be rebuilt later. - Rate-limit outbound calls to the backend so a looping assistant cannot flood it. - Ask before connecting to any production system, and say which environment each test ran against. - If the user's goal is better served by an existing server, say so before building a new one.