Enables image generation using Google's Imagen 4 Ultra AI model with advanced features including multiple aspect ratios, safety filtering levels, and support for both JPG and PNG output formats.
Provides access to Google's Imagen 4 Ultra model through Replicate's platform for high-quality image generation with configurable aspect ratios, output formats, and safety filtering. Includes automatic image download to local storage and prediction tracking 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., "@Replicate Imagen 4 MCP Servercreate a photo of a futuristic cityscape at sunset, 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.
Replicate Imagen 4 MCP Server
A Model Context Protocol (MCP) server that provides access to Google's Imagen 4 Ultra model through the Replicate platform. This server enables high-quality image generation with enhanced detail, richer lighting, and fewer artifacts.
π Repository: https://github.com/PierrunoYT/replicate-imagen4-mcp-server
π Ready to use! Works everywhere with npx - no local installation required.
Features
High-Quality Image Generation: Uses Google's Imagen 4 Ultra model via Replicate
Automatic Image Download: All generated images are automatically downloaded to local storage
Organized File Management: Images saved to dedicated 'images' directory with smart naming
Multiple Aspect Ratios: Support for 1:1, 16:9, 9:16, 3:4, and 4:3
Multiple Output Formats: JPG and PNG support
Safety Filtering: Configurable content safety levels
Dual Access: Returns both local file paths and original URLs
Prediction Tracking: Check status of running predictions
Portable Installation: Works anywhere with npx + GitHub
Robust Error Handling: Graceful handling of missing tokens and API errors
Connection Stability: No more unexpected disconnections or crashes
Detailed Responses: Returns image URLs, metadata, and generation details
Prerequisites
Node.js 18 or higher
Replicate API token
Installation
Option 1: Portable Installation (Recommended)
The easiest way to use this MCP server is with npx, which works anywhere without local installation:
Option 2: Local Installation
For local development or if you prefer to clone the repository:
Setup
1. Get your Replicate API Token
Visit Replicate
Sign up for an account
Navigate to your account settings
Generate an API token
2. Set Environment Variable
Set the REPLICATE_API_TOKEN environment variable:
Or create a .env file:
Automatic Image Download
π₯ How It Works
All generated images are automatically downloaded to your local machine for persistent storage and offline access:
1. Image Generation Flow
API Call: Server calls Replicate's Imagen 4 Ultra API
Response: Replicate returns an output object with URL method
Auto-Download: Server immediately downloads images to local storage
Response: Returns both local paths and original URLs
2. File Organization
Directory Structure:
Filename Format:
Prefix:
imagen4_Prompt: First 50 chars, sanitized (alphanumeric + underscores)
Index: Image number (for multiple images)
Timestamp: ISO timestamp for uniqueness
Extension:
.jpgor.pngbased on output format
3. Benefits
β
Persistent Storage: Images saved locally, not just temporary URLs
β
Offline Access: View images without internet connection
β
Organized Storage: All images in dedicated images directory
β
Unique Naming: No filename conflicts with timestamp system
β
Fallback Safety: Original URLs provided if download fails
Configuration
Quick Setup Helper
Run the path helper to get the exact configuration for your system:
This will output the complete MCP configuration with the correct absolute path.
For Claude Desktop
Add to ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %APPDATA%\Claude\claude_desktop_config.json (Windows):
For Kilo Code MCP Settings
Add to your MCP settings file at:
C:\Users\[username]\AppData\Roaming\Kilo-Code\MCP\settings\mcp_settings.json
Available Tools
imagen4_generate
Generate images using Imagen 4 Ultra with automatic local download.
Parameters:
prompt(required): Text prompt for image generationaspect_ratio(optional): "1:1", "9:16", "16:9", "3:4", or "4:3" (default: "1:1")safety_filter_level(optional): "block_low_and_above", "block_medium_and_above", or "block_only_high" (default: "block_only_high")output_format(optional): "jpg" or "png" (default: "jpg")
Features:
Automatic Download: Images automatically saved to local 'images' directory
Smart Naming: Generates descriptive filenames based on prompt and timestamp
Dual Access: Returns both local file paths and original URLs
Error Resilience: Graceful fallback if download fails
Response includes:
Local file path for immediate access
Original image URL as backup
Generation metadata and settings
Download status information
imagen4_generate_and_save
Generate images using Imagen 4 Ultra with custom filename support and automatic download.
Parameters:
prompt(required): Text prompt for image generationfilename(optional): Custom filename for the image (default: auto-generated)aspect_ratio(optional): "1:1", "9:16", "16:9", "3:4", or "4:3" (default: "1:1")safety_filter_level(optional): "block_low_and_above", "block_medium_and_above", or "block_only_high" (default: "block_only_high")output_format(optional): "jpg" or "png" (default: "jpg")
Features:
Custom Naming: Use your own filename for the image
Auto-Download: Images automatically saved to 'images' directory
Dual Access: Returns both local file paths and original URLs
Error Resilience: Graceful fallback if download fails
imagen4_get_prediction
Get the status and result of a specific Replicate prediction.
Parameters:
prediction_id(required): The ID of the prediction to check
Use this tool to:
Check the status of long-running predictions
Get detailed logs and error information
Retrieve results from async operations
Example Usage
Basic Image Generation
With Specific Parameters
Generate and Save to File
Using the Replicate API Directly
Here's how to use the Replicate API directly in your own code:
Technical Details
Architecture
Language: TypeScript with ES2022 target
Runtime: Node.js 18+ with ES modules
Protocol: Model Context Protocol (MCP) SDK v1.0.0
API Client: Replicate JavaScript client v0.34.1
Validation: Zod schema validation
API Model Used
Model:
google/imagen-4-ultraon ReplicateCapabilities: High-quality image generation with advanced safety filtering
Error Handling
Environment variable validation
API error catching and reporting
Network error handling for file downloads
Detailed error messages with context
Development
Project Structure
Scripts
npm run build- Compile TypeScript to JavaScriptnpm run dev- Watch mode for developmentnpm run start- Start the server directlynpm run test- Test server startup and basic functionalitynpm run get-path- Get configuration path for your system
Making Changes
Edit files in the
src/directoryRun
npm run buildto compileRestart your MCP client to use the updated server
Testing
This runs a basic connectivity test that verifies:
Server starts correctly
MCP protocol initialization
Tool discovery functionality
API Costs
This server uses the Replicate platform, which charges per image generation. Check Replicate pricing for current rates.
Typical costs (as of 2024):
Imagen 4 Ultra: ~$0.05-0.10 per image
Costs vary by resolution and complexity
Authentication
The Replicate API uses token-based authentication. Your token should be kept secure and not included in your code. Always use environment variables:
You can test your authentication with:
Troubleshooting
Server not appearing in MCP client
Verify the path to
build/index.jsis correct and absoluteCheck that your REPLICATE_API_TOKEN is set correctly in the environment variables
Ensure Node.js 18+ is installed:
node --versionTest server startup:
npm run testRestart your MCP client (Claude Desktop, Kilo Code, etc.)
Image generation failing
Verify your Replicate API token is valid and has sufficient credits
Check that your prompt follows Replicate's content policy
Try adjusting the safety filter level
Check the server logs for detailed error messages
Use the
imagen4_get_predictiontool to check prediction status
Build issues
If you need to rebuild the server:
Configuration issues
Use the helper script to get the correct path:
Support
For issues with:
This MCP server: Create an issue in this repository
Replicate API: Check Replicate documentation
MCP Protocol: See MCP documentation
License
MIT License - see LICENSE file for details.
Contributing
Fork the repository
Create a feature branch
Make your changes
Test with
npm run testSubmit a pull request