2Xapi.com GPT-image MCP Server
Generates images via OpenAI-compatible text-to-image APIs, with configurable endpoints, models, sizes, and optional AI moderation.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@2Xapi.com GPT-image MCP Server Generate an image of a cozy cabin in the snowy mountains at sunset."
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
2Xapi.com GPT-image MCP Server
把 OpenAI 兼容的文生图/图生图接口封装成 MCP 工具。接入 Claude Code / Codex / Cursor / Claude Desktop 等客户端后,对话里说「画一只柴犬」就能出图,发一张图说「改成动漫风」就能改图。每位用户使用自己的 API Key,消耗计费到各自账号。
效果演示
左:generate_image 文生图(「一只可爱的橘猫,坐在窗台上,简单插画风格」);中/右:对左图用 edit_image 图生图改风格(全部为真实调用输出)。
文生图 | 图生图 · 改水彩风 + 樱花 | 图生图 · 改水墨风 |
|
|
|
Related MCP server: image-gen-mcp
核心功能
🎨 文生图
generate_image:文字描述生成图片,返回图片 URL + 结构化结果✏️ 图生图
edit_image:传 1-10 张图 + 文字指令,改风格 / 合成 / 扩图(走/images/edits,multipart 上传)🖼 mask 局部重绘:可选 mask 图(alpha 通道 PNG,透明区域=重绘区),只改指定区域
📥 四种图片输入:本地文件路径 / http(s) URL /
data:URI / 裸 base64(URL 自动下载再上传)🛡 输入安全校验:单文件 ≤50MB;本地路径白名单(
IMAGE_ALLOWED_ROOTS,默认仅主目录);npm 版用 sharp 校验真实格式(扩展名不符自动纠正),超 4MB 或 1024px 自动压缩后上传🔐 API Key 脱敏:错误信息里的 key 自动打码;配置查看时只显示掩码
🚦 AI 审核闸门(可选):提示词先过审核模型再进生图账号,减少风控/封号(fail-open,审核服务不可达时自动放行)
⚙️ 对话内配置:
set_config/set_moderation改端点、key、模型、尺寸,立即生效,无需重启📊 结构化结果:
structuredContent返回文件路径 +file://URI + usage 用量(include_preview=true可选附加内联 JPEG 预览;默认关闭,避免部分 Responses 流式客户端报错)
使用方法
接入客户端后,直接用自然语言对话即可,AI 会自动选工具:
你说 | 调用 |
「画一只柴犬,竖图」 |
|
「画 3 张星空壁纸」 |
|
「把这张图改成动漫风」(发图或给路径) |
|
「把这两张图合成一张」 |
|
「只重绘帽子区域」(提供 mask 图) |
|
「查看当前配置」 |
|
「模型换成 dall-e-3」 |
|
「更新 key 为 sk-yyy」 |
|
「列出后端有哪些模型」 |
|
mask 说明:alpha 通道 PNG,透明区域 = 重绘区,不透明 = 保留;需后端支持(2xapi.com 中转站已验证支持)。
一键安装(npm 版,推荐)
前提:Node.js 18+。发布到 GitHub Releases 后:
Claude Code
claude mcp add -s user gpt-image \
--env IMAGE_API_KEY=你的key \
-- npx -y https://github.com/wenkezhi8/2Xapi.com-GPT-image-MCP-Server/releases/download/v0.3.1/gpt-image-mcp-server-0.3.1.tgzCodex
codex mcp add GPT-image \
--env IMAGE_API_KEY=你的key \
-- npx -y https://github.com/wenkezhi8/2Xapi.com-GPT-image-MCP-Server/releases/download/v0.3.1/gpt-image-mcp-server-0.3.1.tgzClaude Desktop / Cursor(手动配置)
{
"mcpServers": {
"GPT-image": {
"command": "npx",
"args": ["-y", "https://github.com/wenkezhi8/2Xapi.com-GPT-image-MCP-Server/releases/download/v0.3.1/gpt-image-mcp-server-0.3.1.tgz"],
"env": {
"IMAGE_API_KEY": "你的key"
}
}
}
}🤖 AI 一键部署:把仓库地址发给任何 AI(Codex / Claude),它会读
AGENTS.md自动完成部署⚡ 一键脚本(二选一):
./install.sh(需先发布 GitHub Release):IMAGE_API_KEY=你的key ./install.sh,自动检测 claude/codex 并接入./deploy.sh(本地构建,不依赖 Release):./deploy.sh --client codex --key 你的key
📄 部署文档:
GPT-image MCP Server部署文档.md(约 5 分钟,含给 AI 的提示词模板)🐍 Python 版:
src/(手动部署用,支持uvx/uv run,零额外依赖;预览功能需另装 Pillow)⚡ npm 版:
gpt-image-mcp-server/(一键安装,推荐)
环境变量
变量 | 作用 | 必填 |
| 你自己的 API Key(计费到你的账号) | ✅ |
| 覆盖接口根地址(到 | 按需 |
| 覆盖配置文件保存路径(默认 | 按需 |
| 允许读取的本地图片路径白名单( | 按需 |
key 与端点必须配套:你的 key 是哪家供应商的,端点就填哪家的。
默认端点说明
本项目默认端点:
https://2xa.cc.cd/v1—— 这是 2xapi.com 中转站的 OpenAI 兼容生图接口(官网 https://2Xapi.com),本 MCP 默认配套的就是这个方案。使用 2xapi.com 中转站的 API Key 可直接运行,无需配置端点。
如果想使用其他 API 端点(OpenAI 官方、Azure、其他中转站等),需要自己更换:
一键安装/npx 方式:设置环境变量
IMAGE_API_BASE_URL=https://你的端点/v1Python 版:修改
config.json的api_base_url字段更换后 key 必须与该端点配套,否则报 401。
工具
工具 | 作用 |
| 文生图,返回图片 URL(可自动存本地) |
| 图生图(图文生图):传 1-10 张图 + 文字指令,改图 / 合成 / 扩图;支持 mask 局部重绘 |
| 查看当前配置(API Key 自动打码) |
| 对话里改端点 / key / 模型 / 尺寸,立即生效 |
| 配置 AI 审核闸门(可选,fail-open) |
| 列出后端可用模型 |
目录结构
.
├── docs/images/ ← README 演示配图
├── GPT-image MCP Server部署文档.md ← 部署文档(必读)
├── gpt-image-mcp-server/ ← npm 版(TypeScript,一键安装)
├── src/ ← Python 版(uvx/uv run)
├── pyproject.toml / uv.lock
└── LICENSE安全
config.json含真实 API Key,已被.gitignore排除,不要提交、不要外发。分发代码前删除
config.json;只保留config.example.json模板。
Available Tools
6 toolsedit_imageEdit image(s) (img2img)A
Edit, transform, combine or extend one or more input images following a text prompt (image + text to image, aka img2img) via the configured OpenAI-compatible images/edits API. Each image reference can be a local file path, an http(s) URL, a data: URI, or raw base64. An optional mask marks the region to regenerate. Returns the edited image URL(s) and metadata; optionally saves locally. Endpoint, key and default model come from config (see get_config / set_config).
Inputs: images (required), prompt (required), n, mask, +5 more.
generate_imageGenerate image (GPT-image)A
Generate one or more images from a text prompt via the configured OpenAI-compatible image API. Endpoint, key and default model come from config (see get_config / set_config); per-call args override them. Returns the image URL, and the local path if save_dir is set or save=true.
Inputs: prompt (required), n, save, size, +3 more.
get_configShow GPT-image configA
Show the current GPT-image configuration: API endpoint, model, default size, save directory, and config file path. The API key is masked. Use set_config to change any of these values.
Inputs: no named parameters. Returns: result
list_image_modelsList backend modelsA
List the models exposed by the configured image backend (GET /models).
Inputs: no named parameters. Returns: result
set_configUpdate GPT-image configA
Update one or more GPT-image settings and persist them to the config file. Any field left null/omitted is unchanged. Changes take effect immediately for subsequent generate_image calls — no restart needed. Fields: api_base_url, api_key, model, size, save_dir.
Inputs: size, model, api_key, save_dir, +1 more. Returns: result
set_moderationConfigure pre-generation moderationA
Configure the moderation gate that screens every prompt BEFORE it reaches the image API. When enabled, prompts judged as disallowed are rejected to protect the account from risk control. Any argument left null is unchanged. Changes persist to config.json and take effect immediately. Pass enabled=false to turn moderation off.
Inputs: model, prompt, api_key, enabled, +1 more. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 6 tools
Each tool has a clearly distinct purpose: configuration get/set, moderation control, image generation, image editing, and model listing. There is no meaningful overlap or ambiguity between tool boundaries.
All tools follow a consistent verb_noun snake_case pattern: get_config, set_config, set_moderation, generate_image, edit_image, list_image_models. Verb choice and naming style are uniform throughout.
Six tools is well-scoped for an image generation MCP server: configuration, moderation, generation, editing, and model discovery. Each tool earns its place without unnecessary bloat or missing essentials.
The core workflow is covered: configuring the backend, generating images, editing images, and listing available models. The only minor gap is that get_config does not explicitly expose current moderation settings, though set_moderation persists them to config.json.
Maintenance
Related MCP Connectors
Generate images from Claude, ChatGPT, Cursor and Codex with 12 top AI image models. Up to 4 images per call, SVG vectorization, background removal, upscaling and image-to-video. Remote MCP with OAuth, no API keys.
Generate images from Claude, ChatGPT, Cursor and Codex with 12 top AI image models and 10 tools: up to 4 images per call, SVG vectorization, editing and more. Remote MCP with OAuth, no API keys. Pay per image, no subscription.
Use AI models for chat, image, and video generation from Claude Code and other MCP hosts.
Create images & video from any MCP agent — 17 models, spend limits, one URL.
Related MCP Servers
- AlicenseAqualityCmaintenanceGenerates and edits images via Gemini, Grok, and GPT-image providers for MCP clients like Claude Code that lack native image generation.320 npmMIT
- AlicenseAqualityDmaintenanceEnables LLMs to generate images via MCP by calling AI models from providers like SiliconFlow, OpenAI, or custom APIs, with tools for image generation and model listing.2MIT
- AlicenseNot gradedqualityCmaintenanceEnables coding agents and other MCP clients to generate images from text prompts and edit, restyle, or extend existing images through an OpenAI-compatible /v1/images API. Results are returned both inline as image content blocks and as files saved to disk, so agents can view and reuse them within a normal task.2MIT
- AlicenseAqualityCmaintenanceEnables MCP-compatible coding agents to generate and edit images from text prompts or local files, returning both a saved file path and an inline image block. Supports up to four sequential images per call, model listing, and one-command setup across OMP, Codex, Claude Code, Cursor, and opencode.314 npmMIT


