Enables text-to-image generation using Google's Imagen 4.0 models, including standard, fast, and ultra quality variants, with support for style transfer using Imagen 3 Customization, customizable aspect ratios, and batch generation capabilities.
Provides integration with Google Cloud's Vertex AI for accessing Imagen API, supporting authentication via Google Cloud Default Application Credentials and project-based configuration for text-to-image generation and style transfer.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@MCP Imagen Servercreate a logo for a coffee shop named 'Brew Haven' with a minimalist design"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
MCP Imagen Server
An MCP (Model Context Protocol) server for Google Imagen API, enabling text-to-image generation using Google's state-of-the-art Imagen models.
Features
Text-to-Image Generation: Generate high-quality images from text prompts using Imagen 4.0 models
Style Transfer: Generate images following the style of a reference image using Imagen 3 Customization
Background Removal: Remove backgrounds from images using rembg AI model
Auto-Crop: Automatically crop images to remove transparent or empty borders with batch processing support
Multiple Models: Support for three Imagen variants:
imagen-4.0-generate-001(default) - Standard quality and speedimagen-4.0-fast-generate-001- Faster generationimagen-4.0-ultra-generate-001- Highest quality (single image only)
Flexible Configuration:
Customizable aspect ratios (1:1, 3:4, 4:3, 9:16, 16:9)
Batch generation (1-4 images per request)
PNG output format with transparency support
Authentication Options:
Google Cloud Default Application Credentials
Vertex AI or Gemini API
Prerequisites
Python 3.11 or later
uv for package management
Google Cloud credentials (see Authentication)
Installation
1. Clone the Repository
git clone https://github.com/anton-proto/mcp-imagen.git
cd mcp-imagen/mcp-imagen-server2. Install with uv
# Install dependencies
uv sync
# Or install in development mode
uv sync --all-extras3. Set Up Authentication
Option A: Using Gemini API (Recommended for quick start)
Get an API key from Google AI Studio
Set the API key:
export GOOGLE_API_KEY="your-api-key-here"
Option B: Using Vertex AI (Recommended for production)
Install Google Cloud SDK:
# For Debian/Ubuntu curl https://sdk.cloud.google.com | bash exec -l $SHELLAuthenticate with Google Cloud:
gcloud auth application-default loginSet your project:
export GOOGLE_CLOUD_PROJECT="your-project-id" export USE_VERTEXAI="true" # Optional: specify location (default: us-central1) export GOOGLE_CLOUD_LOCATION="us-central1"
Usage
Running the Server
uv run mcp-imagen-serverThe server will start and listen for MCP requests via stdio.
Integration with Claude Desktop
Add this configuration to your Claude Desktop config file:
Location:
macOS:
~/Library/Application Support/Claude/claude_desktop_config.jsonWindows:
%APPDATA%\Claude\claude_desktop_config.jsonLinux:
~/.config/Claude/claude_desktop_config.json
Configuration:
{
"mcpServers": {
"imagen": {
"command": "uv",
"args": [
"--directory",
"/absolute/path/to/mcp-imagen-server",
"run",
"mcp-imagen-server"
],
"env": {
"GOOGLE_API_KEY": "your-api-key-here"
}
}
}
}For Vertex AI:
{
"mcpServers": {
"imagen": {
"command": "uv",
"args": [
"--directory",
"/absolute/path/to/mcp-imagen-server",
"run",
"mcp-imagen-server"
],
"env": {
"USE_VERTEXAI": "true",
"GOOGLE_CLOUD_PROJECT": "your-project-id",
"GOOGLE_CLOUD_LOCATION": "us-central1"
}
}
}
}Integration with Other MCP Clients
The server implements the standard MCP protocol and can be used with any MCP-compatible client.
MCP Tools
text-to-image
Generates images from text prompts using Google Imagen API.
Parameters
Parameter | Type | Required | Default | Description |
| string | Yes | - | Text description of the image to generate |
| string | Yes | - | Absolute path to directory where images should be saved |
| string | No |
| Imagen model to use (see Models) |
| integer | No | 1 | Number of images to generate (1-4, must be 1 for ultra model) |
| string | No |
| Aspect ratio of generated images (1:1, 3:4, 4:3, 9:16, 16:9) |
Models
imagen-4.0-generate-001: Standard model with balanced quality and speed
imagen-4.0-fast-generate-001: Faster generation with good quality
imagen-4.0-ultra-generate-001: Highest quality, single image only (sample_count must be 1)
Response
Returns a text response with paths to generated PNG files:
Successfully generated 2 image(s):
1. /path/to/output/A_serene_mountain_landscape_at_sunset_1.png
2. /path/to/output/A_serene_mountain_landscape_at_sunset_2.pngExample Usage
In Claude Desktop or other MCP client:
Generate an image of "A serene mountain landscape at sunset with a lake reflecting the sky" and save it to /tmp/images/style-to-image
Generates images following the style of a reference image using Imagen 3 Customization.
Parameters
Parameter | Type | Required | Description |
| string | Yes | Text description of the image content to generate |
| string | Yes | Absolute path to the style reference image file |
| string | Yes | Description of the style (e.g., "watercolor painting style", "neon sign style", "mosaic style") |
| string | Yes | Absolute path to directory where images should be saved |
| integer | No | Number of images to generate (1-4). Default: 1 |
Response
Returns a text response with paths to generated styled PNG files.
Example Usage
Generate an image of "A cat sitting on a windowsill" in the style of the image at /path/to/watercolor.png (watercolor painting style) and save it to /tmp/images/remove-background
Removes the background from an image using the rembg AI model, producing a PNG with transparent background.
Parameters
Parameter | Type | Required | Description |
| string | Yes | Absolute path to the input image file |
| string | No | Absolute path to save the output image. If not provided, will save with 'nobg_' prefix in same directory |
Response
Returns a text response with the path to the output image with transparent background:
Successfully removed background from image:
Output: /path/to/output/nobg_image.pngExample Usage
Remove the background from /home/user/images/photo.pngOr with custom output path:
Remove the background from /home/user/images/photo.png and save it to /home/user/outputs/transparent.pngautocrop
Automatically crop images to remove transparent or empty borders. Supports both single image and batch processing with parallel execution.
Parameters
Parameter | Type | Required | Description |
| array of strings | Yes | List of absolute paths to input image files to crop |
| string | No | Absolute path to output directory. If not provided, cropped images will be saved in the same directory as input files with '_cropped' suffix |
| integer | No | Number of pixels to add as padding around cropped content. Default: 0 |
| boolean | No | Whether to overwrite existing output files. Default: True. If False and output file exists, the operation will fail with an error |
Response
Returns a text response with processing summary and paths to cropped images:
Processed 3 image(s):
Successfully cropped: 3
Cropped images:
1. /output/dir/image1_cropped.png
2. /output/dir/image2_cropped.png
3. /output/dir/image3_cropped.pngIf any images fail to process, they will be listed separately:
Processed 3 image(s):
Successfully cropped: 2
Cropped images:
1. /output/dir/image1_cropped.png
2. /output/dir/image2_cropped.png
Failed: 1
- image3.png: Error: Image appears to be completely transparent or empty - cannot autocropFeatures
Parallel Processing: Multiple images are processed concurrently for better performance
Batch Support: Process multiple images in a single call
Flexible Output: Save to a specific directory or use default location
Padding Control: Add padding around cropped content if needed
Transparency Aware: Automatically detects and crops around non-transparent pixels
Example Usage
Single image:
Autocrop the image at /home/user/images/logo.pngMultiple images with output directory:
Autocrop these images: ["/home/user/images/logo1.png", "/home/user/images/logo2.png", "/home/user/images/logo3.png"] and save to /home/user/cropped/With padding:
Autocrop /home/user/images/logo.png with 10 pixels of padding and save to /home/user/output/With overwrite disabled (prevent overwriting):
Autocrop /home/user/images/logo.png and save to /home/user/output/ with overwrite disabledNote: By default, the tool will overwrite existing output files. Set overwrite=False to prevent accidental overwrites and raise an error if the output file already exists.
Development
Project Structure
mcp-imagen-server/
├── src/
│ └── mcp_imagen_server/
│ ├── __init__.py # Package initialization
│ ├── imagen_client.py # Imagen API client
│ └── server.py # MCP server implementation
├── pyproject.toml # Project configuration
├── README.md # This file
└── .python-version # Python versionCode Quality
The project uses ruff for linting and formatting:
# Check code
uv run ruff check src/
# Format code
uv run ruff format src/
# Auto-fix issues
uv run ruff check --fix src/Running Tests
# Run tests (when implemented)
uv run pytestEnvironment Variables
Variable | Description | Required | Default |
| Google AI API key for Gemini API | For Gemini API | - |
| Set to "true" to use Vertex AI | No | false |
| GCP project ID | For Vertex AI | - |
| GCP region | No | us-central1 |
Troubleshooting
Authentication Issues
Problem: DefaultCredentialsError or authentication failures
Solution:
For Gemini API: Ensure
GOOGLE_API_KEYis setFor Vertex AI: Run
gcloud auth application-default loginVerify your project has the Vertex AI API enabled
Permission Denied
Problem: Cannot write to output directory
Solution: Ensure the specified output_dir exists and is writable, or the server has permissions to create it
Model Not Available
Problem: Model not found or access denied
Solution:
Verify your Google Cloud project has access to Imagen models
Check that you're using a supported model name
For ultra model, ensure
sample_count=1
License
MIT License - See LICENSE file for details
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.