Get the FREE Ultimate OpenClaw Setup Guide →

imagegen

MCP server for OpenAI Image Generation & Editing — text-to-image, image-to-image (with mask), no extra plugins.

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio spartanz51-imagegen-mcp npx imagegen-mcp \
  --env OPENAI_API_KEY="your_openai_api_key_here"

How to use

The MCP server imagegen-mcp exposes OpenAI image generation and editing capabilities via the MCP protocol. It acts as a wrapper around OpenAI's image APIs and integrates two core MCP tools: text-to-image and image-to-image. The text-to-image tool generates images from natural language prompts, with support for multiple models (e.g., gpt-image-1, dall-e-2, dall-e-3) and adjustable parameters such as size, style, format, and quality. The image-to-image tool edits existing images by providing paths to source images, a prompt describing the desired edits, and optional masks. Generated results are saved to temporary files and returned alongside base64 data. You can configure which models are allowed at runtime using the --models option when starting the server (default includes the supported OpenAI image models).

To use from MCP-enabled clients (e.g., Cursor), start the server via npx and then issue MCP requests specifying the tool name (text-to-image or image-to-image) and the required parameters. The server will handle image generation/editing and respond with the path to the saved image and its data.

How to install

Prerequisites:

  • Node.js v18+ and npm or yarn
  • An OpenAI API key with access to image generation/edit endpoints

Installation steps:

  1. Install dependencies and set up the project
git clone <your-repository-url>
cd <repository-directory>
npm install
# or
yarn install
  1. Configure environment variables
cp .env.example .env

Edit .env to include your OpenAI API key (the README indicates OPENAI_API_KEY as the key):

OPENAI_API_KEY=your_openai_api_key_here
  1. Build (if needed) or run directly with npx
# Quick run with npx (no local build required):
npx imagegen-mcp --help
  1. Run locally (alternative to npx)
npm run build
node dist/index.js --help

Additional notes

Environment variables and configuration:

  • OPENAI_API_KEY is required to authenticate with OpenAI.
  • The server supports environment-driven configuration and CLI options (e.g., --models to restrict available OpenAI image models).

Common issues:

  • If you encounter authentication errors, verify OPENAI_API_KEY is correct and has access to the requested models.
  • Ensure the runtime has permission to write to the system temporary directory for saved images.

Model and parameter notes:

  • The text-to-image tool supports models like gpt-image-1, dall-e-2, dall-e-3 with options for size, style, and output format.
  • The image-to-image tool supports editing through gpt-image-1 and dall-e-2 with masks; available sizes and formats follow OpenAI capabilities.

For Cursor integration, you can adjust the command provided in Cursor settings to point to your server and expose desired models via --models.

Related MCP Servers

Sponsor this space

Reach thousands of developers