Provides tools for generating images from text prompts and editing existing images using OpenAI's DALL-E models (DALL-E 2, DALL-E 3, and gpt-image-1), with support for various parameters like size, quality, style, and output format.
MCP OpenAI Image Generation Server
🚀 零安装配置! 直接在MCP客户端中使用,无需任何预安装步骤
This project provides a server implementation based on the Model Context Protocol (MCP) that acts as a wrapper around OpenAI's Image Generation and Editing APIs (see OpenAI documentation).
Features
- Exposes OpenAI image generation capabilities through MCP tools.
- Supports
text-to-image
generation using models like DALL-E 2, DALL-E 3, and gpt-image-1 (if available/enabled). - Supports
image-to-image
editing using DALL-E 2 and gpt-image-1 (if available/enabled). - Configurable via environment variables and command-line arguments.
- Handles various parameters like size, quality, style, format, etc.
- Saves generated/edited images to temporary files and returns the path along with the base64 data.
Here's an example of generating an image directly in Cursor using the text-to-image
tool integrated via MCP:
🚀 快速安装
方法1: 全局安装 (推荐)
方法2: 一键安装脚本
方法3: 使用 npx (无需安装)
📖 完整安装指南: 查看 INSTALL.md 获取详细说明
Prerequisites
- Node.js (v18 or later recommended)
- npm or yarn
- An OpenAI API key
🎯 零安装配置 (推荐)
**无需任何预安装步骤!**直接配置即可使用:
Cursor 编辑器
Claude Desktop
💡 零安装原理
- ✅ 首次运行:
npx
自动下载并缓存包 - ✅ 后续启动: 使用缓存,启动快速
- ✅ 自动更新: 始终使用最新版本
- ✅ 无污染: 不会全局安装任何包
📁 更多配置示例: 查看 examples/mcp-configs/
目录
Setup
- Clone the repository:
- Install dependencies:
- Configure Environment Variables:
Create a
.env
file in the project root by copying the example:Edit the.env
file and add your OpenAI API key:
Building
To build the TypeScript code into JavaScript:
This will compile the code into the dist
directory.
Running the Server
This section provides details on running the server locally after cloning and setup. For a quick start without cloning, see the Quick Run with npx section.
Using ts-node (for development):
Using the compiled code:
Options:
--models <model1> <model2> ...
: Specify which OpenAI models the server should allow. If not provided, it defaults to allowing all models defined insrc/libs/openaiImageClient.ts
(currently gpt-image-1, dall-e-2, dall-e-3).- Example using
npx
(also works for local runs):... --models gpt-image-1 dall-e-3
- Example after cloning:
node dist/index.js --models dall-e-3 dall-e-2
- Example using
The server will start and listen for MCP requests via standard input/output (using StdioServerTransport
).
MCP Tools
The server exposes the following MCP tools:
text-to-image
Generates an image based on a text prompt.
Parameters:
text
(string, required): The prompt to generate an image from.model
(enum, optional): The model to use (e.g.,gpt-image-1
,dall-e-2
,dall-e-3
). Defaults to the first allowed model.size
(enum, optional): Size of the generated image (e.g.,1024x1024
,1792x1024
). Defaults to1024x1024
. Check OpenAI documentation for model-specific size support.style
(enum, optional): Style of the image (vivid
ornatural
). Only applicable todall-e-3
. Defaults tovivid
.output_format
(enum, optional): Format (png
,jpeg
,webp
). Defaults topng
.output_compression
(number, optional): Compression level (0-100). Defaults to 100.moderation
(enum, optional): Moderation level (low
,auto
). Defaults tolow
.background
(enum, optional): Background (transparent
,opaque
,auto
). Defaults toauto
.transparent
requiresoutput_format
to bepng
orwebp
.quality
(enum, optional): Quality (standard
,hd
,auto
, ...). Defaults toauto
.hd
only applicable todall-e-3
.n
(number, optional): Number of images to generate. Defaults to 1. Note:dall-e-3
only supportsn=1
.
Returns:
content
: An array containing:- A
text
object containing the path to the saved temporary image file (e.g.,/tmp/uuid.png
).
- A
image-to-image
Edits an existing image based on a text prompt and optional mask.
Parameters:
images
(string, required): An array of file paths to local images.prompt
(string, required): A text description of the desired edits.mask
(string, optional): A file path of mask image (PNG). Transparent areas indicate where the image should be edited.model
(enum, optional): The model to use. Onlygpt-image-1
anddall-e-2
are supported for editing. Defaults to the first allowed model.size
(enum, optional): Size of the generated image (e.g.,1024x1024
). Defaults to1024x1024
.dall-e-2
only supports256x256
,512x512
,1024x1024
.output_format
(enum, optional): Format (png
,jpeg
,webp
). Defaults topng
.output_compression
(number, optional): Compression level (0-100). Defaults to 100.quality
(enum, optional): Quality (standard
,hd
,auto
, ...). Defaults toauto
.n
(number, optional): Number of images to generate. Defaults to 1.
Returns:
content
: An array containing:- A
text
object containing the path to the saved temporary image file (e.g.,/tmp/uuid.png
).
- A
Development
- Linting:
npm run lint
oryarn lint
- Formatting:
npm run format
oryarn format
(if configured inpackage.json
)
Contributing
Pull Requests (PRs) are welcome! Please feel free to submit improvements or bug fixes.
This server cannot be installed
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
Enables AI assistants to generate and edit images through OpenAI's DALL-E models via MCP tools. Supports text-to-image generation and image-to-image editing with configurable parameters for size, quality, and style.
Related MCP Servers
- -securityFlicense-qualityAn MCP server that allows users to generate, edit, and create variations of images through OpenAI's DALL-E API, supporting both DALL-E 2 and DALL-E 3 models.Last updated -10
- -securityAlicense-qualityA Model Context Protocol server enabling AI assistants to generate images through OpenAI's DALL-E API with full support for all available options and fine-grained control.Last updated -61MIT License
- -securityAlicense-qualityAn MCP tool server that enables generating and editing images through OpenAI's image models, supporting text-to-image generation and advanced image editing (inpainting, outpainting) across various MCP-compatible clients.Last updated -66MIT License
- AsecurityFlicenseAqualityAn MCP (Model Context Protocol) server that allows generating, editing, and creating variations of images using OpenAI's DALL-E APIs.Last updated -1