Enables AI-powered image generation using Google's Gemini and Imagen models, supporting multiple aspect ratios, dynamic model selection, and high-resolution (2K/4K) output with strong text-in-image rendering capabilities.
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., "@Imagen MCP Servergenerate a futuristic cityscape at sunset with flying cars in 16:9 aspect ratio"
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.
π¨ Imagen MCP Server
A high-quality Model Context Protocol (MCP) server that enables AI assistants to generate images using Google's Gemini and Imagen models.
π Overview
Imagen MCP provides AI-powered image generation capabilities to any MCP-compatible client (such as Claude Desktop, VS Code with GitHub Copilot, or custom applications). It connects to Google's AI platform to provide access to cutting-edge image generation models.
Why Use This MCP Server?
π Dynamic Model Selection: Query available models and choose the best one for your needs
πΌοΈ High-Quality Output: Access to Gemini and Imagen models for 2K/4K resolution images
π Flexible Aspect Ratios: Support for multiple aspect ratios (1:1, 16:9, 9:16, etc.)
π€ Text Rendering: Strong text-in-image rendering with Gemini models
οΏ½οΏ½ Secure Configuration: API keys stored securely via environment variables
π Easy Integration: Works with any MCP-compatible AI assistant
π¦ Minimal Dependencies: Only requires
fastmcp- all other functionality uses Python standard library
β¨ Features
Tool | Description |
| Verify API key configuration and connectivity |
| Discover available image generation models |
| Select which model to use for generation |
| Check which model is currently selected |
| Generate images from text descriptions |
| Generate using 1β3 reference images (can be included as actual content, as-is or modified per prompt) |
| Generate an image then resize/compress to target bounds |
| Generate with references then resize/compress |
| Save generated images to the filesystem |
| Generate and save in a single operation |
| Generate, resize/compress, and save an optimized output |
| Generate with references and save in one step |
| Generate with references, resize/compress, and save |
| Convert formats (png, jpeg, webp, heic/heif, ico) with favicon sizing |
π§ Prerequisites
Python 3.9+ (uses standard library features available in 3.9+)
Google AI API Key (Get one here)
Pillow (installed automatically via
requirements.txtfor resizing/optimization)pillow-heif (installed via
requirements.txtfor HEIC/HEIF support)An MCP-compatible client (Claude Desktop, VS Code with Copilot, etc.)
π Quick Start
1. Clone the Repository
2. Install Dependencies
Or using a virtual environment (recommended):
3. Configure API Key
Create a .env file in the project root:
Or set it as an environment variable directly in your MCP client configuration.
π‘ Tip: Get your API key from Google AI Studio
4. Test the Server
βοΈ Configuration
Environment Variables
Variable | Description | Required |
| Google AI API key | β Yes |
| Default model to use (defaults to | β No |
Model selection fallback (highest priority first): explicit tool parameter β runtime set_image_model β IMAGEN_MODEL_ID env var β built-in default gemini-3-pro-image-preview.
Supported Aspect Ratios
Aspect Ratio | Use Case |
| Social media posts, profile pictures |
| Photography, prints |
| Traditional displays |
| Instagram posts |
| Widescreen, mobile stories |
| Ultra-wide, cinematic |
Note: Not all models support all aspect ratios. The server will automatically retry without aspect ratio if not supported.
π MCP Client Integration
Claude Desktop
Add to your Claude Desktop configuration file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
VS Code with GitHub Copilot
Add to your VS Code MCP settings (.vscode/mcp.json or user settings):
Or run the VS Code command: MCP: Open User Configuration and add the server.
Using with uv (Recommended for Isolation)
If you have uv installed:
π Tools Reference
check_api_status
Verify that your API key is configured and working.
Parameters: None
Returns:
list_image_models
Discover available image generation models for your API key.
Parameters: None
Returns:
set_image_model
Select which model to use for image generation.
Parameters:
Parameter | Type | Required | Description |
| string | β | Model ID from |
Returns:
generate_image_from_prompt
Generate an image from a text description.
Parameters:
Parameter | Type | Required | Description |
| string | β | Detailed text description of the image |
| string | β | One of the supported aspect ratios |
| string | β | Override the current model |
Returns:
generate_image_with_references_from_files
Generate an image using 1β3 reference images (files on disk) plus a text prompt.
Important: reference images are visual inputs β you can instruct the model to include the referenced object/subject inside the generated image (as-is or modified), not only copy its style.
Parameters:
Parameter | Type | Required | Description |
| string[] | β | 1β3 paths to reference images (order matters) |
| string | β | Describe the output and how to use each reference (e.g., keep object identical vs modify) |
| string | β | Optional aspect ratio |
| string | β | Override the current model |
generate_image_with_references_resized_from_files
Same as generate_image_with_references_from_files, but additionally resizes/compresses to target bounds.
generate_and_save_image_with_references
Convenience tool that generates from references and saves to output_path (adds an extension if missing).
generate_and_save_image_with_references_resized
Convenience tool that generates from references, resizes/compresses, and saves to output_path.
save_image_to_file
Save a base64-encoded image to a file.
Parameters:
Parameter | Type | Required | Description |
| string | β | Base64-encoded image data |
| string | β | File path to save the image |
Returns:
generate_and_save_image
Generate an image and save it to a file in one operation.
Parameters:
Parameter | Type | Required | Description |
| string | β | Detailed text description of the image |
| string | β | File path to save the image |
| string | β | One of the supported aspect ratios |
| string | β | Override the current model |
Returns:
generate_image_resized_from_prompt
Generate an image, then resize/compress it to fit within given dimensions.
Parameters:
Parameter | Type | Required | Description |
| string | β | Detailed text description of the image |
| integer | β | Target max width in pixels |
| integer | β | Target max height in pixels |
| string | β | One of the supported aspect ratios |
| string | β | Override the current model |
| string | β | Output format ( |
| integer | β | Quality 1-100 (applies to JPEG/WEBP) |
Returns:
generate_and_save_image_resized
Generate an image, resize/compress it, and save to disk (kept separate from the high-res save path).
Parameters:
Parameter | Type | Required | Description |
| string | β | Detailed text description of the image |
| string | β | File path to save; extension inferred if missing |
| integer | β | Target max width in pixels |
| integer | β | Target max height in pixels |
| string | β | One of the supported aspect ratios |
| string | β | Override the current model |
| string | β | Output format ( |
| integer | β | Quality 1-100 (applies to JPEG/WEBP) |
Returns:
convert_image
Convert an image to another format, optionally emitting multi-size ICOs for favicons.
Parameters:
Parameter | Type | Required | Description |
| string | β | Source image path |
| string | β | Destination path (extension may be inferred from |
| string | β | One of |
| array | β | For ICO: list of sizes (e.g., |
Returns:
π‘ Usage Examples
Once the server is connected to your AI assistant, you can use natural language:
First-Time Setup
"Check if my API key is configured correctly" "List available image generation models" "Set the model to gemini-2.0-flash-exp-image-generation"
Basic Image Generation
"Generate a sunset over mountains with vibrant orange and purple colors"
Product Photography
"Create a product shot of a smartwatch on a minimalist white surface with dramatic lighting"
Specific Dimensions
"Generate a 16:9 banner image for a tech blog featuring abstract circuit patterns"
Save to Project
"Generate a hero image for my website and save it to assets/images/hero.png"
ποΈ Project Structure
π§© VS Code Extension (Optional)
You can manage the MCP server from inside VS Code via the bundled extension.
Build & Install
For End Users (Marketplace install β auto updates)
Install from the VS Code Marketplace (search βImagen MCP Serverβ). Marketplace installs auto-update with new releases.
After install: run the commands below to set your API key and model.
For Manual / VSIX Install
cd vscode-extensionnpm installnpm run package(createsimagen-mcp-vscode-<version>.vsix)In VS Code, run βExtensions: Install from VSIX...β and pick the
.vsix(updates require installing the new VSIX).
For Contributors (publish a release)
Set
publisherinvscode-extension/package.json(alreadygramini-consulting).Set
VSCE_PAT(Personal Access Token with Marketplace publish rights).cd vscode-extension && npm install && npm run package && npx vsce publish(bumps version before publish as needed).Tag the release in GitHub and attach the
.vsixfor non-marketplace installs.
Commands (Command Palette)
Imagen MCP: Set API Key β stored securely in VS Code Secret Storage.
Imagen MCP: Select Model β updates workspace setting
imagenMcp.modelId(defaultgemini-3-pro-image-preview).Imagen MCP: Generate MCP Config β writes
.vscode/mcp.jsonwiring the server command/args and env (GOOGLE_AI_API_KEYfrom secrets,IMAGEN_MODEL_IDfrom settings, falls back to built-in default).
Extension Settings
imagenMcp.modelId(defaultgemini-3-pro-image-preview)imagenMcp.serverCommand(defaultpython)imagenMcp.serverArgs(default["${workspaceFolder}/run_server.py"])
Tip: set imagenMcp.serverCommand to ./run_with_venv.sh if you prefer the helper script; arguments are typically empty in that case.
π‘οΈ Security Considerations
API Key Protection: Never commit your API key. Use environment variables or
.envfilesSecure Storage: The
.envfile is included in.gitignoreby defaultMCP Configuration: API keys can be passed securely via MCP client env configuration
File System Access: Be mindful of where images are saved
π Troubleshooting
Common Issues
"Missing API key" error
Ensure
GOOGLE_AI_API_KEYis set in your environment or.envfileCheck that the
.envfile is in the project root directoryVerify the key is passed in your MCP client configuration
"No model selected" error
Use
list_image_modelsto see available modelsUse
set_image_modelto select one before generating
"Aspect ratio is not enabled" error
The server automatically retries without aspect ratio
Some models don't support custom aspect ratios
No image models found
Your API key may not have access to image generation models
Check your Google AI Studio account for API access
Connection issues with MCP client
Verify the path in your MCP configuration is absolute
Check that Python is in your system PATH
Ensure all dependencies are installed
Debugging
Check your MCP client's logs:
Claude Desktop: Check the application logs
VS Code: View Output panel β MCP
π€ Contributing
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
Ways to Contribute
π Report bugs and issues
π‘ Suggest new features
π Improve documentation
π§ Submit pull requests
π License
This project is licensed under the MIT License - see the LICENSE file for details.
π Acknowledgments
Model Context Protocol - The protocol specification
FastMCP - Python MCP framework
Google Gemini - Image generation models
π¬ Support
Issues: GitHub Issues
Discussions: GitHub Discussions