Skip to main content

AI Router

AI Router is a Python stdio MCP server. Install the mcp-ai-router package from PyPI, run the ai-router CLI, and connect any MCP client with "command": "ai-router" and "args": ["serve"].

It automates authenticated Gemini and ChatGPT web sessions through CloakBrowser — no API keys, but you do need provider web accounts and a one-time CLI login.

Name
PyPI / pipx mcp-ai-router
CLI command ai-router
GitHub scriptkid23/ai-router

Quick start

pipx install mcp-ai-router          # 1. install
ai-router browser login             # 2. log in (opens browser windows)
ai-router browser status            # 3. expect gemini/chatgpt: logged_in

Add MCP config (see Connect MCP client), reload your client, then verify:

Ask your agent: "Call list_providers, then ask Gemini to reply with exactly: router working"

Requirements

Tool Version
Python 3.11+
pipx latest
Disk + network ~200 MB free for first browser download

Tested on macOS, Linux, and Windows. No Poetry, Node.js, or repo clone required for normal stdio MCP use.

Provider accounts: valid Gemini and/or ChatGPT web accounts (free tiers work). Login is manual via the browser UI.

Install

python3 -m pip install --user pipx   # use py -m pip on Windows if needed
python3 -m pipx ensurepath
# open a new terminal
pipx install mcp-ai-router

See pipx installation docs if the commands above fail. On Unix, pipx ensurepath usually adds ~/.local/bin to your shell PATH.

Verify:

ai-router --version
ai-router --help

Upgrade later:

pipx upgrade mcp-ai-router

Uninstall:

pipx uninstall mcp-ai-router
# optional manual cleanup:
# rm -rf ~/.ai-router ~/.cloakbrowser

Login (one-time)

ai-router browser login                  # all available providers
ai-router browser login --provider gemini
ai-router browser login --provider chatgpt
  1. Visible browser windows open (one per provider being configured).
  2. Log in with your provider account in each window.
  3. Close all browser windows when done — this saves the session to disk.

Sessions are stored in ~/.ai-router/profile/. Logging in to one provider only is fine; use ai-router browser status to check.

ai-router browser status
# gemini: logged_in
# chatgpt: logged_in

CloakBrowser download (first use)
pipx install does not download the browser. The first browser login or ask triggers a one-time download of a CloakBrowser-managed Chromium binary (~200 MB) to ~/.cloakbrowser/. You do not need playwright install or a separate Chrome install — automation uses the CloakBrowser binary, not your local Chrome app.

Connect MCP client

Works with any MCP client that supports stdio — Cursor, Claude Code, Claude Desktop, and others.

Cursor~/.cursor/mcp.json or project .cursor/mcp.json:

{
  "mcpServers": {
    "ai-router": {
      "type": "stdio",
      "command": "ai-router",
      "args": ["serve"]
    }
  }
}

Claude Code~/.claude/settings.json:

{
  "mcpServers": {
    "ai-router": {
      "command": "ai-router",
      "args": ["serve"]
    }
  }
}

Claude Desktop — MCP config file for your OS (Anthropic docs); same command / args.

The client spawns ai-router serve (stdio, default). No separate terminal, no Node.js.

If "command": "ai-router" fails

GUI apps often use a different PATH than your terminal. Use the absolute path from:

command -v ai-router    # macOS/Linux
where ai-router       # Windows
{
  "mcpServers": {
    "ai-router": {
      "type": "stdio",
      "command": "/absolute/path/to/ai-router",
      "args": ["serve"]
    }
  }
}

Use a full absolute path in JSON — do not use ~ (most clients do not expand it).

Reload MCP in your client after saving.

MCP tools

Tool Description
ask(prompt, provider?) Send a prompt; default provider is Gemini. Set provider to "chatgpt" for ChatGPT.
ask_multi(prompt, providers?, strategy?) Fan out to multiple providers in parallel (strategy: all, first, longest).
list_providers() List providers and status.
session_status(provider?) Check login state without opening a chat.

Login is CLI only — run ai-router browser login manually; there is no MCP login tool.

Conversation behavior: each ask opens a new provider web chat. Follow-up context is not preserved across calls. Your MCP client's thread and the provider's web chat are separate.

Concurrency: one MCP server process handles requests through a page queue. Concurrent ask calls to the same provider may return BROWSER_BUSY — wait and retry. ask_multi fans out across providers in parallel within one server.

CLI reference

