|
| 1 | +# A3M Router MCP Server (Python) |
| 2 | + |
| 3 | +[MCP (Model Context Protocol)](https://modelcontextprotocol.io/) server for [A3M Router](https://github.com/Das-rebel/a3m-router) — parallel multi-LLM execution for AI agents. |
| 4 | + |
| 5 | +Allows any MCP-compatible AI agent (Claude Desktop, Cursor, Windsurf, Codex, n8n, etc.) to use A3M's intelligent routing and ensemble execution directly from Python. |
| 6 | + |
| 7 | +## Tools |
| 8 | + |
| 9 | +| Tool | Description | |
| 10 | +|------|-------------| |
| 11 | +| `a3m_route` | Route a query to the optimal LLM provider — returns model, tier, cost, reasoning | |
| 12 | +| `a3m_ensemble` | Execute a query across multiple providers in parallel and merge results | |
| 13 | +| `a3m_classify` | Classify query type (fast/creative/deep/code) and get provider recommendations | |
| 14 | +| `a3m_providers` | List all configured providers with cost and availability | |
| 15 | + |
| 16 | +## Installation |
| 17 | + |
| 18 | +```bash |
| 19 | +# From source |
| 20 | +cd python/mcp-server |
| 21 | +pip install -e . |
| 22 | + |
| 23 | +# Or install the package directly (when published) |
| 24 | +pip install a3m-mcp-server |
| 25 | +``` |
| 26 | + |
| 27 | +## Configuration |
| 28 | + |
| 29 | +Set environment variables: |
| 30 | + |
| 31 | +```bash |
| 32 | +# Required: A3M Router URL (must be running) |
| 33 | +export A3M_BASE_URL=http://localhost:8787 |
| 34 | + |
| 35 | +# Optional |
| 36 | +export A3M_API_KEY=not-needed # default |
| 37 | +export A3M_TIMEOUT=30.0 |
| 38 | +``` |
| 39 | + |
| 40 | +## Start A3M Router |
| 41 | + |
| 42 | +```bash |
| 43 | +# Node.js way |
| 44 | +npx a3m-router serve |
| 45 | + |
| 46 | +# Python way |
| 47 | +pip install a3m-router |
| 48 | +a3m-router serve |
| 49 | +``` |
| 50 | + |
| 51 | +## Usage |
| 52 | + |
| 53 | +### Claude Desktop |
| 54 | + |
| 55 | +Add to `~/Library/Application Support/Claude/claude_desktop_config.json`: |
| 56 | + |
| 57 | +```json |
| 58 | +{ |
| 59 | + "mcpServers": { |
| 60 | + "a3m-router": { |
| 61 | + "command": "python", |
| 62 | + "args": ["-m", "a3m_mcp"], |
| 63 | + "env": { |
| 64 | + "A3M_BASE_URL": "http://localhost:8787" |
| 65 | + } |
| 66 | + } |
| 67 | + } |
| 68 | +} |
| 69 | +``` |
| 70 | + |
| 71 | +### Cursor |
| 72 | + |
| 73 | +Settings → Features → MCP Servers → Add: |
| 74 | + |
| 75 | +``` |
| 76 | +Name: A3M Router |
| 77 | +Command: python |
| 78 | +Arguments: -m a3m_mcp |
| 79 | +``` |
| 80 | + |
| 81 | +### n8n MCP Trigger |
| 82 | + |
| 83 | +Add MCP Trigger node with: |
| 84 | + |
| 85 | +```json |
| 86 | +{ |
| 87 | + "server": "a3m-router", |
| 88 | + "command": "python", |
| 89 | + "args": ["-m", "a3m_mcp"] |
| 90 | +} |
| 91 | +``` |
| 92 | + |
| 93 | +### Direct stdio (pipe JSON-RPC) |
| 94 | + |
| 95 | +```bash |
| 96 | +# List tools |
| 97 | +echo '{"jsonrpc":"2.0","id":1,"method":"tools/list"}' | python -m a3m_mcp |
| 98 | + |
| 99 | +# Call a3m_route |
| 100 | +echo '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"a3m_route","arguments":{"query":"Write a Python quicksort"}}}' | python -m a3m_mcp |
| 101 | +``` |
| 102 | + |
| 103 | +## Examples |
| 104 | + |
| 105 | +### Route a query |
| 106 | + |
| 107 | +```python |
| 108 | +# a3m_route tool |
| 109 | +Input: {"query": "Write a Python function to sort a list"} |
| 110 | +Output: |
| 111 | +{ |
| 112 | + "model": "groq/llama-3.3-70b-versatile", |
| 113 | + "tier": "cheap", |
| 114 | + "cost": 0.000012, |
| 115 | + "reasoning": "Code query detected, routing to fast coding provider", |
| 116 | + "classification": "code" |
| 117 | +} |
| 118 | +``` |
| 119 | + |
| 120 | +### Ensemble execution |
| 121 | + |
| 122 | +```python |
| 123 | +# a3m_ensemble tool |
| 124 | +Input: {"query": "Explain quantum computing in 3 sentences", "providers": ["groq", "google", "cerebras"]} |
| 125 | +Output: |
| 126 | +{ |
| 127 | + "query": "Explain quantum computing in 3 sentences", |
| 128 | + "parallel_responses": [ |
| 129 | + {"provider": "groq", "content": "Quantum computing is..."}, |
| 130 | + {"provider": "google", "content": "At its core, quantum..."}, |
| 131 | + {"provider": "cerebras", "content": "Quantum computing leverages..."} |
| 132 | + ], |
| 133 | + "best_answer": "Quantum computing is...", |
| 134 | + "stats": {"total_providers": 3, "successful": 3, "failed": 0} |
| 135 | +} |
| 136 | +``` |
| 137 | + |
| 138 | +## Architecture |
| 139 | + |
| 140 | +``` |
| 141 | +┌──────────────────────────────────────────────────────┐ |
| 142 | +│ MCP Client (Claude, Cursor, Codex, n8n) │ |
| 143 | +└──────────────────────┬───────────────────────────────┘ |
| 144 | + │ MCP Protocol (stdio) |
| 145 | +┌──────────────────────▼───────────────────────────────┐ |
| 146 | +│ A3M Router MCP Server (Python) │ |
| 147 | +│ │ |
| 148 | +│ a3m_route a3m_ensemble a3m_classify a3m_providers │ |
| 149 | +└──────────────────────┬───────────────────────────────┘ |
| 150 | + │ HTTP API |
| 151 | +┌──────────────────────▼───────────────────────────────┐ |
| 152 | +│ A3M Router (a3m-router serve) │ |
| 153 | +│ │ |
| 154 | +│ routeQuery() parallelEnsemble() providers │ |
| 155 | +└───────┬────────────┬────────────┬─────────────────────┘ |
| 156 | + │ │ │ |
| 157 | + ┌────▼───┐ ┌────▼───┐ ┌────▼───┐ |
| 158 | + │ Groq │ │ Google │ │Cerebras│ ... |
| 159 | + └────────┘ └────────┘ └────────┘ |
| 160 | +``` |
| 161 | + |
| 162 | +## Testing |
| 163 | + |
| 164 | +```bash |
| 165 | +cd python/mcp-server |
| 166 | +pip install -e ".[dev]" |
| 167 | +pytest |
| 168 | +``` |
| 169 | + |
| 170 | +## License |
| 171 | + |
| 172 | +MIT |
0 commit comments