OpenAI Image Generation MCP server

Provides tools for generating and editing images using OpenAI's gpt-image-1 model, handling API interactions, error management, and local image storage.
Back to servers
Provider
IncomeStreamSurfer
Release date
Apr 30, 2025
Language
Python
Stats
14 stars

This MCP server provides an interface to OpenAI's image generation capabilities through the Model Context Protocol, allowing AI assistants to generate and edit images using the GPT-4 Vision model via the official OpenAI Python SDK.

Installation

Prerequisites

  • Python 3.8 or later
  • pip (Python package installer)
  • An OpenAI API Key
  • An MCP client environment (such as Cline)

Setting Up the Server

  1. Clone the repository:

    git clone https://github.com/IncomeStreamSurfer/chatgpt-native-image-gen-mcp.git
    cd chatgpt-native-image-gen-mcp
    
  2. Create and activate a virtual environment:

    python -m venv venv
    source venv/bin/activate  # On Windows use: venv\Scripts\activate
    
  3. Install required dependencies:

    pip install -r requirements.txt
    
  4. Set up your OpenAI API key:

    It's recommended to set this as an environment variable:

    • On Linux/Mac:
      export OPENAI_API_KEY="your-api-key-here"
      
    • On Windows (Command Prompt):
      set OPENAI_API_KEY=your-api-key-here
      
    • On Windows (PowerShell):
      $env:OPENAI_API_KEY="your-api-key-here"
      

Configuration

Setting Up with Cline MCP Client

Add the server configuration to your MCP settings file (typically cline_mcp_settings.json):

{
  "mcpServers": {
    "openai-image-gen-mcp": {
      "autoApprove": [
        "generate_image",
        "edit_image"
      ],
      "disabled": false,
      "timeout": 180,
      "command": "python",
      "args": [
        "/absolute/path/to/chatgpt-native-image-gen-mcp/openai_image_mcp.py"
      ],
      "transportType": "stdio"
    }
  }
}

Be sure to replace /absolute/path/to/ with the actual path to your cloned repository.

Usage

The MCP server provides two primary tools for image generation and editing:

Generate Image

Creates images from text prompts using OpenAI's GPT-4 Vision model.

Parameters:

  • prompt (required): Text description of the desired image
  • model: The model to use (default: "gpt-image-1")
  • n: Number of images to generate (default: 1)
  • size: Image dimensions - "1024x1024", "1536x1024", "1024x1536", or "auto" (default: "auto")
  • quality: Rendering quality - "low", "medium", "high", or "auto" (default: "auto")
  • user: Optional unique identifier for your end-user
  • save_filename: Optional custom filename without extension

Example usage:

result = generate_image(
    prompt="A serene mountain landscape at sunset with a lake reflecting the sky",
    size="1536x1024",
    quality="high"
)
# Returns: {"status": "success", "saved_path": "path/to/image.png"}

Edit Image

Edits existing images or creates variations based on input images. Can use multiple reference images or perform inpainting with a mask.

Parameters:

  • prompt (required): Text description of the desired final image
  • image_paths (required): List of file paths to input image(s) (PNG format, < 25MB)
  • mask_path: Optional file path to mask image for inpainting
  • model: The model to use (default: "gpt-image-1")
  • n: Number of images to generate (default: 1)
  • size: Image dimensions - "1024x1024", "1536x1024", "1024x1536", or "auto" (default: "auto")
  • quality: Rendering quality - "low", "medium", "high", or "auto" (default: "auto")
  • user: Optional unique identifier for your end-user
  • save_filename: Optional custom filename without extension

Example usage:

result = edit_image(
    prompt="Change the sunset to a bright day with blue sky",
    image_paths=["/path/to/original/image.png"],
    quality="high"
)
# Returns: {"status": "success", "saved_path": "path/to/edited-image.png"}

Output Location

Generated and edited images are saved in an ai-images subdirectory where the MCP server script is located. The server returns the absolute path to the saved image.

How to add this MCP server to Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later