@genoooool/mcp-image-generator

@genoooool/mcp-image-generator

Enables AI image generation via multiple providers (Yunwu, Gemini) with customizable aspect ratios, resolutions, and output settings, seamlessly integrating with MCP-compatible clients.

Category
访问服务器

README

@genoooool/mcp-image-generator

This is an MCP (Model Context Protocol) server for AI image generation with multi-provider support.

Features

  • 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)

Supported MCP Clients

This MCP server works with:

  • Claude Desktop
  • Claude Code CLI
  • OpenCode
  • Codex
  • Any MCP-compatible client

Installation

Option 1: NPX (Recommended - No installation required)

npx -y @genoooool/mcp-image-generator

Option 2: Global Install

npm install -g @genoooool/mcp-image-generator

Option 3: Local Install

# Clone or download the repository
cd /path/to/project

# Install dependencies
npm install

# Build the project
npm run build

Configuration

Environment Variables

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

How to Switch Provider

1. Using Yunwu Provider

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  # Optional

2. Using Gemini Official Provider

Set 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  # Optional

Note: Gemini Official API key authentication uses query parameter ?key= for REST API requests to generateContent endpoints.

3. Using Custom Gemini Provider

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  # Optional

MCP Client Configuration

Claude Desktop

Configuration File Location

Claude 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

Configuration Format

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"
      }
    }
  }
}

Using Global Installation

If you installed globally:

{
  "mcpServers": {
    "image-generator": {
      "command": "mcp-image-generator",
      "env": {
        "IMAGE_PROVIDER": "yunwu",
        "IMAGE_TOKEN": "your_token"
      }
    }
  }
}

Using Local Installation

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

Configuration File Location

Claude Code CLI loads MCP configuration from:

  • Windows: %USERPROFILE%\.claude\config.json
  • macOS/Linux: ~/.claude/config.json

Configuration Format

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"
      }
    }
  }
}

Using Global Installation

If you installed globally:

{
  "mcpServers": {
    "image-generator": {
      "command": "mcp-image-generator",
      "env": {
        "IMAGE_PROVIDER": "yunwu",
        "IMAGE_TOKEN": "your_token"
      }
    }
  }
}

Using Local Installation

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

Configuration File Location

OpenCode loads MCP configuration from the following locations (in order of precedence):

  1. Global config: ~/.config/opencode/opencode.json
  2. Custom config: OPENCODE_CONFIG environment variable
  3. Project config: opencode.json in project root

Configuration Format

{
  "$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

Configuration File Location

Codex loads MCP configuration from the following locations:

  1. Global config: ~/.config/codex/config.toml
  2. Project config: codex.toml in project root

Configuration Format

[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"

Tool Usage

generate_image

Generate an image using AI models.

Parameters

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

Return Value

{
  "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.

Example Usage

Example 1: Generate a simple image

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"
}

Example 2: Generate with custom filename

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"
}

Example 3: Generate with direct URL (if supported)

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"
}

Development

Build

npm run build

Development Mode (with auto-reload)

npm run dev

Manual Testing

You can test the server manually by running:

IMAGE_PROVIDER=yunwu \
IMAGE_TOKEN=your_token \
node dist/index.js

Then send JSON-RPC messages via stdin.

Provider Details

Yunwu Provider

  • 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 in url field
    • If response contains inlineData.data, decodes base64 and saves to local file
    • If no URL is available, url will be empty and only file_path is guaranteed

Gemini Official Provider

  • 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

Custom Gemini Provider

  • Endpoint: Configurable via IMAGE_BASE_URL
  • Authentication: Supports both bearer token and API key based on IMAGE_AUTH_TYPE
    • bearer: Authorization: Bearer {token} header
    • apikey: ?key={api_key} query parameter

Error Handling

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"}

Troubleshooting

"IMAGE_PROVIDER environment variable is required"

Make sure you set the IMAGE_PROVIDER environment variable.

"IMAGE_TOKEN is required when IMAGE_AUTH_TYPE=bearer"

You're using bearer auth type but didn't provide a token. Either:

  • Set IMAGE_TOKEN environment variable
  • Change to apikey auth type and set IMAGE_API_KEY

"Unable to extract image from response"

The API response format may have changed. Check the provider's API documentation.

Timeout errors

Increase the timeout by setting IMAGE_REQUEST_TIMEOUT:

export IMAGE_REQUEST_TIMEOUT=120000  # 120 seconds

Claude Code doesn't show the MCP server

  1. Make sure you've restarted Claude Code after editing the config file
  2. Check that the configuration file path is correct for your OS
  3. Verify the command works in your terminal (e.g., run npx -y @genoooool/mcp-image-generator)
  4. Check Claude Code logs for error messages

License

MIT

Author

genoooool

Links

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选