OpenAI 图像生成 MCP 服务器
该项目实现了一个 MCP(模型上下文协议)服务器,该服务器通过官方 Python SDK 提供使用 OpenAI 的gpt-image-1模型生成和编辑图像的工具。
特征
该 MCP 服务器提供以下工具:
generate_image:根据文本提示,使用 OpenAI 的gpt-image-1模型生成图像并保存。输入模式:
{ "type": "object", "properties": { "prompt": { "type": "string", "description": "The text description of the desired image(s)." }, "model": { "type": "string", "default": "gpt-image-1", "description": "The model to use (currently 'gpt-image-1')." }, "n": { "type": ["integer", "null"], "default": 1, "description": "The number of images to generate (Default: 1)." }, "size": { "type": ["string", "null"], "enum": ["1024x1024", "1536x1024", "1024x1536", "auto"], "default": "auto", "description": "Image dimensions ('1024x1024', '1536x1024', '1024x1536', 'auto'). Default: 'auto'." }, "quality": { "type": ["string", "null"], "enum": ["low", "medium", "high", "auto"], "default": "auto", "description": "Rendering quality ('low', 'medium', 'high', 'auto'). Default: 'auto'." }, "user": { "type": ["string", "null"], "default": null, "description": "An optional unique identifier representing your end-user." }, "save_filename": { "type": ["string", "null"], "default": null, "description": "Optional filename (without extension). If None, a default name based on the prompt and timestamp is used." } }, "required": ["prompt"] }输出:
{"status": "success", "saved_path": "path/to/image.png"}或错误字典。
edit_image:使用 OpenAI 的gpt-image-1模型编辑图像或创建变体并保存。可以使用多张输入图像作为参考,或使用遮罩进行修复。输入模式:
{ "type": "object", "properties": { "prompt": { "type": "string", "description": "The text description of the desired final image or edit." }, "image_paths": { "type": "array", "items": { "type": "string" }, "description": "A list of file paths to the input image(s). Must be PNG. < 25MB." }, "mask_path": { "type": ["string", "null"], "default": null, "description": "Optional file path to the mask image (PNG with alpha channel) for inpainting. Must be same size as input image(s). < 25MB." }, "model": { "type": "string", "default": "gpt-image-1", "description": "The model to use (currently 'gpt-image-1')." }, "n": { "type": ["integer", "null"], "default": 1, "description": "The number of images to generate (Default: 1)." }, "size": { "type": ["string", "null"], "enum": ["1024x1024", "1536x1024", "1024x1536", "auto"], "default": "auto", "description": "Image dimensions ('1024x1024', '1536x1024', '1024x1536', 'auto'). Default: 'auto'." }, "quality": { "type": ["string", "null"], "enum": ["low", "medium", "high", "auto"], "default": "auto", "description": "Rendering quality ('low', 'medium', 'high', 'auto'). Default: 'auto'." }, "user": { "type": ["string", "null"], "default": null, "description": "An optional unique identifier representing your end-user." }, "save_filename": { "type": ["string", "null"], "default": null, "description": "Optional filename (without extension). If None, a default name based on the prompt and timestamp is used." } }, "required": ["prompt", "image_paths"] }输出:
{"status": "success", "saved_path": "path/to/image.png"}或错误字典。
先决条件
Python(建议使用 3.8 或更高版本)
pip(Python 包安装程序)
OpenAI API 密钥(直接在脚本中设置或通过
OPENAI_API_KEY环境变量设置 -强烈建议使用环境变量以确保安全)。MCP 客户端环境(如 Cline 使用的环境)能够管理和启动 MCP 服务器。
安装
克隆存储库:
git clone https://github.com/IncomeStreamSurfer/chatgpt-native-image-gen-mcp.git cd chatgpt-native-image-gen-mcp设置虚拟环境(推荐):
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`安装依赖项:
pip install -r requirements.txt**(可选但推荐)设置环境变量:**使用您的 OpenAI 密钥设置
OPENAI_API_KEY环境变量,而不是将其硬编码在脚本中。如何设置取决于您的操作系统。
配置(适用于 Cline MCP 客户端)
为了使您的 AI 助手(如 Cline)可以使用此服务器,请将其配置添加到您的 MCP 设置文件(例如, cline_mcp_settings.json )。
在您的设置文件中找到mcpServers对象并添加以下条目:
**重要提示:**请将C:/path/to/your/cloned/repo/替换为您在计算机上克隆此仓库的正确绝对路径。请确保路径分隔符与您的操作系统匹配(例如,在 Windows 上使用反斜杠\ )。如果您通过环境变量设置了 API 密钥,则可以将其从脚本中移除,并在您的 MCP 客户端支持的情况下将其添加到此处的env部分。
运行服务器
通常情况下,您无需手动运行服务器。MCP 客户端(例如 Cline)会在首次调用其工具时,使用配置文件中指定的command和args自动启动服务器。
如果您想手动测试它(确保依赖项已安装并且 API 密钥可用):
用法
AI 助手使用generate_image和edit_image工具与服务器交互。图像保存在openai_image_mcp.py脚本所在位置的ai-images子目录中。成功后,这两个工具会返回已保存图像的绝对路径。
This server cannot be installed
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
通过 MCP 接口提供使用 OpenAI 的 gpt-image-1 模型生成和编辑图像的工具,使 AI 助手能够根据文本提示创建和修改图像。
Related MCP Servers
- Asecurity-licenseAqualityAllows AI assistants to generate and transform high-quality images from text prompts using Google's Gemini model via the MCP protocol.Last updated -323MIT License
- -security-license-qualityAn MCP tool server that enables generating and editing images through OpenAI's image models, supporting text-to-image generation and advanced image editing (inpainting, outpainting) across various MCP-compatible clients.Last updated -75MIT License
- Asecurity-licenseAqualityAn MCP server that allows Claude to use OpenAI's image generation capabilities (gpt-image-1) to create image assets for users, which is particularly useful for game and web development projects.Last updated -113MIT License
- Asecurity-licenseAqualityA Model Context Protocol server that enables generating and editing images using OpenAI's gpt-image-1 model, allowing AI assistants to create and modify images from text prompts.Last updated -24516MIT License