---
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.

<problem_patterns>
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.
</problem_patterns>

<architecture_map>
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
</architecture_map>

<inputs_and_configuration>
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.
</inputs_and_configuration>

<adaptation_playbook>
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.
</adaptation_playbook>

<reference_docs>
- 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`
</reference_docs>
