image-generation-mcp
Generates images using Google Gemini image models via the Interactions API, including support for reference images and multiple aspect ratios.
Generates and edits images using OpenAI image models, supporting reference images and returning local file paths for the resulting images.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@image-generation-mcpCreate an image of a cyberpunk city street at night"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Ask your agent for a picture, and it gets back a file path — not a wall of base64. The server generates the image with Gemini or OpenAI, writes it to disk, and returns only the absolute path. Your context window stays clean, and the file is right there for the agent to open, move, or hand to another tool.
Features
One tool, no ceremony.
generate_image(prompt, images, aspect_ratio)— that's the whole API.Paths, not payloads. Returns an absolute file path, so a 1.5 MB PNG costs you ~60 tokens instead of ~2 million.
Two providers, auto-selected. Set whichever API key you have. Both set?
IMAGE_PROVIDERdecides.Image-to-image. Pass up to 4 reference images to restyle, edit, or combine them.
Flexible inputs. A reference can be a local path, an
http(s)URL, adata:URI, or bare base64 — the server figures out which.Both transports. stdio for local clients, streamable HTTP (localhost-bound) when you need a port.
Honest errors. No retries that mask a bad key, no silent provider fallback. When the API says 429, you see 429.
Small enough to read. ~540 lines of source, no file over 100 lines, strict-typed throughout.
Related MCP server: VisionToolMCP
Prerequisites
Requirement | Notes |
Python 3.11+ | 3.12 is what CI-equivalent local checks run on |
| |
An API key | Google Gemini or OpenAI — at least one |
Billing note. Image models are not free tier on either provider. A Gemini key without billing enabled returns
429 ... limit: 0for every image model.
Quick Start
git clone https://github.com/farukcan/image-generation-mcp.git
cd image-generation-mcp
uv sync
cp .env.example .env # add OPENAI_API_KEY or GEMINI_API_KEY
uv run pytest -m smoke # generates a real image into out/That last command is the fastest way to confirm your key works end to end — it prints the path of the image it just made.
Add it to your agent
Claude Code
claude mcp add image-generation \
-e OPENAI_API_KEY=sk-... \
-- uvx --from git+https://github.com/farukcan/image-generation-mcp image-generation-mcpuvx fetches, builds, and caches the package on first run — there is nothing to
install beforehand and nothing to keep updated by hand.
Prefer a checkout you can edit? Point it at the directory instead:
claude mcp add image-generation \
-e OPENAI_API_KEY=sk-... \
-- uv run --directory /absolute/path/to/image-generation-mcp image-generation-mcpAdd -s user to make it available in every project instead of just this one.
Verify with claude mcp list, and remove it with claude mcp remove image-generation.
Gemini CLI
Same flags, same shape:
gemini mcp add image-generation \
-e OPENAI_API_KEY=sk-... \
-- uvx --from git+https://github.com/farukcan/image-generation-mcp image-generation-mcpCursor, Windsurf, Claude Desktop, and everything else
These read a JSON config file (.cursor/mcp.json, claude_desktop_config.json, …).
The entry is the same everywhere:
{
"mcpServers": {
"image-generation": {
"command": "uvx",
"args": [
"--from", "git+https://github.com/farukcan/image-generation-mcp",
"image-generation-mcp"
],
"env": {
"OPENAI_API_KEY": "sk-...",
"OUT_DIR": "/absolute/path/where/images/should/land"
}
}
}
}Set OUT_DIR explicitly for GUI clients — they often launch with a working
directory you did not expect, and out/ would land there.
As an HTTP service
uv run image-generation-mcp --transport http --port 8000Serves the streamable-HTTP endpoint at http://127.0.0.1:8000/mcp. It binds to
loopback only and has no authentication, so put it behind a proxy before exposing it.
The tool
generate_image(prompt: str, images: list[str] | None = None, aspect_ratio: str = "1:1") -> strParameter | Description |
| What the image should show. |
| Up to 4 reference images. Each is a local file path, an |
|
|
Returns the absolute path of the written file, e.g. /path/to/out/20260827-172746-c9b3.png.
Names are YYYYmmdd-HHMMSS-xxxx, so results sort chronologically and never collide.
On aspect ratios: Gemini honours all ten. OpenAI accepts only three sizes, so
ratios collapse to the nearest of 1024x1024, 1536x1024, or 1024x1536 — asking
for 16:9 there gets you 3:2.
Configuration
Every setting is an environment variable. A .env file in the working directory (or
any parent) is loaded as a fallback; real environment variables always win.
Variable | Default | Purpose |
| — | Enables the Gemini provider |
| — | Enables the OpenAI provider |
| unset | Force |
|
| Also |
|
| Also |
|
| Where generated images are written |
|
|
|
|
| HTTP port; |
Start the server with no API key at all and the first request fails loudly, naming the variables it looked for.
How it works
flowchart LR
A([MCP client]) -->|generate_image| B[server.py]
B --> C[aspect.py<br/>validate ratio]
B --> D[sources.py + download.py<br/>path / URL / base64 → bytes]
B --> E{"registry.py<br/>which provider?"}
E -->|GEMINI_API_KEY| F[gemini_provider.py<br/>Interactions API]
E -->|OPENAI_API_KEY| G[openai_provider.py<br/>generate / edit]
F --> H[output.py<br/>write into OUT_DIR]
G --> H
H -->|absolute path| AEach module does one thing and stays under 100 lines. Providers are cached per resolved config, so an SDK client and its connection pool are reused across calls rather than rebuilt every request.
Providers
Gemini | OpenAI | |
API | Interactions ( | Images ( |
SDK floor |
|
|
Reference images | Sent inline as base64 parts | Uploaded as multipart files |
Output format | Whatever the model returns — the extension follows it | Always PNG ( |
Two deliberate quirks worth knowing:
Gemini's image
response_formatonly acceptsimage/jpegas an explicit MIME type, so the server does not request one and names the file after whatever comes back.input_fidelityis never sent to OpenAI —gpt-image-2rejects it with a 400 and applies high fidelity on its own.
Development
uv run ruff check . && uv run ruff format --check .
uv run mypy
uv run pytest # unit tests, all providers mocked
uv run pytest -m smoke -s # real API calls; costs money, prints the pathsSmoke tests are deselected by default so a normal pytest run never spends money.
test_edits_a_real_image costs two generations, since it makes its own reference image.
The logo and the screenshot are generated too — edit the scripts, not the SVGs:
uv run python media/generate_logo.py
uv run python media/generate_screenshot.pyThe 100-line-per-file ceiling is a design constraint, not an accident: it keeps every module reviewable in one screen. Split rather than stretch.
Troubleshooting
Symptom | Cause |
| The model is not on your plan's free tier. Enable billing on the provider project. |
| Neither key is set, and no |
Images appear somewhere unexpected |
|
| Only the ten listed ratios are accepted; the error lists them. |
| OpenAI takes PNG, JPEG, or WebP references only. |
License
MIT © Ömer Faruk Can
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceProvides tools for generating and editing images using OpenAI's gpt-image-1 model via an MCP interface, enabling AI assistants to create and modify images based on text prompts.15Apache 2.0
- FlicenseAqualityBmaintenanceEnables text-only agents to process images by accepting image files, base64 data, or URLs, sending them to multimodal models, and returning structured text results via MCP.4
- AlicenseAqualityAmaintenanceGenerates and edits images via Gemini, Grok, and GPT-image providers for MCP clients like Claude Code that lack native image generation.319MIT
- AlicenseAqualityAmaintenanceEnables coding agents to generate and edit images using Gemini and OpenAI image models, saving files directly into the project with configurable providers, models, and security restrictions.3MIT
Related MCP Connectors
OCR, transcription, file extraction, and image generation for AI agents via MCP.
Generate on-brand images from your AI agent: design, edit, and render templates over MCP.
Generate images with any major model — one API key, one prepaid balance, one MCP.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/farukcan/image-generation-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server