This is an MCP (Model Context Protocol) server for AI image generation with multi-provider support.
- Multi-provider support: Switch between Yunwu, Gemini Official, and custom Gemini providers without changing code
- Environment variable configuration: All provider settings controlled via environment variables
- Flexible output: Save images to custom directories with custom filenames
- Multiple aspect ratios: Support for 1:1, 16:9, 9:16, 4:3, 3:4, 3:2, 2:3, 5:4, 4:5, 21:9
- Resolution control: 1K, 2K, 4K resolution options (default: 2K)
- Error handling: Comprehensive error messages with HTTP status codes and response details
- Timeout support: Configurable request timeout (default: 60s)
This MCP server works with:
- Claude Desktop
- Claude Code CLI
- OpenCode
- Codex
- Any MCP-compatible client
npx -y @genoooool/mcp-image-generatornpm install -g @genoooool/mcp-image-generator# Clone or download the repository
cd /path/to/project
# Install dependencies
npm install
# Build the project
npm run build| Variable | Required | Description | Default |
|---|---|---|---|
IMAGE_PROVIDER |
Yes | Provider type: yunwu, gemini_official, or custom_gemini |
- |
IMAGE_BASE_URL |
Depends on provider | Override default base URL | Provider-specific |
IMAGE_AUTH_TYPE |
No | Auth type: bearer or apikey |
Provider-specific |
IMAGE_TOKEN |
Yes for bearer auth | Bearer token for authentication | - |
IMAGE_API_KEY |
Yes for apikey auth | API key for authentication | - |
IMAGE_OUT_DIR |
No | Default output directory for images | ./output |
IMAGE_REQUEST_TIMEOUT |
No | Request timeout in milliseconds | 60000 |
Set the following environment variables:
export IMAGE_PROVIDER=yunwu
export IMAGE_TOKEN=your_yunwu_token
export IMAGE_BASE_URL=https://yunwu.ai # Optional, this is the default
export IMAGE_OUT_DIR=./images # OptionalSet the following environment variables:
export IMAGE_PROVIDER=gemini_official
export IMAGE_API_KEY=your_gemini_api_key
export IMAGE_BASE_URL=https://generativelanguage.googleapis.com # Optional, this is the default
export IMAGE_OUT_DIR=./images # OptionalNote: Gemini Official API key authentication uses query parameter ?key= for REST API requests to generateContent endpoints.
Set the following environment variables:
export IMAGE_PROVIDER=custom_gemini
export IMAGE_BASE_URL=https://your-custom-provider.com # Required
export IMAGE_API_KEY=your_api_key # Or use IMAGE_TOKEN with IMAGE_AUTH_TYPE=bearer
export IMAGE_AUTH_TYPE=apikey # Optional: 'bearer' or 'apikey'
export IMAGE_OUT_DIR=./images # OptionalClaude Desktop loads MCP configuration from:
- Windows:
%APPDATA%\Claude\claude_desktop_config.json - macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
Add the MCP server to your configuration file:
If you installed globally:
{
"mcpServers": {
"image-generator": {
"command": "mcp-image-generator",
"env": {
"IMAGE_PROVIDER": "yunwu",
"IMAGE_TOKEN": "your_token"
}
}
}
}If you cloned the repository:
Windows:
{
"mcpServers": {
"image-generator": {
"command": "node",
"args": ["C:\\path\\to\\project\\dist\\index.js"],
"env": {
"IMAGE_PROVIDER": "yunwu",
"IMAGE_TOKEN": "your_token"
}
}
}
}macOS/Linux:
{
"mcpServers": {
"image-generator": {
"command": "node",
"args": ["/path/to/project/dist/index.js"],
"env": {
"IMAGE_PROVIDER": "yunwu",
"IMAGE_TOKEN": "your_token"
}
}
}
}Claude Code CLI loads MCP configuration from:
- Windows:
%USERPROFILE%\.claude\config.json - macOS/Linux:
~/.claude/config.json
Add the MCP server to your configuration file:
{
"mcpServers": {
"image-generator-yunwu": {
"command": "npx",
"args": ["-y", "@genoooool/mcp-image-generator"],
"env": {
"IMAGE_PROVIDER": "yunwu",
"IMAGE_TOKEN": "your_yunwu_token",
"IMAGE_OUT_DIR": "./images"
}
},
"image-generator-gemini": {
"command": "npx",
"args": ["-y", "@genoooool/mcp-image-generator"],
"env": {
"IMAGE_PROVIDER": "gemini_official",
"IMAGE_API_KEY": "your_gemini_api_key",
"IMAGE_OUT_DIR": "./images"
}
},
"image-generator-custom": {
"command": "npx",
"args": ["-y", "@genoooool/mcp-image-generator"],
"env": {
"IMAGE_PROVIDER": "custom_gemini",
"IMAGE_BASE_URL": "https://your-custom-provider.com",
"IMAGE_API_KEY": "your_api_key",
"IMAGE_AUTH_TYPE": "apikey",
"IMAGE_OUT_DIR": "./images"
}
}
}
}If you installed globally:
{
"mcpServers": {
"image-generator": {
"command": "mcp-image-generator",
"env": {
"IMAGE_PROVIDER": "yunwu",
"IMAGE_TOKEN": "your_token"
}
}
}
}If you cloned the repository:
Windows:
{
"mcpServers": {
"image-generator": {
"command": "node",
"args": ["C:\\path\\to\\project\\dist\\index.js"],
"env": {
"IMAGE_PROVIDER": "yunwu",
"IMAGE_TOKEN": "your_token"
}
}
}
}macOS/Linux:
{
"mcpServers": {
"image-generator": {
"command": "node",
"args": ["/path/to/project/dist/index.js"],
"env": {
"IMAGE_PROVIDER": "yunwu",
"IMAGE_TOKEN": "your_token"
}
}
}
}OpenCode loads MCP configuration from the following locations (in order of precedence):
- Global config:
~/.config/opencode/opencode.json - Custom config:
OPENCODE_CONFIGenvironment variable - Project config:
opencode.jsonin project root
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"image-generator-yunwu": {
"type": "local",
"command": ["npx", "-y", "@genoooool/mcp-image-generator"],
"enabled": true,
"environment": {
"IMAGE_PROVIDER": "yunwu",
"IMAGE_TOKEN": "your_yunwu_token",
"IMAGE_OUT_DIR": "./images"
}
},
"image-generator-gemini": {
"type": "local",
"command": ["npx", "-y", "@genoooool/mcp-image-generator"],
"enabled": true,
"environment": {
"IMAGE_PROVIDER": "gemini_official",
"IMAGE_API_KEY": "your_gemini_api_key",
"IMAGE_OUT_DIR": "./images"
}
}
}
}Codex loads MCP configuration from the following locations:
- Global config:
~/.config/codex/config.toml - Project config:
codex.tomlin project root
[mcp_servers.image_yunwu]
command = "npx"
args = ["-y", "@genoooool/mcp-image-generator"]
[mcp_servers.image_yunwu.env]
IMAGE_PROVIDER = "yunwu"
IMAGE_TOKEN = "your_token"
IMAGE_OUT_DIR = "./images"
[mcp_servers.image_gemini]
command = "npx"
args = ["-y", "@genoooool/mcp-image-generator"]
[mcp_servers.image_gemini.env]
IMAGE_PROVIDER = "gemini_official"
IMAGE_API_KEY = "your_gemini_api_key"
IMAGE_OUT_DIR = "./images"
[mcp_servers.image_custom]
command = "npx"
args = ["-y", "@genoooool/mcp-image-generator"]
[mcp_servers.image_custom.env]
IMAGE_PROVIDER = "custom_gemini"
IMAGE_BASE_URL = "https://your-custom-provider.com"
IMAGE_API_KEY = "your_api_key"
IMAGE_AUTH_TYPE = "apikey"
IMAGE_OUT_DIR = "./images"Generate an image using AI models.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
model |
string | No | gemini-3-pro-image-preview |
Model to use for generation |
prompt |
string | Yes | - | The prompt for image generation |
aspect_ratio |
string | No | 1:1 |
Aspect ratio: 1:1, 16:9, 9:16, 4:3, 3:4, 3:2, 2:3, 5:4, 4:5, 21:9 |
image_size |
string | No | 2K |
Resolution: 1K, 2K, 4K |
out_dir |
string | No | ./output |
Directory to save the image |
filename |
string | No | timestamp.png |
Custom filename |
{
"url": "string",
"file_path": "string | null",
"provider": "string"
}Note: For Yunwu provider, if the response does not include a URL field, only file_path will be returned and url will be empty.
Input:
{
"prompt": "A beautiful sunset over the ocean",
"aspect_ratio": "16:9",
"image_size": "2K"
}Output:
{
"url": "",
"file_path": "./images/20260111_034500.png",
"provider": "yunwu"
}Input:
{
"prompt": "A futuristic cityscape at night",
"model": "gemini-3-pro-image-preview",
"aspect_ratio": "1:1",
"out_dir": "./my_images",
"filename": "cityscape.png"
}Output:
{
"url": "",
"file_path": "./my_images/cityscape.png",
"provider": "gemini_official"
}Input:
{
"prompt": "A peaceful mountain landscape",
"aspect_ratio": "4:3",
"image_size": "1K"
}Output:
{
"url": "https://cdn.example.com/images/abc123.png",
"file_path": null,
"provider": "yunwu"
}npm run buildnpm run devYou can test the server manually by running:
IMAGE_PROVIDER=yunwu \
IMAGE_TOKEN=your_token \
node dist/index.jsThen send JSON-RPC messages via stdin.
- Endpoint:
POST https://yunwu.ai/v1beta/models/{model}:generateContent - Authentication: Bearer token via
Authorization: Bearer {token}header - Response Handling:
- If response contains
fileData.uri, returns the URL inurlfield - If response contains
inlineData.data, decodes base64 and saves to local file - If no URL is available,
urlwill be empty and onlyfile_pathis guaranteed
- If response contains
- Endpoint:
POST https://generativelanguage.googleapis.com/v1beta/models/{model}:generateContent?key={api_key} - Authentication: API key via query parameter
?key=in the URL - Response Handling: Same as Yunwu provider
- Endpoint: Configurable via
IMAGE_BASE_URL - Authentication: Supports both bearer token and API key based on
IMAGE_AUTH_TYPEbearer:Authorization: Bearer {token}headerapikey:?key={api_key}query parameter
The server returns detailed error messages when issues occur:
- HTTP errors: Includes HTTP status code and response body
- Validation errors: Includes field names and validation messages
- Configuration errors: Clearly indicates missing required environment variables
Example error response:
Yunwu API error (401): {"error": "Invalid token"}
Make sure you set the IMAGE_PROVIDER environment variable.
You're using bearer auth type but didn't provide a token. Either:
- Set
IMAGE_TOKENenvironment variable - Change to
apikeyauth type and setIMAGE_API_KEY
The API response format may have changed. Check the provider's API documentation.
Increase the timeout by setting IMAGE_REQUEST_TIMEOUT:
export IMAGE_REQUEST_TIMEOUT=120000 # 120 seconds- Make sure you've restarted Claude Code after editing the config file
- Check that the configuration file path is correct for your OS
- Verify the command works in your terminal (e.g., run
npx -y @genoooool/mcp-image-generator) - Check Claude Code logs for error messages
MIT
genoooool
{ "mcpServers": { "image-generator-yunwu": { "command": "npx", "args": ["-y", "@genoooool/mcp-image-generator"], "env": { "IMAGE_PROVIDER": "yunwu", "IMAGE_TOKEN": "your_yunwu_token", "IMAGE_OUT_DIR": "./images" } }, "image-generator-gemini": { "command": "npx", "args": ["-y", "@genoooool/mcp-image-generator"], "env": { "IMAGE_PROVIDER": "gemini_official", "IMAGE_API_KEY": "your_gemini_api_key", "IMAGE_OUT_DIR": "./images" } }, "image-generator-custom": { "command": "npx", "args": ["-y", "@genoooool/mcp-image-generator"], "env": { "IMAGE_PROVIDER": "custom_gemini", "IMAGE_BASE_URL": "https://your-custom-provider.com", "IMAGE_API_KEY": "your_api_key", "IMAGE_AUTH_TYPE": "apikey", "IMAGE_OUT_DIR": "./images" } } } }