MCP Server
9RouterX ships a built-in Model Context Protocol server (internal/mcpserver).
It speaks JSON-RPC 2.0 over two transports: stdio (line-delimited requests,
for local IDE processes) and HTTP POST at http://localhost:20128/api/mcp.
Enable it
The server is off until ROUTERX_MCP_TOKEN is set to a non-empty value. An
empty token means every call is refused: stdio exits with mcp: ROUTERX_MCP_TOKEN is not set; server disabled, and the HTTP route answers 403.
| Deployment | How to set the token |
|---|---|
| systemd | Environment=ROUTERX_MCP_TOKEN=<your-token> in the service unit, then systemctl daemon-reload && systemctl restart 9routerx |
| Docker | -e ROUTERX_MCP_TOKEN=<your-token> on docker run, or the environment: block in compose |
| Tray / desktop | set the variable in the launcher environment before starting 9RouterX |
Do not put the token in a committed file. Rotate it by generating a new value and restarting the gateway; existing clients must be updated to match.
Authenticate
HTTP requests carry the token as Authorization: Bearer <token> or in the
X-MCP-Token header. Both must match ROUTERX_MCP_TOKEN exactly. The listener
is loopback by default: do not expose /api/mcp to a public network. Scope the
token to the operator who needs agent access and treat it like a dashboard
password.
Tools
The server exposes 14 tools. Descriptions below come from toolDefinitions()
in internal/mcpserver/mcpserver.go; a tool returns a result object or a
tool-level error, never a JSON-RPC protocol error for business failures.
| Tool | Description |
|---|---|
list_keys |
List API keys with metadata (no raw secrets) |
get_health |
Gateway health and version |
list_models |
Model catalog per provider |
list_combos |
Combo configurations with strategies |
cache_stats |
Semantic cache statistics |
usage_summary |
Usage aggregated by provider (prompt/completion/cost) |
security_log |
Recent security events (last N, filter by severity); optional limit (default 50) |
notifications |
Notification feed with unread count |
resilience_status |
Circuit breaker states per provider |
team_usage |
Usage report for one team; requires team_id |
backup_create |
Create an immediate database backup (write) |
quota_check |
Per-connection quota snapshot |
list_providers |
Provider connections with status |
get_settings |
Current gateway settings |
Several tools are pointers to richer dashboard endpoints: list_models points
to GET /v1/models, cache_stats to GET /api/cache, resilience_status to
GET /api/resilience/status, backup_create to POST /api/settings/auto-backup,
and quota_check to GET /api/usage/{connectionId}.
Client configuration
Generic mcpServers block for Claude Code, Cursor or another MCP client
(HTTP transport):
{
"mcpServers": {
"9routerx": {
"url": "http://localhost:20128/api/mcp",
"headers": { "Authorization": "Bearer <ROUTERX_MCP_TOKEN>" }
}
}
}
For stdio transport, point the client at the 9routerx binary with
ROUTERX_MCP_TOKEN in its environment and let the client manage the process.
JSON-RPC examples
List tools (no server call to localhost needed to read this page):
curl -s http://localhost:20128/api/mcp \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <ROUTERX_MCP_TOKEN>' \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'
Call one tool:
curl -s http://localhost:20128/api/mcp \
-H 'Content-Type: application/json' \
-H 'X-MCP-Token: <ROUTERX_MCP_TOKEN>' \
-d '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"get_health","arguments":{}}}'
The server accepts initialize, tools/list and tools/call; any other method
returns a JSON-RPC method not found error.
