2Xapi.com GPT-image MCP Server
Wraps OpenAI-compatible text-to-image APIs as MCP tools, enabling image generation directly from conversations in Claude Code, Codex, Cursor, or Claude Desktop using the user's own API key.
README
2Xapi.com GPT-image MCP Server
把 OpenAI 兼容的文生图接口封装成 MCP 工具。接入 Claude Code / Codex / Cursor / Claude Desktop 等客户端后,对话里说「画一只柴犬」就能出图。每位用户使用自己的 API 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) - ⚡ npm 版:
gpt-image-mcp-server/(一键安装,推荐)
一键安装(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.1.0/gpt-image-mcp-server-0.1.0.tgz
Codex
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.1.0/gpt-image-mcp-server-0.1.0.tgz
Claude Desktop / Cursor(手动配置)
{
"mcpServers": {
"GPT-image": {
"command": "npx",
"args": ["-y", "https://github.com/wenkezhi8/2Xapi.com-GPT-image-MCP-Server/releases/download/v0.1.0/gpt-image-mcp-server-0.1.0.tgz"],
"env": {
"IMAGE_API_KEY": "你的key"
}
}
}
}
环境变量
| 变量 | 作用 | 必填 |
|---|---|---|
IMAGE_API_KEY |
你自己的 API Key(计费到你的账号) | ✅ |
IMAGE_API_BASE_URL |
覆盖接口根地址(到 /v1);默认用内置端点 |
按需 |
IMAGE_CONFIG_PATH |
覆盖配置文件保存路径(默认 ~/.gpt-image-mcp/config.json) |
按需 |
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://你的端点/v1 - Python 版:修改
config.json的api_base_url字段 - 更换后 key 必须与该端点配套,否则报 401。
- 一键安装/npx 方式:设置环境变量
工具
| 工具 | 作用 |
|---|---|
generate_image |
文生图,返回图片 URL(可自动存本地) |
get_config |
查看当前配置(API Key 自动打码) |
set_config |
对话里改端点 / key / 模型 / 尺寸,立即生效 |
set_moderation |
配置 AI 审核闸门(可选,fail-open) |
list_image_models |
列出后端可用模型 |
目录结构
.
├── 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模板。
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
Neon Database
MCP server for interacting with Neon Management API and databases
E2B
Using MCP to run code via e2b.
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.