openai-image-mcp
Provides tools for generating images using the OpenAI GPT image generation API, allowing AI agents to create images either inline as MCP image content or saved to disk.
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., "@openai-image-mcpgenerate an image of a futuristic city skyline"
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.
openai-image-mcp
A minimal, production-ready MCP server that exposes OpenAI GPT Image generation as two well-defined tools: generate_image (returns the PNG inline as MCP image content) and generate_image_to_file (writes the PNG to disk for asset pipelines).
Part of the mcp-accelerator: it is the reference implementation of the accelerator's "local stdio server with externalized secrets" pattern for APIs that have no official hosted MCP server.
This documentation follows the structure of a TOGAF Architecture Definition Document (ADM phases A through F), so that both humans and AI agents can extract the intent, the contracts, and the constraints without reading the code first. If you are an AI agent, start with Section 8: Agent Usage Contract.
Table of Contents
Related MCP server: imagegen-mcp
1. Architecture Vision (Phase A)
1.1 Problem statement
AI assistants such as Claude can reason about images but cannot create them with OpenAI models out of the box. OpenAI offers no official hosted MCP server for its image API. Teams therefore either paste generated images around manually or build one-off integrations per project.
1.2 Vision
Provide image generation as a first-class MCP capability: any MCP host (Claude Code, Claude Desktop) gains a generate_image tool that produces brand assets, mockup imagery, placeholder art, or documentation illustrations on demand, inside the conversation, with the API key kept out of every config file.
1.3 Stakeholders and concerns
Stakeholder | Concern | How this architecture addresses it |
Developer using Claude Code | Generate assets without leaving the terminal | Tools are available in-session after a one-line config entry |
Project team | Reusable setup across projects | Config templates live in the mcp-accelerator, the server is generic |
Security officer | API keys must not leak via dotfiles or repos | Key is resolved at process launch from the environment or the macOS Keychain, never stored in config |
AI agent (Claude) | Needs deterministic tool contracts | Strict parameter validation, explicit error messages, contract documented in Section 8 |
1.4 Value proposition
One capability, two delivery modes: inline image content for conversational use, file output for build and asset pipelines.
Zero configuration drift: the server has no config file of its own. Behavior is fully determined by the tool parameters and one environment variable.
Small enough to audit in five minutes: a single Python module of about 75 lines.
2. Business Architecture (Phase B)
2.1 Business capability
"Generative image supply for software delivery": producing visual assets (app icons drafts, hero images, empty-state illustrations, test fixtures, blog graphics) as part of the normal engineering workflow rather than as a separate design request.
2.2 Core use cases
ID | Use case | Actor | Tool used |
UC-1 | Generate an illustration during a conversation and inspect it immediately | Developer via Claude |
|
UC-2 | Generate an asset directly into the project tree (for example | Claude Code in an implementation task |
|
UC-3 | Batch-produce placeholder images for a UI prototype | Claude Code, iterating |
|
UC-4 | Create documentation or listing graphics (App Store, README) | Developer via Claude | either |
2.3 Value chain position
flowchart LR
A[Requirement<br/>needs a visual] --> B[Prompt<br/>formulated by human or AI]
B --> C[openai-image-mcp<br/>MCP tool call]
C --> D[PNG asset]
D --> E1[Inline review<br/>in conversation]
D --> E2[Committed to repo<br/>asset pipeline]3. Application Architecture (Phase C)
3.1 Component model
flowchart LR
subgraph Host["MCP Host (Claude Code / Claude Desktop)"]
LLM[Claude]
end
subgraph Server["openai-image-mcp (local process)"]
FMCP[FastMCP runtime<br/>stdio transport]
T1[Tool: generate_image]
T2[Tool: generate_image_to_file]
GEN[_generate_png<br/>validation + API call]
end
subgraph OpenAI["OpenAI Platform"]
IMG[Images API<br/>model gpt-image-2]
end
FS[(Local filesystem)]
KEY[/OPENAI_API_KEY<br/>env or Keychain/]
LLM -- "JSON-RPC over stdio" --> FMCP
FMCP --> T1 & T2
T1 & T2 --> GEN
GEN -- "HTTPS" --> IMG
T2 -- "write PNG" --> FS
KEY -. "read at process start" .-> Server3.2 Tool catalog
Tool | Purpose | Returns |
| Generate a PNG and return it as MCP image content |
|
| Generate a PNG and persist it to an absolute path | Confirmation string with path and byte count |
3.3 Interaction (runtime view)
sequenceDiagram
participant C as Claude (MCP host)
participant S as openai-image-mcp
participant O as OpenAI Images API
C->>S: tools/call generate_image_to_file(prompt, output_path, size)
S->>S: validate prompt not empty, size allowed, path absolute
S->>O: images.generate(model=gpt-image-2, output_format=png)
O-->>S: b64_json payload
S->>S: decode, create parent dirs, write file
S-->>C: "Image saved: /path/file.png (N bytes)"4. Data Architecture (Phase C)
4.1 Data flows and classification
Data | Direction | Classification | Persistence |
Prompt text | Host to server to OpenAI | Potentially confidential (leaves the machine) | Not persisted by the server |
API key | Environment to server to OpenAI (HTTPS auth header) | Secret | Never written to disk by the server |
Generated PNG | OpenAI to server to host or filesystem | Project asset | Only persisted when |
4.2 Data principles
The server is stateless: no cache, no logs of prompts or images, no temp files.
Prompts are transmitted to OpenAI. Do not include secrets, personal data, or unreleased confidential material in prompts.
File writes happen only at the exact
output_paththe caller supplies (plus creation of missing parent directories).
5. Technology Architecture (Phase D)
5.1 Technology stack
Layer | Choice | Rationale |
Language / runtime | Python >= 3.11 | Team standard, first-class MCP SDK |
MCP framework |
| Decorator-based tools, stdio transport built in |
API client | official | Maintained, typed |
Package manager |
| Fast, lockfile-based, reproducible |
Transport | stdio | Launched and owned by the MCP host, no open ports, no daemon |
Image model |
| Current OpenAI image model; change in |
5.2 Deployment model
The server is not deployed anywhere. Each MCP host process spawns its own instance on demand as a child process and terminates it with the session. There is nothing to operate, monitor, or patch besides the Python dependencies.
6. Security Architecture (cross-cutting)
Fail-fast startup: the process refuses to start without
OPENAI_API_KEY, so misconfiguration is caught at registration time, not at first tool call.No secrets at rest: config templates reference the key via
${OPENAI_API_KEY}or resolve it at launch from the macOS Keychain:security add-generic-password -s OPENAI_API_KEY -a "$USER" -w "sk-your-key"Input validation: empty prompts rejected,
sizerestricted to an allowlist,output_pathmust be absolute (prevents surprises from host-dependent working directories).Network egress: exactly one destination,
api.openai.comover HTTPS.Residual risk:
generate_image_to_filewrites wherever the caller points it. The MCP host's permission system is the guard rail for that; review file paths when approving tool calls.
7. Implementation and Migration (Phases E and F)
7.1 Installation
git clone https://github.com/rammc/openai-image-mcp.git ~/openai-image-mcp
cd ~/openai-image-mcp
uv sync7.2 Claude Code (project scope .mcp.json)
{
"mcpServers": {
"openai-image": {
"type": "stdio",
"command": "uv",
"args": ["--directory", "${HOME}/openai-image-mcp", "run", "python", "main.py"],
"env": { "OPENAI_API_KEY": "${OPENAI_API_KEY}" }
}
}
}Keychain variant (macOS, no shell profile changes needed):
{
"mcpServers": {
"openai-image": {
"type": "stdio",
"command": "sh",
"args": [
"-c",
"OPENAI_API_KEY=\"$(security find-generic-password -s OPENAI_API_KEY -w)\" exec uv --directory \"$HOME/openai-image-mcp\" run python main.py"
]
}
}
}7.3 Claude Desktop (claude_desktop_config.json)
Claude Desktop does not inherit your shell environment, so use the Keychain variant above (same JSON, without the "type" field).
7.4 Verification
export OPENAI_API_KEY="sk-your-key"
uv run python main.py # must start without error, then Ctrl+CIn Claude Code, run /mcp and confirm that openai-image is connected and lists two tools.
7.5 Migration notes
Coming from a copy of this server with project-specific paths: only the
--directoryargument changes, the tool contract is identical.Model upgrades (for example a future
gpt-image-3): single constant inmain.py, no contract change expected.
8. Agent Usage Contract
This section is written for AI agents (Claude and others) so the repository is directly consumable without reading the source.
8.1 Tool contracts
generate_image(prompt: str, size: str = "auto") -> MCP Image (PNG)
generate_image_to_file(prompt: str, output_path: str, size: str = "auto") -> strConstraints, enforced server-side with descriptive errors:
promptmust be non-empty after trimming. Write precise, visual prompts: subject, style, composition, color, background. The prompt is sent verbatim to OpenAI.sizemust be one of:"auto","1024x1024"(square),"1536x1024"(landscape),"1024x1536"(portrait). Any other value raises an error, including values like"512x512".output_pathmust be an ABSOLUTE path ending in a filename (use.png). Missing parent directories are created automatically.
8.2 Decision rule: which tool
The user wants to SEE or iterate on the image in conversation: use
generate_image.The image is an artifact of the task (belongs in a repo, a build, a document): use
generate_image_to_filewith a path inside the project, then reference the file. Do not usegenerate_imageand re-save the payload manually.
8.3 Behavioral notes for agents
Calls are synchronous and take several seconds up to about a minute. Do not retry immediately on slowness.
Each call costs real OpenAI credits. Batch thoughtfully, do not regenerate an acceptable image just to confirm.
Validation errors (for example "The prompt must not be empty.") mean the argument was wrong, not that the service failed. Fix the argument and retry once.
For transparent backgrounds or specific aspect ratios beyond the three sizes, state it in the prompt; the API decides best-effort.
8.4 Example calls
generate_image(
prompt="Flat vector illustration of a mountain trail at sunrise, warm orange and teal palette, minimal, no text",
size="1536x1024"
)
generate_image_to_file(
prompt="App icon draft: stylized letter M, deep red gradient background, modern, centered, no text besides the letter",
output_path="/Users/me/project/assets/icon-draft.png",
size="1024x1024"
)9. Operations and Troubleshooting
Symptom | Cause | Fix |
Server fails to start: "OPENAI_API_KEY is missing" | Key not in the launch environment | Export the variable or use the Keychain launch command |
Tool error: "size must be one of ..." | Unsupported size value | Use one of the four allowed values |
Tool error: "output_path must be an absolute path." | Relative path passed | Pass an absolute path |
| Invalid or revoked key | Rotate the key, update Keychain entry |
Server not listed in | Wrong | Verify the path and |
License and status
MIT License, see LICENSE. Version 0.1.0. Issues and extension requests: open a GitHub issue in this repo.
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.
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/rammc/openai-image-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server