Skip to main content

OpenAI Image Generation MCP Server - provides tools for generating and editing images using OpenAI's gpt-image-1 model

Project description

OpenAI Image Generation MCP Server

This project implements an MCP (Model Context Protocol) server that provides tools for generating and editing images using OpenAI's gpt-image-1 model via the official Python SDK.

Features

This MCP server provides the following tools:

  • generate_image: Generates an image using OpenAI's gpt-image-1 model based on a text prompt and saves it.

    • Input Schema:
      {
        "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"]
      }
      
    • Output: {"status": "success", "saved_path": "path/to/image.png"} or error dictionary.
  • edit_image: Edits an image or creates variations using OpenAI's gpt-image-1 model and saves it. Can use multiple input images as reference or perform inpainting with a mask.

    • Input Schema:
      {
        "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"]
      }
      
    • Output: {"status": "success", "saved_path": "path/to/image.png"} or error dictionary.

Prerequisites

  • Python (3.8 or later recommended)
  • pip (Python package installer)
  • An OpenAI API Key (set directly in the script or via the OPENAI_API_KEY environment variable - using environment variables is strongly recommended for security).
  • An MCP client environment (like the one used by Cline) capable of managing and launching MCP servers.

Installation

  1. Clone the repository:
    git clone https://github.com/IncomeStreamSurfer/chatgpt-native-image-gen-mcp.git
    cd chatgpt-native-image-gen-mcp
    
  2. Set up a virtual environment (Recommended):
    python -m venv venv
    source venv/bin/activate  # On Windows use `venv\Scripts\activate`
    
  3. Install dependencies:
    pip install -r requirements.txt
    
  4. (Optional but Recommended) Set Environment Variable: Set the OPENAI_API_KEY environment variable with your OpenAI key instead of hardcoding it in the script. How you set this depends on your operating system.

Configuration (for Cline MCP Client)

To make this server available to your AI assistant (like Cline), add its configuration to your MCP settings file (e.g., cline_mcp_settings.json).

Find the mcpServers object in your settings file and add the following entry:

{
  "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 ...
  }
}

Important: Replace C:/path/to/your/cloned/repo/ with the correct absolute path to where you cloned this repository on your machine. Ensure the path separator is correct for your operating system (e.g., use backslashes \ on Windows). If you set the API key via environment variable, you can remove it from the script and potentially add it to the env section here if your MCP client supports it.

Running the Server

You don't typically need to run the server manually. The MCP client (like Cline) will automatically start the server using the command and args specified in the configuration file when one of its tools is called for the first time.

If you want to test it manually (ensure dependencies are installed and API key is available):

python openai_image_mcp.py

Usage

The AI assistant interacts with the server using the generate_image and edit_image tools. Images are saved within an ai-images subdirectory created where the openai_image_mcp.py script is located. The tools return the absolute path to the saved image upon success.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file iflow_mcp_incomestreamsurfer_chatgpt_native_image_gen_mcp-0.1.0.tar.gz.

File metadata

  • Download URL: iflow_mcp_incomestreamsurfer_chatgpt_native_image_gen_mcp-0.1.0.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for iflow_mcp_incomestreamsurfer_chatgpt_native_image_gen_mcp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f7cde19a1848e54eae7c60f0d48fbc289d5c8de6bfeedafce34a2a7ed62e8f6d
MD5 cf9b6e2d530b1acf812d71bee4116f51
BLAKE2b-256 8c1fab094acc7d0c90b064698aa4fd8247d5c1a9fff2c77a5bf5935a9748c9f4

See more details on using hashes here.

File details

Details for the file iflow_mcp_incomestreamsurfer_chatgpt_native_image_gen_mcp-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: iflow_mcp_incomestreamsurfer_chatgpt_native_image_gen_mcp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for iflow_mcp_incomestreamsurfer_chatgpt_native_image_gen_mcp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c5ab81c39758602b11e5adeaca6c8aaa83309766b7b67e507497277881d7f549
MD5 73c5aa11667116f1e39b3857aa4eed9d
BLAKE2b-256 af716f68649a6e5e6b8f4bb4c4b3ee5977f5ffcd9d12ebcc7244037d44fd5943

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page