使用说明
openai图像mcp服务器
用于OpenAI图像生成的MCP服务器。使用gpt图像模型族生成、编辑和创建图像变体(gpt-image-1, gpt-image-1-mini, gpt-image-1.5, gpt-image-2)--直接从任何兼容MCP的客户端,如Claude Desktop、Cursor或VS Code。
DALL-E 2 / DALL-E 3 已删除。 OpenAI于2026年5月12日退役了两款DALL-E模型。此服务器现在仅针对gpt映像系列。这
gpt_image_create_variation该工具在编辑端点之上重新实现,因为/v1/images/variations终点随着DALL-E 2的消失而消失。
工具
| 工具 | 说明 |
|---|---|
gpt_image_generate |
从文本提示生成图像 |
gpt_image_edit |
使用修复/遮罩编辑现有图像 |
gpt_image_create_variation |
创建图像的风格变体(通过编辑端点) |
gpt_image_create_character_reference |
为游戏角色生成基础参考图像 |
gpt_image_generate_pose |
从角色参考图像生成任何姿势/动作 |
gpt_image_generate_sprite_sheet |
生成多帧子画面(便利包装) |
需求
- Node.js 18+
- 一 OpenAI API密钥
安装
克劳德桌面版
添加 ~/Library/Application Support/Claude/claude_desktop_config.json (macOS)或 %APPDATA%\Claude\claude_desktop_config.json (Windows):
{
"mcpServers": {
"gpt-image-gen": {
"command": "npx",
"args": ["-y", "openai-image-mcp-server@latest"],
"env": {
"OPENAI_API_KEY": "sk-..."
}
}
}
}
光标
添加到光标MCP设置(~/.cursor/mcp.json):
{
"mcpServers": {
"gpt-image-gen": {
"command": "npx",
"args": ["-y", "openai-image-mcp-server@latest"],
"env": {
"OPENAI_API_KEY": "sk-..."
}
}
}
}
VS代码(带副驾驶MCP扩展)
添加到您的VS代码 settings.json:
{
"mcp.servers": {
"gpt-image-gen": {
"command": "npx",
"args": ["-y", "openai-image-mcp-server@latest"],
"env": {
"OPENAI_API_KEY": "sk-..."
}
}
}
}
克劳德代码
添加 ~/.claude/settings.json:
{
"env": {
"OPENAI_API_KEY": "sk-..."
},
"mcpServers": {
"openai-image": {
"command": "npx",
"args": ["-y", "openai-image-mcp-server"]
}
}
}
或者通过CLI:
claude mcp add openai-image -e OPENAI_API_KEY=sk-... -- npx -y openai-image-mcp-server@latest
手册(来源)
git clone https://github.com/YOUR_USERNAME/openai-image-mcp-server
cd openai-image-mcp-server
npm install
npm run build
OPENAI_API_KEY=sk-... node dist/index.js
工具参考
gpt_image_generate
从文本提示生成一个或多个图像。
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
prompt |
string | 必填 | 图像的文本描述 |
model |
gpt-image-1 |
gpt-image-1-mini |
gpt-image-1.5 |
n |
数字(1-10) | 1 |
图像数量 |
size |
1024x1024 |
1024x1536 |
1536x1024 |
quality |
low |
medium |
high |
background |
transparent |
opaque |
auto |
output_format |
png |
jpeg |
webp |
output_compression |
数字(0-100) | -- | jpeg/webp压缩 |
output_directory |
字符串 | ./openai-image-gen |
保存文件的目录 |
图像总是以base64数据的形式返回并写入磁盘。gpt图像模型不生成URL。
示例:
Generate a photorealistic portrait of a tabby cat sitting on a windowsill
Generate a wide cinematic shot of a foggy mountain valley at sunrise
→ model: gpt-image-2, size: 1536x1024, quality: high
Generate a glowing magic crystal with transparent background
→ background: transparent, output_format: png
gpt_image_edit
使用文本提示编辑现有图像。支持使用可选遮罩进行修复——遮罩中的透明像素定义了要编辑的区域。
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
image_path |
string | 必填 | 源PNG的绝对路径(<25 MB,自动调整大小) |
prompt |
string | 必填 | 所需编辑的描述 |
mask_path |
string | -- | 屏蔽PNG的绝对路径(透明=编辑区) |
model |
gpt-image-1 |
gpt-image-1-mini |
gpt-image-1.5 |
n |
数字(1-10) | 1 |
结果数量 |
size |
1024x1024 |
1024x1536 |
1536x1024 |
quality |
low |
medium |
high |
background |
transparent |
opaque |
auto |
output_format |
png |
jpeg |
webp |
output_compression |
数字(0-100) | -- | jpeg/webp压缩 |
output_directory |
字符串 | ./openai-image-gen |
保存文件的目录 |
示例:
Edit /photos/room.png → "Add a potted plant near the window"
Edit /photos/portrait.png with mask /photos/mask.png → "Replace background with a sunny beach"
gpt_image_create_variation
创建现有图像的艺术变体。
在编辑端点之上实现,因为传统 /v1/images/variations 终点于2026年5月12日用DALL-E 2退役。通过 variation_prompt 对于有针对性的变体,或依赖默认的“风格变体”提示。
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
image_path |
string | 必需 | 源PNG的绝对路径(<25 MB) |
variation_prompt |
string | 内置默认值 | 描述变量的自定义指令 |
model |
gpt-image-1 |
gpt-image-1-mini |
gpt-image-1.5 |
n |
数字(1-10) | 1 |
变化次数 |
size |
1024x1024 |
1024x1536 |
1536x1024 |
quality |
low |
medium |
high |
output_format |
png |
jpeg |
webp |
output_compression |
数字(0-100) | -- | jpeg/webp压缩 |
output_directory |
字符串 | ./openai-image-gen |
保存文件的目录 |
示例:
Create 3 variations of /art/original.png
→ n: 3, output_directory: /art/variations
Reinterpret /photo.png as oil painting with warm sunset tones
→ variation_prompt: "Reinterpret as oil painting with warm sunset tones"
gpt_image_create_character_reference
在透明背景上为游戏角色生成基础参考图像。在生成任何姿势之前,请将此作为第一步。
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
character_description |
string | 必填 | 完整的外观描述。最多3000个字符。 |
output_path |
string | 必需 | 输出PNG的绝对路径 |
quality |
low |
medium |
high |
bg_threshold |
数字(0-255) | 240 |
背景移除阈值 |
例子:
Create a character reference for a cute chibi goose
→ character_description: "cute chibi goose, white feathers, orange beak, blue sailor hat, red bow tie"
output_path: /project/assets/sprites/goose_ref.png
gpt_image_generate_pose
使用参考图像生成特定的姿势或动作帧,以实现视觉一致性。
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
reference_image_path |
string | 必需 | 引用PNG的路径 gpt_image_create_character_reference |
character_description |
string | 必填 | 与引用使用的描述相同 |
pose_description |
string | 必填 | 自由文本姿势或动作。最多1000个字符。 |
output_path |
string | 必需 | 输出PNG的绝对路径 |
quality |
low |
medium |
high |
bg_threshold |
数字(0-255) | 240 |
背景移除阈值 |
示例姿势:
"walking with left foot forward""crying, tears streaming down face""jumping with both arms raised""attacking, swinging sword to the right""sitting cross-legged""waving hello"
gpt_image_generate_sprite_sheet
便利包装器:在内部生成一个引用,然后生成所有请求的姿势并将其组装到一个小角色表中。要获得更多控制,请使用 gpt_image_create_character_reference + gpt_image_generate_pose 直接。
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
character_description |
string | 必填 | 字符的外观。最多3000个字符。 |
poses |
string[] | 3帧步行周期 | 每帧的姿势描述列表 |
output_path |
string | required | 输出子画面PNG的绝对路径 |
quality |
low |
medium |
high |
bg_threshold |
数字(0-255) | 240 |
背景移除阈值 |
frame_gap |
编号 | 0 |
帧之间的像素间隙 |
它是如何工作的:
- 生成一个中性参考系
gpt-image-1 - 使用带有引用的编辑API生成每个请求的姿势
- 删除背景(从边缘进行泛色填充,保留白色字符部分)
- 将每个框架裁剪至内容物,并将衬垫裁剪至统一尺寸
- 将所有帧水平合成为一个透明的PNG
示例:
3-frame walk cycle (default)
→ character_description: "chibi knight in silver armor with red cape"
output_path: /sprites/knight_walk.png
Custom poses
→ character_description: "cute chibi goose, white feathers, blue sailor hat, red bow tie"
poses: ["walking left foot forward", "waving hello", "sitting down"]
output_path: /sprites/goose_actions.png
Aggressive background removal for a character with light-colored clothing
→ character_description: "white-robed healer with golden halo"
output_path: /sprites/healer.png
bg_threshold: 200
提示: 越具体你
character_description,3帧越一致。包括艺术风格(如“像素艺术”、“赤壁”、“平面卡通”)、颜色细节和任何独特的配饰。
模型比较
| gpt-image 1 | gpt-image 1-mini | gpt-image1.5 | gpt-mage2 | |
|---|---|---|---|---|
| 生成 | ✓ | ✓ | ✓ | ✓ |
| 编辑 | ✓ | ✓ | ✓ | ✓ |
| 变化(通过编辑) | ✓ | ✓ | ✓ | ✓ |
| 透明背景 | ✓ | ✓ | ✓ | ✗ |
| 尺寸 | 1024²/1024×1536/1536×1024 | 相同 | 相同 | 灵活(≤3840px,16px倍数) |
| 输出格式 | png/jpeg/webp | same | same | 相同 |
| 最适合 | 传统 | 经济高效的批量 | 快速+透明bg | 默认 ·最先进的质量,文本渲染 |
将图像保存到磁盘
所有gpt图像模型都返回base64数据(无URL)。生成的图像会自动写入磁盘--pass output_directory 自定义位置,否则文件将进入 ./openai-image-gen.
Generate a sunset landscape and save it
→ output_directory: /Users/me/Desktop
文件另存为 generated_<timestamp>_<n>.<ext>, edited_<timestamp>_<n>.<ext>,或 variation_<timestamp>_<n>.<ext> 哪里 <ext> 火柴 output_format (默认值 png).
许可证
麻省理工学院