gpt-image-mcp

gpt-image-mcp

MCP server that adds a generate_image tool to Claude Code and other MCP hosts, using OpenAI's gpt-image-2 to create and save PNG images locally.

Category
Visit Server

README

gpt-image-mcp

Give Claude Code the image-generation superpower. Say "draw me a picture", and Claude Code generates it right in your conversation using OpenAI gpt-image-2 โ€” no need to switch apps or copy prompts.

README ไธญๆ–‡ Python License: MIT MCP

๐ŸŽฏ What is this?

For Claude Code users: this project plugs gpt-image-2 image generation straight into Claude Code as an MCP server. Install once, register once, and Claude Code gains a native generate_image ability โ€” you describe the image in plain language (any language), and Claude Code produces the prompt, calls gpt-image-2, and hands you a local PNG. If you've ever wanted Claude to "just draw it" instead of explaining it, this is the missing piece.

It also works as a standalone CLI and with any other MCP host โ€” the same core, everywhere.

No ChatGPT Plus subscription needed โ€” just any gpt-image-2-capable API key.

Workflow:

You: "A cyberpunk orange tabby cat in a spacesuit, starfield, cinematic lighting"
  โ†“  Claude Code optimizes your prompt into professional English (automatic)
  โ†“  gpt-image-mcp calls OpenAI gpt-image-2
  โ†“  PNG saved locally โ†’ absolute path returned
You: got your image โœ“

โœจ Features

  • Native Claude Code integration. Register once, and Claude Code gains a real generate_image tool โ€” describe any scene in plain language, get a local PNG back inside your chat.
  • Two entrypoints, one core. The same generation logic powers both an MCP server and a plain CLI.
    • gpt-image-mcp --mcp โ†’ stdio MCP server with generate_image / list_images tools
    • gpt-image-mcp "a cat in a spacesuit" โ†’ one-shot CLI generation
  • Any OpenAI-compatible backend. Point OPENAI_BASE_URL anywhere you like (resellers, proxies, self-hosted gateways).
  • Quality tiers map to gpt-image-2's own low / medium / high knob. No extra models, no extra cost surprises.
  • Keys never in code. Everything is env-driven โ€” secrets stay out of your repo.
  • Async-safe. Images stream to disk as base64-decoded PNGs locally; the API never writes to your disk for you.

๐Ÿงฐ Requirements

  • Python 3.10+
  • An OpenAI API key, or an OpenAI-compatible endpoint (reseller / gateway / self-hosted) that serves gpt-image-2 (or a compatible model you set via GPT_IMAGE_MODEL).
  • Python installable via pip or uv.

๐Ÿ“ฆ Install

From PyPI

pip install gpt-image-mcp           # pip
# or
uv tool install gpt-image-mcp       # uv

From source

git clone https://github.com/Garfield-Wuu/gpt-image-mcp
cd gpt-image-mcp
python -m venv .venv
source .venv/bin/activate           # Windows: .venv\Scripts\activate
pip install -e .

โš™๏ธ Configuration

All configuration is via environment variables:

Variable Required Default Description
OPENAI_API_KEY โœ… โ€” Your API key (official or reseller). Never hardcode it.
OPENAI_BASE_URL โŒ https://api.openai.com/v1 Any OpenAI-compatible endpoint base URL (incl. /v1).
GPT_IMAGE_MODEL โŒ gpt-image-2 Model name served by the endpoint.
GPT_IMAGE_OUT โŒ <cwd>/out Directory where generated PNGs are saved.

Tip: The default base URL is the official OpenAI endpoint. To use a reseller or proxy, just set OPENAI_BASE_URL to its /v1 root โ€” nothing else changes.

๐Ÿš€ Usage

As an MCP server (Claude Code)

Register the server (replace ~/.venv with your actual env path):

claude mcp add gpt-image -s user \
  --env OPENAI_API_KEY="$OPENAI_API_KEY" \
  --env OPENAI_BASE_URL="$OPENAI_BASE_URL" \
  --env GPT_IMAGE_OUT="$PWD/out" \
  -- gpt-image-mcp --mcp

Restart Claude Code, and two tools become available:

  • generate_image โ€” generate an image and save it locally.
    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚ "A cyberpunk orange tabby cat in a spacesuit โ€ฆ"             โ”‚
    โ”‚    โ†’ gpt-image-mcp โ†’ local PNG โ†’ absolute path returned    โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
    
    Parameters: prompt (required), size, quality, out_name.
  • list_images โ€” list previously generated PNGs (newest first).

What to say in Claude Code:

"Draw a cyberpunk orange tabby in a spacesuit, starfield, cinematic, high quality." โ†’ triggers generate_image

"Generate a 1536x1024 landscape hero shot: cyberpunk city in the rain, neon reflections." โ†’ set size + quality

"Which images have I generated before?" โ†’ triggers list_images

No magic syntax needed โ€” just describe the image in your own words, in any language. Claude Code handles the rest.

As a CLI

export OPENAI_API_KEY="sk-..."
gpt-image-mcp "a cyberpunk orange tabby cat, neon rain, cinematic" \
  --size 1536x1024 --quality high --out ./out/hero.png

Without --no-interactive, the CLI lets you pick size/quality interactively when a TTY is present.

๐Ÿ–ผ๏ธ Parameters

size โ€” canvas orientation:

Value Orientation
1024x1024 Square
1536x1024 Landscape
1024x1536 Portrait

quality โ€” gpt-image-2's own quality knob (single model; trade-off is speed/cost vs. detail):

Value Use case
low Drafts / quick thumbnails
medium Balanced default
high Final hero art, more detail/slower

๐Ÿ› ๏ธ Development

pip install -e ".[dev]"
ruff check .            # lint
pytest                  # run tests
python -m build         # build sdist + wheel

Layout:

src/gpt_image_mcp/
โ”œโ”€โ”€ img_core.py    # shared generation logic (no MCP dependency)
โ”œโ”€โ”€ mcp_server.py  # FastMCP server: generate_image / list_images
โ””โ”€โ”€ __main__.py    # CLI + MCP entrypoints

๐Ÿ” Security

  • Your API key is never embedded in this package. It is read from OPENAI_API_KEY at call time.
  • Nothing is logged or transmitted beyond the single image-generation request.
  • The .env and out/ directories are git-ignored by default.

๐Ÿ“ Notes & caveats

  • Each request typically takes ~10โ€“60 s depending on endpoint and quality tier.
  • This project is not affiliated with OpenAI; it's an independent MCP wrapper.
  • gpt-image-2 returns images as base64 by default, which this tool decodes and writes to disk locally. A url fallback is also handled.

๐Ÿ“„ License

MIT ยฉ Garfield-Wuu.

โญ Support

If this saved you a rabbit hole, a star is appreciated. Issues and PRs welcome.


๐ŸŒ Other languages / ๅ…ถไป–่ฏญ่จ€

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured