A Model Context Protocol (MCP) server that enables seamless generation of high-quality images using OpenAI compatible APIs. This server provides a standardized interface to specify image generation parameters.
- High-quality image generation powered by OpenAI compatible APIs
- Support for customizable dimensions (width and height)
- Clear error handling for prompt validation and API issues
- Easy integration with MCP-compatible clients
- Returns a direct URL to the generated image
npm install openai-image-mcp
Or run directly:
npx openai-image-mcp@latest
Add to your MCP server configuration:
{
"mcpServers": {
"openai-image-gen": {
"command": "npx",
"args": ["openai-image-mcp@latest -y"],
"env": {
"OPENAI_API_KEY": "<YOUR_API_KEY>",
"OPENAI_API_URL": "<OPTIONAL_API_ENDPOINT_URL>", // Optional: Defaults to OpenAI standard endpoint if not provided
"DEFAULT_MODEL": "<OPTIONAL_DEFAULT_MODEL_NAME>" // Optional: Defaults to 'black-forest-labs/FLUX.1-schnell-Free' if not provided
}
}
}
}
The server provides one tool: generate_image
This tool requires a prompt
. Other parameters like model
, width
, height
, steps
, and n
are optional and use defaults if not provided. It returns a direct URL to the generated image.
{
// Required
prompt: string; // Text description of the image to generate
// Optional with defaults
model?: string; // Default: "black-forest-labs/FLUX.1-schnell-Free"
width?: number; // Default: 1024 (min: 128, max: 2048)
height?: number; // Default: 768 (min: 128, max: 2048)
steps?: number; // Default: 1 (min: 1, max: 100)
n?: number; // Default: 1 (max: 4)
// response_format is always "url"
// image_path is removed
}
Only the prompt is required:
{
"name": "generate_image",
"arguments": {
"prompt": "A serene mountain landscape at sunset"
}
}
Override defaults:
{
"name": "generate_image",
"arguments": {
"prompt": "A futuristic cityscape at night",
"model": "dall-e-3", // Example model
"width": 1024,
"height": 1024,
"steps": 50,
"n": 1
}
}
The response will be a simple text string containing the direct URL to the generated image.
Example Response:
https://image-provider.com/path/to/generated/image.png
It is recommended that clients display this URL as a clickable link or directly render the image using Markdown, e.g., 
.
(Response format details updated above)
If not specified in the request, these defaults are used:
- model: "black-forest-labs/FLUX.1-schnell-Free"
- width: 1024
- height: 768
- steps: 1
- n: 1
- response_format: "url" (This is now fixed and cannot be changed)
- Only the
prompt
parameter is required - All optional parameters use defaults if not provided
- When provided, parameters must meet their constraints (e.g., width/height ranges)
- The server now always returns a direct URL to the image.
- Image saving to disk is no longer supported by this server.
- Node.js >= 16
- OpenAI compatible API key (
OPENAI_API_KEY
) - Optional: OpenAI API URL (
OPENAI_API_URL
) if using a non-standard endpoint (e.g., self-hosted or alternative provider). If not provided, defaults to the standard OpenAI API endpoint. - Optional: Default Model Name (
DEFAULT_MODEL
) to override the built-in default (black-forest-labs/FLUX.1-schnell-Free
).
{
"@modelcontextprotocol/sdk": "0.6.0",
"axios": "^1.6.7"
}
Clone and build the project:
git clone https://github.com/your-username/openai-image-mcp
cd openai-image-mcp
npm install
npm run build
npm run build
- Build the TypeScript projectnpm run watch
- Watch for changes and rebuildnpm run inspector
- Run MCP inspector
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a new branch (
feature/my-new-feature
) - Commit your changes
- Push the branch to your fork
- Open a Pull Request
Feature requests and bug reports can be submitted via GitHub Issues. Please check existing issues before creating a new one.
For significant changes, please open an issue first to discuss your proposed changes.
This project is licensed under the MIT License. See the LICENSE file for details.