# mcp-brain-router — Role-Based Multi-Provider MCP Router — Complete AI & LLM Reference Corpus (`llms-full.txt`)
- Repository: https://github.com/mohan-n-swamy/mcp-brain-router
- Web Discovery URL: https://mohan-n-swamy.github.io/repos/mcp-brain-router/
- License: MIT
- Keywords: mcp, mcp-server, model-context-protocol, llm-router, multi-agent, claude-code, ai-agents, agent-orchestration, gemini, grok, developer-tools, python
---
## File: `AI-README.md` — AI-README.md
---
repo: "mohan-n-swamy/mcp-brain-router"
title: "mcp-brain-router — Role-Based Multi-Provider MCP Router"
license: "MIT"
keywords: [mcp, mcp-server, model-context-protocol, llm-router, multi-agent, claude-code, ai-agents, agent-orchestration, gemini, grok, developer-tools, python]
capabilities:
- "Eight fixed, auditable role cascades in `config.ROLES` (`thinker`, `adversary`, `coder`, `processor`, `writer`, `explorer`, `qa`, `simple`)."
- "Cross-provider `adversary` filter that automatically skips the caller's own model provider."
- "300-second model health/quota ping cache (`~/.local/state/brain-router-ping.json`) preventing repeated timeout stalls."
- "Isolated `agy` one-shot execution cutting input overhead from ~25,640 tokens to ~10,060 tokens via scoped plugin exclusion and deny-all tool hooks."
when_to_use:
- "A local Model Context Protocol (MCP) server for Claude Code, Antigravity, Grok, and Codex that delegates self-contained tasks across 8 specialized roles (`thinker`, `adversary`, `coder`, `processor`, `writer`, `explorer`, `qa`, `simple`) with 300-second ping-cached quota failover and cross-provider adversarial enforcement."
- "Single-provider coding sessions hit subscription rate limits mid-build, burn frontier tokens on trivial extraction tasks, and suffer from single-family sycophancy when reviewing their own designs. `mcp-brain-router` separates orchestration from worker selection so every sub-task routes to the best available model family automatically."
inputs_required:
- "BRAIN_ROUTER_CALLER: Identifies the calling orchestrator (`claude`, `antigravity`, `grok`, `codex`)"
- "CONFIG_TOML: Mode-0600 file holding optional provider API keys"
quickstart:
- "pipx install mcp-brain-router && mcp-brain-router-install"
- "mcp-brain-router roles"
- "pytest -q"
---
# mcp-brain-router — Role-Based Multi-Provider MCP Router — Machine-Readable Agent Guide
A local Model Context Protocol (MCP) server for Claude Code, Antigravity, Grok, and Codex that delegates self-contained tasks across 8 specialized roles (`thinker`, `adversary`, `coder`, `processor`, `writer`, `explorer`, `qa`, `simple`) with 300-second ping-cached quota failover and cross-provider adversarial enforcement.
Single-provider coding sessions hit subscription rate limits mid-build, burn frontier tokens on trivial extraction tasks, and suffer from single-family sycophancy when reviewing their own designs. `mcp-brain-router` separates orchestration from worker selection so every sub-task routes to the best available model family automatically.
Key modules and entry points in this repository:
- `mcp_brain_router/server.py`: MCP server exposing `roles`, `decide`, and `delegate` tools
- `mcp_brain_router/config.py`: Canonical 8-role cascade definitions and per-role timeouts
- `bin/`: Deck builders, routing-mode gates, and benchmark utilities
Every organization-specific value enters through `.env` (copied from `.env.example`) or external adapter files. No source edit is needed to change organization names, endpoints, database URLs, webhook secrets, or thresholds.
When a human asks an AI coding agent to deploy or adapt `mcp-brain-router` into their stack:
1. Run `mcp-brain-router-install` to register the MCP server in Claude Code, Grok, and Codex.
2. Call `delegate(role='adversary', ...)` before shipping non-trivial architectural changes.
- Product Requirements: `docs/PRD.md`
- Working-Backwards PR-FAQ: `docs/PR-FAQ.md`
- High-Level Architecture: `docs/HLD.md`
- Low-Level Interfaces & Runbook: `docs/LLD.md`
- Coding Agent Rules: `AGENTS.md`
---
## File: `.env.example` — Environment Contract (.env.example)
```ini
# mcp-brain-router — Role-Based Multi-Provider MCP Router — Environment Contract
# Copy to .env and set values for your organization.
# Identifies the calling orchestrator (`claude`, `antigravity`, `grok`, `codex`)
BRAIN_ROUTER_CALLER=claude
# Mode-0600 file holding optional provider API keys
CONFIG_TOML=~/.config/mcp-brain-router/config.toml
```
---
## File: `AGENTS.md` — AGENTS.md
# AGENTS.md — mcp-brain-router — Role-Based Multi-Provider MCP Router
Read this file first before modifying `mcp-brain-router`.
## Purpose
A local Model Context Protocol (MCP) server for Claude Code, Antigravity, Grok, and Codex that delegates self-contained tasks across 8 specialized roles (`thinker`, `adversary`, `coder`, `processor`, `writer`, `explorer`, `qa`, `simple`) with 300-second ping-cached quota failover and cross-provider adversarial enforcement.
## Commands
```bash
pipx install mcp-brain-router && mcp-brain-router-install
mcp-brain-router roles
pytest -q
```
## Module Map
- `mcp_brain_router/server.py`: MCP server exposing `roles`, `decide`, and `delegate` tools
- `mcp_brain_router/config.py`: Canonical 8-role cascade definitions and per-role timeouts
- `bin/`: Deck builders, routing-mode gates, and benchmark utilities
## Invariants
1. Keep all organization names, credentials, domains, and thresholds in `.env` or external config files. Never hardcode company names, host IPs, or secrets in source files.
2. Deterministic business logic belongs in code and lookup tables, not inside LLM prompts.
3. Update `docs/HLD.md`, `docs/LLD.md`, and `.env.example` in the same commit whenever an interface or environment variable changes.
4. Run the repository smoke check and secret scan before opening a pull request.
---
## File: `docs/PRD.md` — Product Requirements Document (docs/PRD.md)
# Product Requirements Document — mcp-brain-router — Role-Based Multi-Provider MCP Router
A local Model Context Protocol (MCP) server for Claude Code, Antigravity, Grok, and Codex that delegates self-contained tasks across 8 specialized roles (`thinker`, `adversary`, `coder`, `processor`, `writer`, `explorer`, `qa`, `simple`) with 300-second ping-cached quota failover and cross-provider adversarial enforcement.
## 1. Problem
Single-provider coding sessions hit subscription rate limits mid-build, burn frontier tokens on trivial extraction tasks, and suffer from single-family sycophancy when reviewing their own designs. `mcp-brain-router` separates orchestration from worker selection so every sub-task routes to the best available model family automatically.
## 2. Users and Jobs-to-be-Done
| Persona | Job-to-be-Done |
|---|---|
| Claude Code / Antigravity / Grok Power User | Delegate sub-tasks across subscriptions and local models (`apple-fm`, Ollama) without manual switching. |
| Engineering Rig Maintainer | Enforce cross-provider `adversary` design and code reviews automatically. |
## 3. Core Capabilities
- Eight fixed, auditable role cascades in `config.ROLES` (`thinker`, `adversary`, `coder`, `processor`, `writer`, `explorer`, `qa`, `simple`).
- Cross-provider `adversary` filter that automatically skips the caller's own model provider.
- 300-second model health/quota ping cache (`~/.local/state/brain-router-ping.json`) preventing repeated timeout stalls.
- Isolated `agy` one-shot execution cutting input overhead from ~25,640 tokens to ~10,060 tokens via scoped plugin exclusion and deny-all tool hooks.
## 4. Configurable Inputs
Adopters configure the system for their own organization without editing core application logic:
| Variable | Default / Example | Purpose |
|---|---|---|
| `BRAIN_ROUTER_CALLER` | `claude` | Identifies the calling orchestrator (`claude`, `antigravity`, `grok`, `codex`) |
| `CONFIG_TOML` | `~/.config/mcp-brain-router/config.toml` | Mode-0600 file holding optional provider API keys |
## 5. Phasing and Stability Exit Criteria
1. **Phase 1 (Local Synthetic Run):** Clone the repository, copy `.env.example` to `.env`, and run the quickstart commands against synthetic seed data. Exit criterion: smoke checks pass with zero external credentials.
2. **Phase 2 (Read-Only Shadow Wiring):** Connect read-only credentials or webhook listeners in shadow/dry-run mode. Exit criterion: 100 consecutive events or queries reconcile cleanly against source records.
3. **Phase 3 (Production Cutover):** Enable live writes, alerts, or routing behind bounded retry and idempotency guards.
## 6. Non-Goals
- Shipping organization-specific business rules hardcoded in application source.
- Storing credentials, personal customer records, or tenant URLs inside version control.
- Replacing deterministic validation or arithmetic with unconstrained model prompts.
---
## File: `docs/PR-FAQ.md` — Working-Backwards PR-FAQ (docs/PR-FAQ.md)
# Working-Backwards PR-FAQ — mcp-brain-router — Role-Based Multi-Provider MCP Router
**Release Summary:** `mcp-brain-router` gives engineering and operations teams a self-hosted, open-source implementation of mcp-brain-router — Role-Based Multi-Provider MCP Router that configures via `.env` and runs on standard infrastructure in minutes.
## Press Release
Operations and engineering teams often rebuild the same internal workflows behind closed doors or pay per-seat SaaS markups for rigid tools that cannot match their field reality. `mcp-brain-router` open-sources a battle-tested implementation of mcp-brain-router — Role-Based Multi-Provider MCP Router, stripped of all single-company assumptions and packaged with clear adapter boundaries, synthetic demo data, and machine-readable agent documentation.
Any team can fork `mcp-brain-router`, supply their own `.env` inputs and taxonomy config, and deploy locally or in production with Docker, Python, or Node. AI coding assistants such as Claude Code, Codex, and Cursor can read `AI-README.md` and `llms.txt` to wire custom ERP, CRM, or warehouse adapters in a single session.
## External Adopter FAQ
**Q1: How long does it take to run locally after cloning?**
Under five minutes. Copy `.env.example` to `.env` and run the quickstart commands in `README.md`. Synthetic fixtures let you inspect the workflow before connecting live credentials.
**Q2: Do I need to rewrite source files to use my own company name, channels, or rules?**
No. Organization names, endpoints, thresholds, and credentials sit in `.env` and declarative config files. External system specifics live behind narrow adapter modules documented in `docs/LLD.md`.
**Q3: What license governs this repository?**
MIT License. You can fork, modify, self-host, and use it commercially without restriction.
## Internal Engineering & Security FAQ
**Q4: How do we prevent tenant or employer data from ever entering a public fork?**
The repository starts from a clean git history, excludes raw exports and binary dumps, validates every commit through `gitleaks`, and ships only synthetic fixtures.
**Q5: What happens when an upstream API or model provider is slow or unavailable?**
Inbound webhooks persist raw payloads before processing, outbound writes carry idempotency keys with bounded exponential backoff, and model-backed paths fail open to deterministic rules or explicit human queues.
---
## File: `docs/HLD.md` — High-Level Design (docs/HLD.md)
# High-Level Design (HLD) — mcp-brain-router — Role-Based Multi-Provider MCP Router
A local Model Context Protocol (MCP) server for Claude Code, Antigravity, Grok, and Codex that delegates self-contained tasks across 8 specialized roles (`thinker`, `adversary`, `coder`, `processor`, `writer`, `explorer`, `qa`, `simple`) with 300-second ping-cached quota failover and cross-provider adversarial enforcement.
## 1. System Topology
```mermaid
flowchart LR
Orch["Claude / Antigravity / Grok"] -->|"delegate(role=...)"| Router["mcp-brain-router"]
Router --> Ping["300s Ping & Quota Cache"]
Ping --> Local["apple-fm / Ollama ($0)"]
Ping --> Cloud["Claude · Gemini · Grok CLIs"]
```
## 2. Architectural Decisions and Rejected Alternatives
| Decision | Why It Holds | Rejected Alternative |
|---|---|---|
| Role-owned cascades in repo code (`config.ROLES`) | Keeps routing deterministic and inspectable rather than hidden in per-host config drift. | Ad-hoc model names hardcoded in every skill |
| Cross-provider `adversary` skip | Guarantees a design authored by Claude is critiqued by Gemini or Grok (and vice versa). | Self-review by the same model family |
## 3. Data Flow and Failure Boundaries
1. **Configuration Boundary:** Startup validates `.env` variables and declarative config schemas before accepting traffic or running scheduled jobs.
2. **Adapter Boundary:** External services (databases, chat channels, HRMS, warehouses, or LLM providers) sit behind explicit adapter modules so failures stay isolated and testable with local mocks.
3. **Observability and Audit:** State transitions and job executions emit structured logs and deterministic status records rather than mutating state silently.
## 4. Scaling Notes
- **1x to 10x load:** Single-node Docker Compose or process supervisor handles standard team workloads with indexed database queries and bounded worker concurrency.
- **First bottleneck at 10x+:** High-frequency webhook or batch ingestion queues; mitigate by separating the stateless HTTP receiver from background worker processes sharing Redis or PostgreSQL locks.
---
## File: `docs/LLD.md` — Low-Level Design & Runbook (docs/LLD.md)
# Low-Level Design (LLD) & Operations Runbook — mcp-brain-router — Role-Based Multi-Provider MCP Router
This document defines the module responsibilities, environment contract, and operational procedures for `mcp-brain-router`.
## 1. Module and File Inventory
| Path | Responsibility |
|---|---|
| `mcp_brain_router/server.py` | MCP server exposing `roles`, `decide`, and `delegate` tools |
| `mcp_brain_router/config.py` | Canonical 8-role cascade definitions and per-role timeouts |
| `bin/` | Deck builders, routing-mode gates, and benchmark utilities |
## 2. Environment Variable Contract
| Variable | Default / Example | Required | Description |
|---|---|---|---|
| `BRAIN_ROUTER_CALLER` | `claude` | Yes | Identifies the calling orchestrator (`claude`, `antigravity`, `grok`, `codex`) |
| `CONFIG_TOML` | `~/.config/mcp-brain-router/config.toml` | Yes | Mode-0600 file holding optional provider API keys |
## 3. Extension Recipe
1. Run `mcp-brain-router-install` to register the MCP server in Claude Code, Grok, and Codex.
2. Call `delegate(role='adversary', ...)` before shipping non-trivial architectural changes.
## 4. Operations Runbook
### 1. Inspect live role cascades
```bash
mcp-brain-router roles
```
### 2. Re-register across installed harnesses
```bash
mcp-brain-router-install
```
---
## File: `docs/RESEARCH-2026.md` — 2026 Research & Landscape Notes (docs/RESEARCH-2026.md)
# 2026 Multi-Provider Agent Routing Research
## 1. HTTP Completion Proxies vs Agentic CLI Subscription Routing
In 2026, HTTP proxy routers such as LiteLLM and OpenRouter route raw chat-completion API calls on per-token billing. By contrast, production CLI coding engineers hold flat-rate subscriptions across Claude Max, Gemini Ultra, and SuperGrok alongside zero-cost local models (`apple-fm` on Apple Silicon and `gpt-oss:20b` via Ollama). `mcp-brain-router` routes *self-contained agentic turns* across those installed CLIs and local runtimes by semantic role (`thinker`, `adversary`, `coder`, `processor`, `writer`, `explorer`, `qa`, `simple`).
## 2. Key 2026 Design Improvements
- **Cross-Provider Adversarial Review (`A28`):** Single-family self-critique shares correlated blind spots; skipping the caller's own provider on `role=adversary` catches real structural flaws.
- **300-Second Health & Quota Ping Cache:** Avoids burning 30-second timeouts repeatedly when one subscription window hits its 5-hour cap.
- **One-Shot Context Diet:** Running worker CLIs inside an isolated temporary directory without heavy IDE plugins cuts per-call prompt overhead by ~60%.