OpenAI Image Generation MCP Server

Apache 2.0
2
  • Linux
  • Apple

Integrations

  • Enables image generation and editing using OpenAI's gpt-image-1 model, providing tools to create images from text prompts, edit existing images, and perform inpainting with masks.

  • Uses the OpenAI Python SDK to implement the image generation capabilities, allowing for programmatic access to OpenAI's image models through Python.

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 服务器。

安装

  1. 克隆存储库:
    git clone https://github.com/IncomeStreamSurfer/chatgpt-native-image-gen-mcp.git cd chatgpt-native-image-gen-mcp
  2. 设置虚拟环境(推荐):
    python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
  3. 安装依赖项:
    pip install -r requirements.txt
  4. **(可选但推荐)设置环境变量:**使用您的 OpenAI 密钥设置OPENAI_API_KEY环境变量,而不是将其硬编码在脚本中。如何设置取决于您的操作系统。

配置(适用于 Cline MCP 客户端)

为了使您的 AI 助手(如 Cline)可以使用此服务器,请将其配置添加到您的 MCP 设置文件(例如, cline_mcp_settings.json )。

在您的设置文件中找到mcpServers对象并添加以下条目:

{ "mcpServers": { // ... other server configurations ... "openai-image-gen-mcp": { "autoApprove": [ "generate_image", "edit_image" ], "disabled": false, "timeout": 180, // Increased timeout for potentially long image generation "command": "python", // Or path to python executable if not in PATH "args": [ // IMPORTANT: Replace this path with the actual absolute path // to the openai_image_mcp.py file on your system "C:/path/to/your/cloned/repo/chatgpt-native-image-gen-mcp/openai_image_mcp.py" ], "env": { // If using environment variables for the API key: // "OPENAI_API_KEY": "YOUR_API_KEY_HERE" }, "transportType": "stdio" } // ... other server configurations ... } }

**重要提示:**请将C:/path/to/your/cloned/repo/替换为您在计算机上克隆此仓库的正确绝对路径。请确保路径分隔符与您的操作系统匹配(例如,在 Windows 上使用反斜杠\ )。如果您通过环境变量设置了 API 密钥,则可以将其从脚本中移除,并在您的 MCP 客户端支持的情况下将其添加到此处的env部分。

运行服务器

通常情况下,您无需手动运行服务器。MCP 客户端(例如 Cline)会在首次调用其工具时,使用配置文件中指定的commandargs自动启动服务器。

如果您想手动测试它(确保依赖项已安装并且 API 密钥可用):

python openai_image_mcp.py

用法

AI 助手使用generate_imageedit_image工具与服务器交互。图像保存在openai_image_mcp.py脚本所在位置的ai-images子目录中。成功后,这两个工具会返回已保存图像的绝对路径。

-
security - not tested
A
license - permissive license
-
quality - not tested

通过 MCP 接口提供使用 OpenAI 的 gpt-image-1 模型生成和编辑图像的工具,使 AI 助手能够根据文本提示创建和修改图像。

  1. Features
    1. Prerequisites
      1. Installation
        1. Configuration (for Cline MCP Client)
          1. Running the Server
            1. Usage

              Related MCP Servers

              • A
                security
                A
                license
                A
                quality
                Enables the generation of images using Together AI's models through an MCP server, supporting customizable parameters such as model selection, image dimensions, and output directory.
                Last updated -
                1
                4
                JavaScript
                MIT License
                • Apple
                • Linux
              • A
                security
                A
                license
                A
                quality
                A MCP server that enables Claude and other MCP-compatible assistants to generate images from text prompts using Together AI's image generation models.
                Last updated -
                1
                2
                TypeScript
                MIT License
                • Apple
                • Linux
              • -
                security
                A
                license
                -
                quality
                A MCP server that integrates with Cursor IDE to generate images based on text descriptions using JiMeng AI, allowing users to create and save custom images directly within their development environment.
                Last updated -
                82
                Python
                MIT License
                • Apple
                • Linux
              • -
                security
                F
                license
                -
                quality
                An MCP server that allows users to generate, edit, and create variations of images through OpenAI's DALL-E API, supporting both DALL-E 2 and DALL-E 3 models.
                Last updated -
                2
                TypeScript

              View all related MCP servers

              ID: bm6a8lqog0