Gemini Image Generator MCP Server
Generates and transforms images using Google's Gemini model through the MCP protocol, enabling AI assistants to create high-quality images from text prompts.
README
This repo is fork from @qhdrl12/mcp-server-gemini-image-generator with new models and better visibility of errors.

Gemini Image Generator MCP Server
Generate high-quality images from text prompts using Google's Gemini model through the MCP protocol.
Overview
This MCP server allows any AI assistant to generate images using Google's Gemini AI model. The server handles prompt engineering, text-to-image conversion, filename generation, and local image storage, making it easy to create and manage AI-generated images through any MCP client.
Features
- Text-to-image generation using Gemini 2.5 Flash
- Image-to-image transformation based on text prompts
- Support for both file-based and base64-encoded images
- Automatic intelligent filename generation based on prompts
- Automatic translation of non-English prompts
- Local image storage with configurable output path
- Strict text exclusion from generated images
- High-resolution image output
- Direct access to both image data and file path
Available MCP Tools
The server provides the following MCP tools for AI assistants (uses only Gemini generate_content with gemini-2.5-flash-image):
1. generate_image_from_text
Creates a new image from a text prompt description.
generate_image_from_text(
prompt: str,
output_image_path: Optional[str] = None
) -> Tuple[bytes, str]
Parameters:
prompt: Text description of the image you want to generateoutput_image_path(optional): Absolute directory path to save the image. If omitted, usesOUTPUT_IMAGE_PATHor~/gen_image.
Returns:
- A tuple containing:
- Raw image data (bytes)
- Path to the saved image file (str)
This dual return format allows AI assistants to either work with the image data directly or reference the saved file path.
Examples:
- "Generate an image of a sunset over mountains"
- "Create a photorealistic picture of a fluffy ginger cat"
Pass a custom output directory (if your MCP client allows specifying arguments):
generate_image_from_text(
prompt="futuristic city at dawn",
output_image_path="/Users/username/Pictures/ai"
)
Example Output
This image was generated using the prompt:
"A photorealistic picture of a fluffy ginger cat sitting on a wooden floor, looking directly at the camera. Soft, natural light from a window."

A photorealistic picture of a fluffy ginger cat sitting on a wooden floor, looking directly at the camera. Soft, natural light from a window.
Known Issues
When using this MCP server with Claude Desktop Host:
-
Performance Issues: Using
transform_image_from_encodedmay take significantly longer to process compared to other methods. This is due to the overhead of transferring large base64-encoded image data through the MCP protocol. -
Path Resolution Problems: There may be issues with correctly resolving image paths when using Claude Desktop Host. The host application might not properly interpret the returned file paths, making it difficult to access the generated images.
For the best experience, consider using alternative MCP clients or the transform_image_from_file method when possible.
2. transform_image_from_encoded
Transforms an existing image based on a text prompt using base64-encoded image data.
transform_image_from_encoded(
encoded_image: str,
prompt: str,
output_image_path: Optional[str] = None
) -> Tuple[bytes, str]
Parameters:
encoded_image: Base64 encoded image data with format header (must be in format: "data:image/[format];base64,[data]")prompt: Text description of how you want to transform the imageoutput_image_path(optional): Absolute directory path to save the transformed image. If omitted, usesOUTPUT_IMAGE_PATHor~/gen_image.
Returns:
- A tuple containing:
- Raw transformed image data (bytes)
- Path to the saved transformed image file (str)
Example:
- "Add snow to this landscape"
- "Change the background to a beach"
With custom output directory:
transform_image_from_encoded(
encoded_image="data:image/png;base64,iVBORw0K...",
prompt="add cinematic teal-orange grading",
output_image_path="/tmp/ai_out"
)
3. transform_image_from_file
Transforms an existing image file based on a text prompt.
transform_image_from_file(
image_file_path: str,
prompt: str,
output_image_path: Optional[str] = None
) -> Tuple[bytes, str]
Parameters:
image_file_path: Path to the image file to be transformedprompt: Text description of how you want to transform the imageoutput_image_path(optional): Absolute directory path to save the transformed image. If omitted, usesOUTPUT_IMAGE_PATHor~/gen_image.
Returns:
- A tuple containing:
- Raw transformed image data (bytes)
- Path to the saved transformed image file (str)
Examples:
- "Add a llama next to the person in this image"
- "Make this daytime scene look like night time"
With custom output directory:
transform_image_from_file(
image_file_path="/Users/username/Pictures/input.png",
prompt="convert to watercolor style",
output_image_path="/Users/username/Pictures/ai_out"
)
Example Transformation
Using the ginger cat image created above, we applied a transformation with the following prompt:
"Using the provided image of my cat, please add a small, knitted wizard hat on its head. Make it look like it's sitting comfortably and not falling off."
Before:

