Gemini Image Generation MCP Server
Provides image generation, editing, and refinement using Google's Gemini 2.5 Flash Image model.
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., "@Gemini Image Generation MCP Servergenerate an image of a serene mountain landscape at sunset"
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.
Gemini Image Generation MCP Server
A Model Context Protocol (MCP) Server that interfaces with Google's Gemini API for image generation using the Gemini 2.5 Flash Image model.
Features
Generate images using Gemini's 2.5 Flash Image model with various customization options
Edit and refine images using multimodal capabilities
Multi-image composition and style transfer
Conversational image refinement
Save generated images to local storage in specified folders
Support for multiple image formats (PNG, JPEG, WebP)
Include SynthID watermarking for AI-generated images
Related MCP server: Gemini Flash Image MCP Server
Installation
Install uv
On Mac you can install it using homebrew
brew install uvGetting a Gemini API Key
Navigate to Google AI Studio
Sign in with your Google Account
Look for "Get API key" or navigate to the API key management section
Follow the prompts to create a new key
Google AI Studio will generate a unique string of characters – this is your API key
Usage with Claude Code
Configure Claude Code to use this MCP server by updating your .cursor/mcp.json or other agent configuration:
{
"mcpServers": {
"gemini-image": {
"command": "uv",
"args": [
"--directory",
"/Users/marabian/mcp-servers/gemini-imagegen-mcp",
"run",
"mcp",
"run",
"main.py"
],
"env": {
"GEMINI_API_KEY": "your_api_key_here",
"DEFAULT_SAVE_DIR": "/path/to/default/save/directory"
}
}
}
}Important Configuration Notes:
Replace
your_api_key_herewith your actual Gemini API key.For the
DEFAULT_SAVE_DIR:Set this to a directory where you want to save all generated images
You can use a relative path like
./imageswithin your projectFor projects, consider using a path like
${PROJECT_ROOT}/generated-imagesDefaults to
./generated-imagesin the MCP server directory if not specified
When working in different projects:
The agent will save images to
DEFAULT_SAVE_DIRby defaultYou can override this within each tool call using the
save_dirparameterImages will be organized with unique timestamps to prevent conflicts
Available Tools
The Gemini Image Generation MCP Server provides the following tools:
Image Generation
generate_image- Generate an image based on a text promptedit_image- Edit existing images using multimodal promptsrefine_image- Refine an existing image with conversational instructionsget_available_models- List available Gemini image generation models
Image Management
list_saved_images- List images saved in the specified directoryset_save_directory- Set the directory where generated images will be saved
Tool Parameters
generate_image
prompt(required): The text prompt describing the image to generatemodel: Model to use (default: "gemini-2.5-flash-image-preview")temperature: Controls randomness (0.0-1.0, default: 0.7)top_p: Controls nucleus sampling (0.0-1.0, default: 0.95)top_k: Controls top-k sampling (default: 40)max_output_tokens: Maximum tokens to generate (optional)save_dir: Directory to save images (optional, uses default if not specified)filename: Custom filename (optional, timestamp-based if not specified)include_text_response: Include text alongside images (default: true)
edit_image
prompt(required): Instructions for editing the imageimage_paths(required): List of image file paths to edit (up to 3 recommended)model: Model to use (default: "gemini-2.5-flash-image-preview")temperature: Controls randomness (0.0-1.0, default: 0.7)top_p: Controls nucleus sampling (0.0-1.0, default: 0.95)top_k: Controls top-k sampling (default: 40)max_output_tokens: Maximum tokens to generate (optional)save_dir: Directory to save images (optional, uses default if not specified)filename: Custom filename (optional, timestamp-based if not specified)include_text_response: Include text alongside images (default: true)
refine_image
prompt(required): Original prompt used to generate the imageprevious_image_path(required): Path to the image to refinerefinement_instruction(required): Instructions for refinementmodel: Model to use (default: "gemini-2.5-flash-image-preview")temperature: Controls randomness (0.0-1.0, default: 0.7)save_dir: Directory to save images (optional, uses default if not specified)filename: Custom filename (optional, timestamp-based if not specified)
Examples
Generating a Basic Image
# Generate a landscape image
generate_image(
prompt="A serene mountain landscape at sunset with a lake reflection",
temperature=0.8,
save_dir="/path/to/project/images",
filename="mountain_sunset"
)Editing an Existing Image
# Edit an image to add elements
edit_image(
prompt="Add a small wooden boat on the lake",
image_paths=["/path/to/mountain_sunset.png"],
temperature=0.7,
save_dir="/path/to/project/edits",
filename="mountain_with_boat"
)Multi-Image Composition
# Combine multiple images into one scene
edit_image(
prompt="Create a cohesive fantasy scene combining these elements",
image_paths=[
"/path/to/dragon.png",
"/path/to/castle.png",
"/path/to/forest.png"
],
temperature=0.6,
filename="fantasy_scene"
)Conversational Refinement
# Refine an existing image with specific instructions
refine_image(
prompt="A modern office workspace",
previous_image_path="/path/to/office.png",
refinement_instruction="Make the lighting warmer and add some plants",
filename="office_warmer"
)Advanced Generation with Style Control
# Generate with specific artistic style
generate_image(
prompt="A portrait of a wise old wizard in the style of Renaissance paintings, oil on canvas, dramatic lighting, detailed brushwork",
temperature=0.5,
top_p=0.9,
max_output_tokens=2000,
filename="renaissance_wizard"
)Model Features
Gemini 2.5 Flash Image
Text-to-Image Generation: Create images from detailed text descriptions
Image Editing: Modify existing images with natural language instructions
Multi-Image Composition: Combine multiple input images into new scenes
Style Transfer: Apply artistic styles from reference images
Conversational Refinement: Iteratively improve images through dialogue
World Knowledge: Leverages Gemini's understanding for contextually accurate images
Character Consistency: Maintain consistent appearance across multiple generations
SynthID Watermarking: All generated images include invisible AI identification
Pricing
Image Generation: $30 per 1 million output tokens
Tokens per Image: 1,290 tokens
Cost per Image: ~$0.039
Best Practices
Prompt Writing
Be Descriptive: Use detailed, narrative descriptions rather than keyword lists
Include Photography Terms: For realistic images, mention camera angles, lens types, lighting
Specify Style: Clearly indicate artistic style, medium, or technique desired
Provide Context: Include setting, mood, and atmospheric details
Image Editing
Start with Quality Input: Use high-resolution, clear input images
Limit Input Images: Use up to 3 input images for optimal results
Be Specific: Provide clear instructions about what to change or add
Iterate Gradually: Make incremental changes for better control
Performance Optimization
Use Appropriate Temperature: Lower values (0.3-0.5) for precise results, higher (0.7-1.0) for creativity
Control Token Usage: Set
max_output_tokenswhen appropriateBatch Related Tasks: Generate multiple variations in sequence for consistency
Troubleshooting
Common Issues
API Key Errors: Ensure your Gemini API key is valid and has image generation permissions
File Not Found: Check that image paths exist and are accessible
Large File Sizes: Generated images may be large; ensure sufficient disk space
Rate Limits: Gemini API has usage limits; implement appropriate delays between requests
Error Messages
GEMINI_API_KEY environment variable not set: Set your API key in the environmentImage file does not exist: Verify the provided image path is correctInvalid model: Use supported model names like "gemini-2.5-flash-image-preview"
Limitations
Input Image Limit: Best results with up to 3 input images
Supported Languages: Optimized for EN, es-MX, ja-JP, zh-CN, hi-IN
File Formats: Supports PNG, JPEG, WebP for both input and output
Content Policy: Subject to Google's AI content policies
Contributing
This MCP server is based on the Model Context Protocol. To contribute:
Fork the repository
Create a feature branch
Make your changes
Test thoroughly
Submit a pull request
License
This project follows the same license terms as the Model Context Protocol.
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/marabian/gemini-imagen-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server