ai-router --version
ai-router serve [--transport stdio|http] [--host 127.0.0.1] [--port 8087]
ai-router browser login [--provider gemini|chatgpt]
ai-router browser status [--provider gemini|chatgpt]
Transport Use case
stdio (default) MCP clients — "args": ["serve"]
http Local debugging only — see below

Config (optional)

Create ~/.ai-router/config.yaml. Values merge with built-in defaults (ChatGPT stays enabled unless you override URLs):

default_provider: gemini
host: 127.0.0.1
port: 8087
answer_timeout_s: 120
profile_dir: ~/.ai-router/profile
providers:
  gemini:
    url: https://gemini.google.com/app
  chatgpt:
    url: https://chatgpt.com/

Precedence: environment variables override YAML; YAML overrides defaults.

Variable Default Description
AI_ROUTER_PROFILE_DIR ~/.ai-router/profile Browser profile directory
AI_ROUTER_DEFAULT_PROVIDER gemini Default provider for ask
AI_ROUTER_HOST 127.0.0.1 HTTP bind address
AI_ROUTER_PORT 8087 HTTP port
AI_ROUTER_ANSWER_TIMEOUT_S 120 Per-request timeout (seconds)

Troubleshooting

Problem Fix
pipx: command not found Use python3 -m pipx
ai-router: command not found Run pipx ensurepath, open a new terminal
MCP client cannot find ai-router Use absolute path in "command"
pipx install mcp-ai-router fails Check Python ≥ 3.11 and https://pypi.org/project/mcp-ai-router/
gemini: logged_out / NOT_LOGGED_IN Run ai-router browser login
Slow first login or first ask CloakBrowser downloading ~200 MB, or cold browser start
Browser does not open Needs network + disk; requires cloakbrowser ≥ 0.4.4
BROWSER_BUSY Another request is in progress — wait and retry
Profile lock / browser errors Only one MCP server per profile; restart client to clear stale processes
Need HTTP debug ai-router serve --transport http

HTTP debug (advanced)

Not needed for stdio MCP. Run the server in a terminal, then bridge with Node.js:

ai-router serve --transport http
{
  "mcpServers": {
    "ai-router": {
      "command": "npx",
      "args": ["-y", "mcp-remote@latest", "http://127.0.0.1:8087/mcp"]
    }
  }
}

HTTP binds to localhost only and has no authentication — do not expose it beyond your machine.

Development

git clone https://github.com/scriptkid23/ai-router.git
cd ai-router
poetry install
poetry run pytest -v
poetry run ruff check src tests
poetry run ai-router serve --transport http

Smoke-test a wheel (macOS/Linux example):

poetry build
pipx install --force dist/mcp_ai_router-*.whl
mkdir -p /tmp/ai-router-smoke && cd /tmp/ai-router-smoke
ai-router --help && ai-router --version && ai-router browser status

Security

  • Prompts are sent to Gemini/ChatGPT web UIs — provider privacy and terms apply. Review each provider's terms; web automation may violate some account policies.
  • ~/.ai-router/profile/ holds live session cookies — treat like a password. Deleting it logs you out locally.
  • Logs may be written to ~/.ai-router/logs/ and stderr.
  • HTTP debug mode binds to 127.0.0.1 with no auth — localhost only.

License

MIT — see LICENSE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_ai_router-0.1.5.tar.gz (32.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_ai_router-0.1.5-py3-none-any.whl (47.0 kB view details)

Uploaded Python 3

File details

Details for the file mcp_ai_router-0.1.5.tar.gz.

File metadata

  • Download URL: mcp_ai_router-0.1.5.tar.gz
  • Upload date:
  • Size: 32.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.11.1 Windows/10

File hashes

Hashes for mcp_ai_router-0.1.5.tar.gz
Algorithm Hash digest
SHA256 28f30183431d16ea28337282f5dbee5a56d8d47abe84697b3de61c07acabc33e
MD5 70052426d12e5f394f5a14899278c805
BLAKE2b-256 8d23ec37889150303417d4af37139302cccde592c64e3e592cd5df5f82bd647e

See more details on using hashes here.

File details

Details for the file mcp_ai_router-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: mcp_ai_router-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 47.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.11.1 Windows/10

File hashes

Hashes for mcp_ai_router-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 999a5c7bd97fa1c44cfbc13d79769473b6fa9cdc7e31a95da7aa09b42eabba02
MD5 44b790fb2e4609d6db7a19a10807b5e0
BLAKE2b-256 a2040fa19fb2d1a707432f5830ab98c89a0729e617a070eacb0f1adcc8fd2420

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.9

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 files

This release

0.1.5 This release

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page