openai-gpt-image-1-mcp
Provides AI agents and coding assistants with image generation and editing capabilities using OpenAI's GPT-image-1 model, with support for local or Supabase storage.
README
<h1 align="center">OpenAI GPT Image Generation MCP Server</h1>
<p align="center"> <em>AI Image Generation and Editing Capabilities for AI Agents and AI Coding Assistants</em> </p>
A powerful implementation of the Model Context Protocol (MCP) integrated with OpenAI's GPT-image-1 model for providing AI agents and AI coding assistants with advanced image generation and editing capabilities.
With this MCP server, you can <b>generate images from text descriptions</b> and <b>edit existing images</b> with powerful AI. Images can be stored either locally or in Supabase Storage for easy access.
Overview
This MCP server provides tools that enable AI agents to generate and edit images using OpenAI's GPT-image-1 model. It follows the best practices for building MCP servers based on the Mem0 MCP server template. The server handles all aspects of the image generation process including API calls, error handling, and storing the generated images either locally or in Supabase Storage for easy access from anywhere.
Features
- Text-to-Image Generation: Create images from detailed text descriptions
- Image Editing: Modify existing images using text instructions
- Multiple Reference Images: Use multiple input images as references for generation
- Inpainting Support: Edit specific areas of images using masks
- Image Quality Control: Configure image size and quality settings
- Flexible Storage Options: Store images locally or in Supabase Storage
- Public Image URLs: Get direct URLs to access generated images when using Supabase Storage
Tools
The server provides two essential image generation tools:
generate_image: Create new images from text descriptionsedit_image: Edit existing images based on text prompts, with support for multiple reference images and masks
Prerequisites
- Docker/Docker Desktop if running the MCP server as a container (recommended)
- Python 3.10+ if running the MCP server directly
- OpenAI API key with access to GPT-image-1 model
- Supabase account (optional, for cloud storage of images)
Installation
Using Docker (Recommended)
-
Clone this repository:
git clone https://github.com/DevRico003/openai-gpt-image-1-mcp.git cd openai-gpt-image-1-mcp -
Build the Docker image:
docker build -t openai-gpt-image-1-mcp --build-arg PORT=8050 . -
Create a
.envfile based on the.env.examplefile
Using Python directly (no Docker)
-
Clone this repository:
git clone https://github.com/DevRico003/openai-gpt-image-1-mcp.git cd openai-gpt-image-1-mcp -
Install dependencies:
pip install -e . -
Create a
.envfile based on the.env.examplefile
Configuration
Create a .env file in the project root with the following variables:
# MCP Server Configuration
HOST=0.0.0.0
PORT=8050
TRANSPORT=sse
# OpenAI API Configuration
OPENAI_API_KEY=your_openai_api_key
# Storage Configuration
# Set to 'local' to store images on the server, or 'supabase' to use Supabase Storage
STORAGE_MODE=supabase
# Supabase Configuration (required if STORAGE_MODE=supabase)
SUPABASE_URL=https://your-project-url.supabase.co
SUPABASE_KEY=your-supabase-service-key
SUPABASE_BUCKET=your-bucket-name
# Optional settings for image generation
# MODEL_NAME=gpt-image-1
# DEFAULT_IMAGE_SIZE=auto
# DEFAULT_IMAGE_QUALITY=auto
Supabase Setup (Optional)
If you want to use Supabase for image storage:
- Create a Supabase account at supabase.com
- Create a new project and get your project URL and service key
- Create a storage bucket named
images - Make sure public access is enabled for the bucket if you want the images to be publicly accessible
Running the Server
Using Docker
docker run --env-file .env -p 8050:8050 openai-gpt-image-1-mcp
Using Python
python src/main.py
The server will start and listen on the configured host and port.
Integration with MCP Clients
SSE Configuration
Once you have the server running with SSE transport, you can connect to it using this configuration:
{
"mcpServers": {
"openai-gpt-image-1": {
"transport": "sse",
"url": "http://localhost:8050/sse"
}
}
}
Note for Windsurf users: Use
serverUrlinstead ofurlin your configuration:{ "mcpServers": { "openai-gpt-image-1": { "transport": "sse", "serverUrl": "http://localhost:8050/sse" } } }Note for Docker users: Use
host.docker.internalinstead oflocalhostif your client is running in a different container.
Stdio Configuration
Add this server to your MCP configuration for Claude Desktop, Windsurf, or any other MCP client:
{
"mcpServers": {
"openai-gpt-image-1": {
"command": "python",
"args": ["path/to/openai-gpt-image-1-mcp/src/main.py"],
"env": {
"TRANSPORT": "stdio",
"OPENAI_API_KEY": "your_openai_api_key"
}
}
}
}
Docker with Stdio Configuration
{
"mcpServers": {
"openai-gpt-image-1": {
"command": "docker",
"args": ["run", "--rm", "-i",
"-e", "TRANSPORT",
"-e", "OPENAI_API_KEY",
"openai-gpt-image-1-mcp"],
"env": {
"TRANSPORT": "stdio",
"OPENAI_API_KEY": "your_openai_api_key"
}
}
}
}
Tool Usage Examples
Generating an Image with Supabase Storage
# Generate an image of a flying cat with Supabase storage
# Make sure STORAGE_MODE=supabase in your .env file
result = await generate_image(
prompt="A photorealistic flying cat with wings soaring through clouds",
size="1024x1024",
quality="high"
)
# Get the public URL for the image
image_url = result['image_url'] # URL to view the image
download_url = result['download_url'] # URL to download the image
filename = result['filename'] # Filename of the generated image
storage_path = result['storage_path'] # Path in Supabase storage
print(f"Image generated successfully!")
print(f"View the image at: {image_url}")
# Example of displaying the image in a web application
html_img = f'<img src="{image_url}" alt="Flying cat">'
# Example of creating a download link
html_download = f'<a href="{download_url}" download="{filename}">Download Image</a>'
Generating an Image with Local Storage
# Generate an image with local storage
# Make sure STORAGE_MODE=local in your .env file
result = await generate_image(
prompt="A photorealistic flying cat with wings soaring through clouds",
size="1024x1024",
quality="high",
return_image=True # Get the image data directly (default is True)
)
# When using local storage, you get file paths and optional base64 data
saved_path = result['saved_path'] # Absolute path on server
relative_path = result['relative_path'] # Relative path from working directory
filename = result['filename'] # Filename of the generated image
directory = result['directory'] # Directory where images are stored
# If return_image=True, you also get image data
image_data = result['image_data'] # Base64 encoded image data
mime_type = result['mime_type'] # "image/png"
# Save image from base64 data
import base64
with open(f"local-{filename}", "wb") as f:
f.write(base64.b64decode(image_data))
print(f"Image saved locally as: local-{filename}")
Editing an Image
# Edit an existing image to add a hat
result = await edit_image(
prompt="Add a wizard hat to the cat",
image_paths=["/path/to/cat_image.png"],
size="1024x1024",
quality="high"
)
# Check storage mode used
storage_mode = result['storage_mode'] # "supabase" or "local"
if storage_mode == "supabase":
# Access the image via public URL
image_url = result['image_url']
print(f"View edited image at: {image_url}")
else:
# When using local storage
saved_path = result['saved_path']
# If return_image=True was used, you can also access the image data
if 'image_data' in result:
image_data = result['image_data']
# Save locally from base64 data
import base64
with open(f"edited-{result['filename']}", "wb") as f:
f.write(base64.b64decode(image_data))
Storage Options
The MCP server supports two storage modes:
-
Supabase Storage: Images are uploaded to Supabase and available via public URLs. This is ideal for:
- Remote access without filesystem access to the server
- Sharing images with other systems or users
- Long-term storage independent of the MCP server
-
Local Storage: Images are saved to a local directory on the server. This can be used when:
- You prefer to manage storage yourself
- You don't need remote access to the images
- You're testing or developing locally
Performance Considerations
If you're using local storage and are concerned about token limits:
# Generate image without returning the base64 data
result = await generate_image(
prompt="A photorealistic flying cat with wings soaring through clouds",
return_image=False # Don't include image data in the response
)
# Now you only have path information
saved_path = result['saved_path']
filename = result['filename']
For Docker deployments with shared volumes:
docker run -v $(pwd)/ai-images:/app/ai-images --env-file .env -p 8050:8050 openai-gpt-image-1-mcp
This way, you can access locally stored images in the ai-images directory on your host machine.
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。