Enables AI-powered image generation and editing using Google's Gemini 2.5 Flash Image API, with automatic prompt enhancement via Gemini 2.0 Flash for superior image quality
MCP Image Generator
A powerful MCP (Model Context Protocol) server that enables AI assistants to generate and edit images using Google's Gemini 2.5 Flash Image API. Seamlessly integrate advanced image generation capabilities into Claude Code, Cursor, and other MCP-compatible AI tools.
✨ Features
- AI-Powered Image Generation: Create images from text prompts using Gemini 2.5 Flash Image Preview
- Intelligent Prompt Enhancement: Automatically optimizes your prompts using Gemini 2.0 Flash for superior image quality
- Adds photographic and artistic details
- Enriches lighting, composition, and atmosphere descriptions
- Preserves your intent while maximizing generation quality
- Image Editing: Transform existing images with natural language instructions
- Context-aware editing that preserves original style
- Maintains visual consistency with source image
- Advanced Options:
- Multi-image blending for composite scenes
- Character consistency across generations
- World knowledge integration for accurate context
- Multiple Output Formats: PNG, JPEG, WebP support
- File Output: Images are saved as files for easy access and integration
🔧 Prerequisites
- Node.js 20 or higher
- Gemini API Key - Get yours at Google AI Studio
- Claude Code or Cursor (or any MCP-compatible AI tool)
- Basic terminal/command line knowledge
🚀 Quick Start
1. Get Your Gemini API Key
Get your API key from Google AI Studio
2. MCP Configuration
For Claude Code
For Cursor
Add to your Cursor settings:
- Global (all projects):
~/.cursor/mcp.json
- Project-specific:
.cursor/mcp.json
in your project root
⚠️ Security Note: Never commit your API key to version control. Keep it secure and use environment-specific configuration.
📁 Path Requirements:
IMAGE_OUTPUT_DIR
must be an absolute path (e.g.,/Users/username/images
, not./images
)- Defaults to
./output
in the current working directory if not specified - Directory will be created automatically if it doesn't exist
Optional: Skip Prompt Enhancement
Set SKIP_PROMPT_ENHANCEMENT=true
to disable automatic prompt optimization and send your prompts directly to the image generator. Useful when you need full control over the exact prompt wording.
Claude Code:
Cursor:
Add "SKIP_PROMPT_ENHANCEMENT": "true"
to the env section in your config.
📖 Usage Examples
Once configured, your AI assistant can generate images using natural language:
Basic Image Generation
The system automatically enhances this to include rich details about lighting, materials, composition, and atmosphere for optimal results.
Image Editing
Advanced Features
🔧 API Reference
generate_image
Tool
The MCP server exposes a single tool for all image operations. Internally, it uses a two-stage process:
- Prompt Optimization: Gemini 2.0 Flash analyzes and enriches your prompt
- Image Generation: Gemini 2.5 Flash Image Preview creates the final image
Parameters
Parameter | Type | Required | Description |
---|---|---|---|
prompt | string | ✅ | Text description or editing instruction |
inputImagePath | string | ❌ | Absolute path to input image for editing |
fileName | string | ❌ | Custom filename for output (auto-generated if not specified) |
blendImages | boolean | ❌ | Enable multi-image blending |
maintainCharacterConsistency | boolean | ❌ | Maintain character appearance across generations |
useWorldKnowledge | boolean | ❌ | Use real-world knowledge for context |
Response
🛠️ Troubleshooting
Common Issues
"API key not found"
- Ensure
GEMINI_API_KEY
is set in your environment - Verify the API key is valid and has image generation permissions
"Input image file not found"
- Use absolute file paths, not relative paths
- Ensure the file exists and is accessible
- Supported formats: PNG, JPEG, WebP (max 10MB)
"No image data found in Gemini API response"
- Try rephrasing your prompt with more specific details
- Ensure your prompt is appropriate for image generation
- Check if your API key has sufficient quota
Performance Tips
- Image generation: 30-60 seconds typical (includes prompt optimization)
- Image editing: 15-45 seconds typical (includes context analysis)
- Simple prompts work great - the AI automatically adds professional details
- Complex prompts are preserved and further enhanced
- Consider enabling
useWorldKnowledge
for historical or factual subjects
💰 Usage Notes
- This MCP server uses the paid Gemini API for both prompt optimization and image generation
- Gemini 2.0 Flash for intelligent prompt enhancement (minimal token usage)
- Gemini 2.5 Flash Image Preview for actual image generation
- Check current pricing and rate limits at Google AI Studio
- Monitor your API usage to avoid unexpected charges
- The prompt optimization step adds minimal cost while significantly improving output quality
📄 License
MIT License - see LICENSE for details.
Need help? Open an issue or check the troubleshooting section above.
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
Tools
Enables AI assistants to generate and edit images using Google's Gemini 2.5 Flash Image API with intelligent prompt enhancement. Supports text-to-image generation, image editing with natural language instructions, and advanced features like character consistency and multi-image blending.