image-gen-mcp

image-gen-mcp

Enables AI agents to generate images via multiple providers like OpenAI and Google, with automatic failover and configurable retry settings.

Category
访问服务器

README

image-gen-mcp

English | 中文

A multi-provider AI image generation MCP server that gives image generation capabilities to agents without them (e.g. Claude Code).

  • Unified abstraction: ImageProvider interface — adding a provider = one adapter file + one registry entry
  • Multi-provider failover: priority routing, retries, automatic fallback to the next provider until success or the max failover count
  • Three-layer config: defaults → environment variables → CLI args (args win)
  • SDK selection (by priority): official SDK → compatible SDK → fetch. Current state:
    • google — official @google/genai SDK (Gemini image models / Imagen)
    • openai / openrouter / grok / siliconflow / volcengine — official openai SDK
    • zhipu (CogView) / dashscope (Wan) — no active official Node SDK, but their image APIs are OpenAI-compatible, reusing the openai SDK (compatible-SDK path)
  • Output modes: url / base64 / file (saved locally), configurable globally or per call
  • Transport: stdio, installable via npx

Quick Start

# After publishing
npx @inferai/image-gen-mcp

# Local development
pnpm install && pnpm build
node dist/index.js

Configure it as a stdio MCP server in your client. Windows — Claude Desktop: %APPDATA%\Claude\claude_desktop_config.json; Claude Code: ~/.claude.json (C:\Users\<user>\.claude.json). cmd /c is required to resolve npx:

{
  "mcpServers": {
    "image-gen": {
      "command": "cmd",
      "args": ["/c", "npx", "-y", "@inferai/image-gen-mcp"],
      "env": {
        "IMAGE_MCP_OPENAI_API_KEY": "sk-...",
        "IMAGE_MCP_ZHIPU_API_KEY": "..."
      }
    }
  }
}

Linux / macOS — Claude Desktop: ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or ~/.config/Claude/claude_desktop_config.json (Linux); Claude Code: ~/.claude.json:

{
  "mcpServers": {
    "image-gen": {
      "command": "npx",
      "args": ["-y", "@inferai/image-gen-mcp"],
      "env": {
        "IMAGE_MCP_OPENAI_API_KEY": "sk-...",
        "IMAGE_MCP_ZHIPU_API_KEY": "..."
      }
    }
  }
}

Providers are auto-discovered: a provider is enabled iff its API key is configured — no provider list to maintain. Set IMAGE_MCP_<ID>_API_KEY (or --<id>-api-key) for exactly the providers you want.

Configuration

All settings follow a three-layer override: defaults → IMAGE_MCP_* env vars → --key=value args.

Global

Setting Env var args Default
Enabled providers — (auto-discovery) — Every provider with a configured API key, in registry order
Max retries (within one provider) IMAGE_MCP_MAX_RETRIES --max-retries 2
Max failovers IMAGE_MCP_MAX_DEGRADATIONS --max-degradations 1
Retry backoff base (ms, exponential) IMAGE_MCP_RETRY_BACKOFF_MS --retry-backoff-ms 1000
Request timeout (ms) IMAGE_MCP_REQUEST_TIMEOUT_MS --request-timeout-ms 60000
Output mode IMAGE_MCP_OUTPUT_MODE --output-mode url
Directory for file mode IMAGE_MCP_OUTPUT_DIR --output-dir ./output

Providers (<ID> per table below)

