Skip to main content
Glama
README.md
# crossroute-mcp

stdio MCP server with two tools:

- `list_routes` lists configured upstream routes. It does not reveal API keys.
- `complete` sends a prompt to one route and, when configured, fails over to another route that serves the same model.

Routes speak either an OpenAI-compatible API (`chat_completions` or `responses`) or an Anthropic-compatible Messages API. Secrets stay in environment variables named by the config file.

## Requirements

Python 3.11 or newer.

## Install

From a checkout of this repository:

```bash
pip install -e .
```

With [uv](https://docs.astral.sh/uv/):

```bash
uv sync
```

The console script is `crossroute-mcp`.

## Configure

1. Copy the example config and edit the placeholders:

```bash
cp config.example.json config.json
```

2. Export the API keys named in the config, or copy `.env.example` to `.env` and fill it in. `.env` and `config.json` are gitignored.

```bash
export CROSSROUTE_CONFIG="$PWD/config.json"
export PROVIDER_A_API_KEY="replace-me"
export PROVIDER_B_API_KEY="replace-me"
```

`config.example.json` uses generic route names (`provider-a`, `provider-b`) and hostnames under `example`. Replace the base URLs and model ids with the gateways you actually use. Do not commit real keys.

Each route names its key with `api_key_env`. Optional `api_key_env_fallbacks` are extra environment variable names; empty ones are skipped. Set `"enabled": false` on a route object to leave it in the file without loading it. `reasoning_budget_map` supplies token budgets for Anthropic `budget` thinking. The example values are placeholders.

Environment variables:

| Variable | Purpose |
| --- | --- |
| `CROSSROUTE_CONFIG` | Path to the JSON config. When unset, `./config.json` is used if that file exists; otherwise `~/.config/crossroute-mcp/config.json`. |
| `CROSSROUTE_TIMEOUT_SEC` | HTTP timeout in seconds. Default: `120`. |
| `PROVIDER_A_API_KEY` and similar | Key values. The config names the variable; this repo never stores the value. |

A minimal MCP client entry (placeholders only):

```json
{
  "mcpServers": {
    "crossroute": {
      "command": "crossroute-mcp",
      "env": {
        "CROSSROUTE_CONFIG": "/absolute/path/to/config.json",
        "PROVIDER_A_API_KEY": "replace-me",
        "PROVIDER_B_API_KEY": "replace-me"
      }
    }
  }
}
```

## Run

```bash
crossroute-mcp
```

The process speaks MCP on stdin and stdout. Startup logs go to stderr and include the config path, route count, and safety mode. Prompt and response bodies are not logged.

## Tools

`list_routes` returns route names, protocols, default models, reasoning levels, and the cross-route failover chains. Base URLs and key values are omitted.

`complete` arguments:

| Argument | Required | Notes |
| --- | --- | --- |
| `route` | yes | Route name from `list_routes`. |
| `prompt` | yes | User text. Scanned locally before any network call. |
| `system` | no | Optional system text. Scanned the same way. |
| `model` | no | Overrides the route default. This is also the model used for cross-route matching. |
| `reasoning_level` | no | `none`, `minimal`, `low`, `medium`, `high`, `xhigh`, or `max`. |
| `max_tokens` | no | Falls back to the route default, then `8192`. |
| `temperature` | no | Sent only when you set it. Some reasoning models reject it. |
| `cross_route` | no | Default `true`. Set `false` to stay on the named route. |

If the result has `suggest_local_fallback: true`, the caller can finish with its own model. If `safety_blocked` is true, do not retry the same prompt anywhere.

## Cross-route fallbacks

`cross_route_fallbacks` in the config is a list of failover chains. Each chain has:

- `id`: a short name for the chain.
- `match_models`: model ids that select this chain.
- `route_chain`: ordered hops, each with a `route` and a `model`.

The intent model is the `model` argument when you pass one. Otherwise it is the entry route's `default_model`. When `cross_route` is true (the default) and that intent model matches a chain, a failure on the entry route is retried on the later hops in order. Hops that name an unknown or disabled route are skipped.

Same-route `model_fallbacks` run only on the entry route. A later hop uses the model named on that hop and does not expand that route's `model_fallbacks`.

Set `cross_route` to false to stay on the named route. The example chain `example-model-failover` tries `provider-a` first and then `provider-b`, both with `example-model`.

## Safety

Before a request is sent, `complete` scans `prompt` and `system` for email addresses, payment card numbers, API keys and private keys, contract numbers, long pasted contracts or policy text, and unpublished financial figures.

| Mode | Behavior |
| --- | --- |
| `block` | Default. Scan `prompt` and `system`, and refuse the call before any network request. |
| `off` | Skip the scan. Set `"safety": {"mode": "off"}` in the config. |

Unknown mode values fail closed and are treated as `block`. A blocked call returns `safety_blocked: true` and `suggest_local_fallback: false`. The error names the category only. Error text is English and does not include the matched substring.

## Tests

```bash
python -m unittest discover -s tests -v
```

## License

MIT. See [LICENSE](LICENSE).

The copyright line is `Copyright (c) 2026 CheeInsight`.

TDQS

A3.8/5.0

Scored across 2 tools

Disambiguation4/5

The two tools serve clearly separate purposes: list_routes is a read-only discovery call, while complete performs the actual generation against a named route. The only friction is the bare name 'complete', which alone would be vague, but the description and the paired discovery tool make selection unambiguous.

Naming Consistency3/5

Both names are snake_case lowercase verbs, so the surface is readable. However, list_routes follows a verb_noun pattern while complete is a bare verb with no object, so the two names do not form a predictable pair (e.g., list_routes / call_route would be more consistent).

Tool Count3/5

Two tools is thin for a routing/gateway server, but the scope is deliberately narrow: discover routes, then invoke one. It sits at the borderline where the surface is defensible yet feels minimal rather than well-scoped.

Completeness3/5

The core lifecycle (discover routes, call a route) is covered, and the rich response envelope handles failure paths. Notable gaps remain: no per-route detail/health or availability check, no model/route status inspection, and no way to validate config despite the tool advertising fallback and safety-mode behavior.