ImageRouter
Local MCP server that routes image-generation requests to xAI/Grok, Antigravity, and OpenAI Codex with ordered fallback, a local Playground, and an OpenAI-compatible image endpoint.
README
ImageRouter
Local MCP image-generation router for xAI/Grok, Antigravity, and OpenAI Codex with ordered fallback, a local Playground, and an OpenAI-compatible image endpoint.
ImageRouter is a local image-generation control plane for developer tools and AI agents. It exposes two MCP tools that route requests through configured xAI, Antigravity, and OpenAI Codex accounts.
ImageRouter v1 is intentionally narrow:
- One image per request.
- MCP over stdio and Streamable HTTP.
POST /v1/images/generationsfor REST clients.- Ordered provider and account fallback.
- No gallery, image cache, prompt history, chat, audio, video, search, or CLI integrations.
- Prompts pass through unchanged. The prompt pipeline is a no-op extension point for a later template/enhancer phase.
Connector status
| Provider | Status | Authentication | Notes |
|---|---|---|---|
| xAI / Grok | Stable | API key or OAuth | Uses the published xAI Images API. |
| Antigravity | Experimental | OAuth or manual token | Uses a private Code Assist endpoint that may change. |
| OpenAI Codex | Experimental | OAuth or manual token | Uses a private ChatGPT Codex Responses endpoint and requires an eligible account. |
Experimental connector failures are isolated to their route attempt; they do not crash the MCP server.
Requirements
- Node.js 20 or newer.
- A supported provider account.
- A local MCP client for MCP usage.
Quick start
Download and install
Requirements: Node.js 20+ and git.
Windows PowerShell, macOS, and Linux:
git clone https://github.com/Duylamneuuu/imagerouter.git
cd imagerouter
npm install
Optional local environment file:
# macOS/Linux
cp .env.example .env.local
# Windows PowerShell
Copy-Item .env.example .env.local
The environment file is optional for the normal dashboard flow. Do not commit .env.local; it is ignored by Git. Antigravity OAuth reconnect/refresh additionally requires the two IMAGEROUTER_ANTIGRAVITY_* variables described below.
Run the dashboard
npm run dev
Open http://127.0.0.1:20127, then:
- Add one or more accounts on Providers.
- Test each account.
- Arrange the provider chain on Routing.
- Reveal the HTTP token on Settings if an HTTP client needs it.
Production mode:
npm run build
npm run start
Both commands bind only to 127.0.0.1. The saved dashboard port is applied on restart; IMAGEROUTER_PORT overrides it.
Run the full local quality check:
npm run check
MCP
stdio
Run the protocol launcher directly:
npm run mcp:stdio
Example client configuration:
{
"mcpServers": {
"imagerouter": {
"command": "npm",
"args": ["run", "mcp:stdio"],
"cwd": "C:/absolute/path/to/ImageRouter"
}
}
}
The stdio launcher writes MCP protocol frames to stdout and diagnostics to stderr.
Streamable HTTP
Endpoint:
http://127.0.0.1:20127/mcp
Send the token shown in Settings:
Authorization: Bearer <ImageRouter token>
Example client configuration:
{
"mcpServers": {
"imagerouter": {
"url": "http://127.0.0.1:20127/mcp",
"headers": {
"Authorization": "Bearer ${IMAGEROUTER_TOKEN}"
}
}
}
}
Tools
generate_image accepts:
{
"prompt": "A precise image prompt",
"provider": "auto",
"model": "xai/grok-imagine-image-quality",
"reference_images": [],
"aspect_ratio": "16:9",
"output_path": "C:/optional/output.png",
"overwrite": false
}
providerdefaults toauto.modelmay be a plain model override orprovider/model, which pins that provider.- Without
output_path, image bytes are returned only in the MCP response. - With
output_path, exactly one file is written atomically. Existing files are protected unlessoverwriteistrue.
The response contains an MCP image block, a short text summary, and structured route metadata. get_image_router_status returns routes, capabilities, and redacted account health; it never returns credentials.
REST compatibility
curl http://127.0.0.1:20127/v1/images/generations \
-H "Authorization: Bearer $IMAGEROUTER_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"model": "auto",
"prompt": "A cobalt technical illustration on white paper",
"response_format": "b64_json"
}'
model accepts auto or provider/model. JSON responses follow the OpenAI image shape and add a router object with the actual provider/model and attempts. Set response_format to binary, or send Accept: image/*, to receive raw image bytes.
Routing semantics
- The first enabled route is the default.
autoexhausts enabled accounts for a provider in account-priority order before moving to the next route.- An explicit provider still tries its other accounts but never falls back to another provider.
- Cross-provider fallback occurs only for timeout, network, quota/rate-limit, token-refresh, capacity, and upstream 5xx failures.
- Invalid prompts/parameters, safety rejection, output-path errors, and capability mismatch do not cross-fallback.
- In
auto, an incompatible route is recorded as skipped and the next compatible route is tried.
Local data and privacy
Default data locations:
- Windows:
%APPDATA%/ImageRouter - macOS/Linux:
~/.imagerouter
Set IMAGEROUTER_DATA_DIR to use another location. ImageRouter never reads or modifies a legacy profile.
SQLite stores:
- encrypted provider credentials;
- route and account order;
- runtime settings;
- activity timestamp, provider/model, duration, status, fallback count, error code, and optional output path.
SQLite does not store prompts, image blobs, image base64, or generated previews. The Playground creates a temporary browser object URL and revokes it when replaced or unmounted.
The HTTP server binds to loopback, validates the Host and browser Origin, and requires a local bearer token on /mcp and /v1/images/generations.
Environment
See .env.example.
| Variable | Default | Purpose |
|---|---|---|
IMAGEROUTER_DATA_DIR |
Platform data directory | SQLite and credential-vault location. |
IMAGEROUTER_PORT |
Saved setting or 20127 |
Local dashboard, MCP HTTP, and REST port. |
IMAGEROUTER_MAX_BODY_SIZE |
32mb |
Next.js request body ceiling. |
IMAGEROUTER_PLAYWRIGHT_EXECUTABLE_PATH |
Auto-detected local browser | Optional existing Chromium/Chrome executable for E2E. |
IMAGEROUTER_ANTIGRAVITY_CLIENT_ID |
Empty | OAuth client ID for reconnecting Antigravity accounts. |
IMAGEROUTER_ANTIGRAVITY_CLIENT_SECRET |
Empty | OAuth client secret for reconnecting Antigravity accounts; never commit it. |
Development and tests
npm run lint
npm test
npm run build
npm run test:e2e
E2E uses an already-installed Chromium/Chrome executable when one is available; the test command does not install a browser.
Real-provider smoke tests are opt-in and may incur provider charges:
npm run test:smoke
They remain skipped unless the matching IMAGEROUTER_SMOKE_* credentials are present.
Architecture
server/providers/ xAI, Antigravity, Codex adapters
server/image/ validation, capabilities, routing, artifacts
server/mcp/ shared MCP factory, HTTP and stdio transports
server/rest/ OpenAI-compatible image endpoint
server/db/ minimal SQLite schema and encrypted credentials
src/app/ six-screen local workbench
tests/ unit, integration, E2E and opt-in smoke tests
Attribution
ImageRouter is an independent rewrite. Portions of the Antigravity and Codex adapter behavior were derived from the MIT-licensed decolua/9router project. See NOTICE.md for provenance.
License
MIT. See LICENSE.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。