Env var args Notes
IMAGE_MCP_<ID>_API_KEY --<id>-api-key Required (provider is disabled without it)
IMAGE_MCP_<ID>_BASE_URL --<id>-base-url Overrides the default endpoint
IMAGE_MCP_<ID>_MODEL --<id>-model Overrides the default model
IMAGE_MCP_<ID>_PRIORITY --<id>-priority Lower number wins; defaults to registry order
ID Default endpoint Default model Notes
openai https://api.openai.com/v1 gpt-image-1 OpenAI
openrouter https://openrouter.ai/api/v1 none (model required at call time) Aggregator; model names like openai/gpt-image-1
grok https://api.x.ai/v1 grok-2-image xAI
siliconflow https://api.siliconflow.cn/v1 none (model required at call time) SiliconFlow
volcengine https://ark.cn-beijing.volces.com/api/v3 none (model = Ark endpoint id) ByteDance Volcano Ark (Doubao Seedream etc.)
zhipu https://open.bigmodel.cn/api/paas/v4 cogview-4-flash Zhipu CogView
dashscope https://dashscope.aliyuncs.com/compatible-mode/v1 wan2.7-image Alibaba Wan
google —(SDK-managed) gemini-2.5-flash-image Google Gemini / Imagen

Example (env vars):

export IMAGE_MCP_OPENAI_API_KEY=sk-...
export IMAGE_MCP_ZHIPU_API_KEY=...
export IMAGE_MCP_GOOGLE_API_KEY=...
export IMAGE_MCP_MAX_RETRIES=3
export IMAGE_MCP_MAX_DEGRADATIONS=2

Example (args override):

npx @inferai/image-gen-mcp \
  --openai-api-key=sk-... \
  --zhipu-api-key=... \
  --max-retries=0 \
  --max-degradations=1 \
  --output-mode=file \
  --output-dir=./images

MCP Tools

generate_image

Parameter Required Description
prompt ✓ Image content description
provider Explicit provider id (must be enabled); defaults to automatic priority routing
model Overrides the provider default model (required for providers without one)
size e.g. 1024x1024, passed through to the provider
n 1–4, number of images
outputMode url / base64 / file, overrides the global config

Returns JSON with the actual provider/model used and the full failover attempt log:

{
  "provider": "openai",
  "model": "gpt-image-1",
  "images": [{ "format": "url", "data": "https://...", "mimeType": "image/png" }],
  "attempts": [
    { "provider": "zhipu", "model": "cogview-4-flash", "status": "failed", "error": "429 rate limited" },
    { "provider": "openai", "model": "gpt-image-1", "status": "success" }
  ]
}
  • file mode: images are written to IMAGE_MCP_OUTPUT_DIR, the local absolute path is returned
  • url mode: base64 results are converted to data: URIs automatically

list_providers

Lists enabled providers (id / default model / endpoint / priority); no API key required.

Retry & Failover Semantics

Try providers in priority ascending order; within a provider: retryable errors
(network/timeout/429/5xx) retry with exponential backoff up to maxRetries,
non-retryable (401/400 etc.) fail it immediately; on provider failure fall back to
the next, up to maxDegradations times; total failure returns an error with the full
attempt summary.
  • max-retries=0: each provider is tried once
  • max-degradations=0: only the highest-priority provider is used
  • API keys are sanitized in all error messages and attempt logs

Development

pnpm install
pnpm dev        # rslib watch
pnpm test       # rstest unit tests
pnpm check      # biome format + lint
pnpm build      # build dist
node scripts/smoke.mjs   # stdio end-to-end smoke test (requires a configured key)

Integration tests need real API keys and are not part of the suite; verify manually:

IMAGE_MCP_OPENAI_API_KEY=sk-... node dist/index.js   # then call via an MCP client

Debugging with MCP Inspector:

pnpm dlx @modelcontextprotocol/inspector node dist/index.js --xxx-api-key=xxx --xxx2-api-key=xxx

Publishing

Publishing is automated (.github/workflows/publish.yml with the changesets/action select-mode flow): push to main creates a version PR, and merging it publishes to npm automatically.

pnpm changeset   # record changes (the only manual step), then merge the PR to main

pnpm release exists as a manual fallback. CI runs check + test + build on every PR; local git hooks (simple-git-hooks) run pnpm check pre-commit and pnpm format pre-push.

License

MIT

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选