After:

The original ginger cat with a hat
Setup
Prerequisites
- Python 3.11+
- Google AI API key (Gemini)
- MCP host application (Claude Desktop App, Cursor, or other MCP-compatible clients)
Getting a Gemini API Key
- Visit Google AI Studio API Keys page
- Sign in with your Google account
- Click "Create API Key"
- Copy your new API key for use in the configuration
- Note: The API key provides a certain quota of free usage per month. You can check your usage in the Google AI Studio
Installation
Manual Installation
- Clone the repository:
git clone https://github.com/your-username/mcp-server-gemini-image-generator.git
cd mcp-server-gemini-image-generator
- Create a virtual environment and install dependencies:
# Using uv (recommended)
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
uv pip install -e .
# Or using regular venv
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
pip install -e .
- Set up environment variables (choose one method):
Method A: Using .env file (optional)
# Create .env file in the project root
cat > .env << 'EOF'
GEMINI_API_KEY=your-gemini-api-key-here
OUTPUT_IMAGE_PATH=/path/to/save/images
EOF
Method B: Set directly in Claude Desktop config (recommended)
- Set environment variables directly in the
claude_desktop_config.json(shown in configuration section below)
Configure Claude Desktop
Add the following to your claude_desktop_config.json:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"gemini-image-generator": {
"command": "uv",
"args": [
"--directory",
"/absolute/path/to/mcp-server-gemini-image-generator",
"run",
"mcp-server-gemini-image-generator"
],
"env": {
"GEMINI_API_KEY": "your-actual-gemini-api-key-here",
"OUTPUT_IMAGE_PATH": "/absolute/path/to/your/images/directory"
}
}
}
}
Important Configuration Notes:
-
Replace paths with your actual paths:
- Change
/absolute/path/to/mcp-server-gemini-image-generatorto the actual location where you cloned this repository - Change
/absolute/path/to/your/images/directoryto where you want generated images to be saved
- Change
-
Environment Variables:
- Replace
your-actual-gemini-api-key-herewith your real Gemini API key from Google AI Studio - Use absolute paths for
OUTPUT_IMAGE_PATHto ensure images are saved correctly
- Replace
-
Example with real paths:
{
"mcpServers": {
"gemini-image-generator": {
"command": "uv",
"args": [
"--directory",
"/Users/username/Projects/mcp-server-gemini-image-generator",
"run",
"mcp-server-gemini-image-generator"
],
"env": {
"GEMINI_API_KEY": "GEMINI_API_KEY",
"OUTPUT_IMAGE_PATH": "OUTPUT_IMAGE_PATH"
}
}
}
}
Usage
Once installed and configured, you can ask Claude to generate or transform images using prompts like:
Generating New Images
- "Generate an image of a sunset over mountains"
- "Create an illustration of a futuristic cityscape"
- "Make a picture of a cat wearing sunglasses"
Transforming Existing Images
- "Transform this image by adding snow to the scene"
- "Edit this photo to make it look like it was taken at night"
- "Add a dragon flying in the background of this picture"
The generated/transformed images will be saved to the provided output_image_path when specified, otherwise to your configured default path (OUTPUT_IMAGE_PATH or ~/gen_image). With the updated return types, AI assistants can also work directly with the image data without needing to access the saved files.
Testing
You can test the application by running the FastMCP development server:
fastmcp dev server.py
This command starts a local development server and makes the MCP Inspector available at http://localhost:5173/. The MCP Inspector provides a convenient web interface where you can directly test the image generation tool without needing to use Claude or another MCP client. You can enter text prompts, execute the tool, and see the results immediately, which is helpful for development and debugging.
License
MIT License
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。