$curl -o .claude/agents/mcp-builder.md https://raw.githubusercontent.com/Rune-kit/rune/HEAD/agents/mcp-builder.mdBuild MCP servers from specs — generates tool definitions, resource handlers, test suites. Supports TypeScript (official SDK) and Python (FastMCP). Multi-provider adapter pattern.
| 1 | # mcp-builder |
| 2 | |
| 3 | ## Purpose |
| 4 | |
| 5 | MCP server builder. Generates complete, tested MCP servers from a natural language description or specification. Handles tool definitions, resource handlers, input validation, error handling, configuration, tests, and documentation. Supports TypeScript (official SDK) and Python (FastMCP). |
| 6 | |
| 7 | ## Triggers |
| 8 | |
| 9 | - Called by `cook` when MCP-related task detected (keywords: "MCP server", "MCP tool", "model context protocol") |
| 10 | - Called by `scaffold` when MCP Server template selected |
| 11 | - `/rune mcp-builder <description>` — manual invocation |
| 12 | - Auto-trigger: when project contains `mcp.json`, `@modelcontextprotocol/sdk`, or `fastmcp` in dependencies |
| 13 | |
| 14 | ## Calls (outbound) |
| 15 | |
| 16 | - `ba` (L2): if user description is vague — elicit requirements for what tools/resources the server should expose |
| 17 | - `research` (L3): look up target API documentation, existing MCP servers for reference |
| 18 | - `test` (L2): generate and run test suite for the server |
| 19 | - `docs` (L2): generate server documentation (tool catalog, installation, configuration) |
| 20 | - `verification` (L3): verify server builds and tests pass |
| 21 | |
| 22 | ## Called By (inbound) |
| 23 | |
| 24 | - `cook` (L1): when MCP-related task detected |
| 25 | - `scaffold` (L1): MCP Server template in Phase 5 |
| 26 | - User: `/rune mcp-builder` direct invocation |
| 27 | |
| 28 | ## Executable Steps |
| 29 | |
| 30 | ### Step 1 — Spec Elicitation |
| 31 | |
| 32 | If description is detailed enough (tools, resources, target API specified), proceed. |
| 33 | If vague, ask targeted questions: |
| 34 | |
| 35 | 1. **What tools should this MCP server expose?** (actions the AI can perform) |
| 36 | 2. **What resources does it manage?** (data the AI can read) |
| 37 | 3. **What external APIs does it connect to?** (if any) |
| 38 | 4. **TypeScript or Python?** (default: TypeScript with @modelcontextprotocol/sdk) |
| 39 | 5. **Authentication?** (API keys, OAuth, none) |
| 40 | |
| 41 | If user provides a detailed spec or existing API docs → extract answers, confirm. |
| 42 | |
| 43 | ### Step 2 — Architecture Design |
| 44 | |
| 45 | <MUST-READ path="references/auto-discovery-pattern.md" trigger="when the server has 5+ tools OR multiple API providers — use auto-discovery registry for graceful degradation"/> |
| 46 | |
| 47 | Determine server structure based on spec: |
| 48 | |
| 49 | **TypeScript (default):** |
| 50 | ``` |
| 51 | mcp-server-<name>/ |
| 52 | ├── src/ |
| 53 | │ ├── index.ts — server entry point, tool/resource registration |
| 54 | │ ├── tools/ |
| 55 | │ │ ├── <tool-name>.ts — one file per tool |
| 56 | │ │ └── index.ts — tool registry |
| 57 | │ ├── resources/ |
| 58 | │ │ ├── <resource>.ts — one file per resource type |
| 59 | │ │ └── index.ts — resource registry |
| 60 | │ ├── lib/ |
| 61 | │ │ ├── client.ts — external API client (if applicable) |
| 62 | │ │ └── types.ts — shared types |
| 63 | │ └── config.ts — environment variable validation |
| 64 | ├── tests/ |
| 65 | │ ├── tools/ |
| 66 | │ │ └── <tool-name>.test.ts |
| 67 | │ └── resources/ |
| 68 | │ └── <resource>.test.ts |
| 69 | ├── package.json |
| 70 | ├── tsconfig.json |
| 71 | ├── .env.example |
| 72 | └── README.md |
| 73 | ``` |
| 74 | |
| 75 | **Python (FastMCP):** |
| 76 | ``` |
| 77 | mcp-server-<name>/ |
| 78 | ├── src/ |
| 79 | │ ├── server.py — FastMCP server with tool/resource decorators |
| 80 | │ ├── tools/ |
| 81 | │ │ └── <tool_name>.py |
| 82 | │ ├── resources/ |
| 83 | │ │ └── <resource>.py |
| 84 | │ ├── lib/ |
| 85 | │ │ ├── client.py — external API client |
| 86 | │ │ └── types.py — Pydantic models |
| 87 | │ └── config.py — settings via pydantic-settings |
| 88 | ├── tests/ |
| 89 | │ ├── test_<tool_name>.py |
| 90 | │ └── test_<resource>.py |
| 91 | ├── pyproject.toml |
| 92 | ├── .env.example |
| 93 | └── README.md |
| 94 | ``` |
| 95 | |
| 96 | ### Step 3 — Generate Server Code |
| 97 | |
| 98 | #### Tool Generation |
| 99 | |
| 100 | For each tool: |
| 101 | |
| 102 | **TypeScript:** |
| 103 | ```typescript |
| 104 | import { z } from 'zod'; |
| 105 | |
| 106 | export const toolName = { |
| 107 | name: 'tool_name', |
| 108 | description: 'What this tool does — used by AI to decide when to call it', |
| 109 | inputSchema: z.object({ |
| 110 | param1: z.string().describe('Description for AI'), |
| 111 | param2: z.number().optional().describe('Optional parameter'), |
| 112 | }), |
| 113 | async handler(input: { param1: string; param2?: number }) { |
| 114 | // Implementation |
| 115 | return { content: [{ type: 'text', text: JSON.stringify(result) }] }; |
| 116 | }, |
| 117 | }; |
| 118 | ``` |
| 119 | |
| 120 | **Python (FastMCP):** |
| 121 | ```python |
| 122 | from fastmcp import FastMCP |
| 123 | |
| 124 | mcp = FastMCP("server-name") |
| 125 | |
| 126 | @mcp.tool() |
| 127 | async def tool_name(param1: str, param2: int | None = None) -> str: |
| 128 | """What this tool does — used by AI to decide when to call it.""" |
| 129 | # Implementation |
| 130 | return json.dumps(result) |
| 131 | ``` |
| 132 | |
| 133 | #### Resource Generation |
| 134 | |
| 135 | For each resource: |
| 136 | - URI template with parameters |
| 137 | - Read handler that returns structured content |
| 138 | - List handler for collections |
| 139 | |
| 140 | #### Configuration |
| 141 | |
| 142 | Generate `.env.example` with all required environment variables: |
| 143 | ```env |
| 144 | # Required |
| 145 | API_KEY=your_api_key_here |
| 146 | API_BASE_URL=https://api.example.com |
| 147 | |
| 148 | # Optional |
| 149 | LOG_LEVEL=info |
| 150 | CACHE_TTL=300 |
| 151 | ``` |
| 152 | |
| 153 | Genera |