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.
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
2. Install with uv
3. 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
The 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:
For Vertex AI:
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:
Example Usage
In Claude Desktop or other MCP client:
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
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:
Example Usage
Or with custom output path:
autocrop
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:
If any images fail to process, they will be listed separately:
Features
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:
Multiple images with output directory:
With padding:
With overwrite disabled (prevent overwriting):
Note: 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
Code Quality
The project uses ruff for linting and formatting:
Running Tests
Environment 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.