MCP Image Gen
Generates images from text prompts using Google's Gemini AI models with customizable aspect ratios and resolutions up to 4K, automatically saving images locally.
README
MCP Image Gen
A Model Context Protocol (MCP) server for generating images using Google's Gemini AI models.
Features
- 🎨 Generate high-quality images from text prompts using Gemini AI
- 📐 Customizable aspect ratios (1:1, 16:9, 9:16, 4:3, 3:4)
- 🔧 Configurable image sizes (small to 4K resolution)
- ⚙️ Flexible configuration via JSON file
- 💾 Automatic local image saving with organized filenames (saves to ~/gemini_images by default)
- 🚀 Built on the MCP SDK for seamless integration
⚠️ Known Issues
- Aspect ratio and image size parameters may not be working correctly - Images are currently being generated in landscape format regardless of the specified aspect ratio. This is being investigated. The API calls appear correct, but the Gemini API may not be respecting the configuration parameters as expected.
Models Supported
- gemini-3-pro-image-preview (Default): Professional-grade, supports up to 4K resolution
- gemini-2.5-flash-image: Optimized for speed, generates 1024px resolution
Installation
- Clone the repository:
git clone https://github.com/Legorobotdude/mcp-image-gen.git
cd mcp-image-gen
- Install dependencies:
pnpm install
- Build the project:
pnpm build
Configuration
Environment Variables
Set your Gemini API key:
export GEMINI_API_KEY=your_api_key_here
Get your API key from Google AI Studio.
Config File (Optional)
Create a config.json file in the project root to customize defaults:
{
"model": "gemini-3-pro-image-preview",
"defaultAspectRatio": "1:1",
"defaultImageSize": "large",
"outputDirectory": "~/gemini_images"
}
Available Options:
model:"gemini-3-pro-image-preview"or"gemini-2.5-flash-image"defaultAspectRatio:"1:1","16:9","9:16","4:3", or"3:4"defaultImageSize:"small"(1K - 1024px)"medium"(2K - 2048px)"large"(2K - 2048px)"xlarge"(4K - 4096px - only for gemini-3-pro-image-preview)
outputDirectory: Path where generated images will be saved (default:~/gemini_images, can use absolute paths or~for home directory)
Usage with 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
{
"mcpServers": {
"mcp-image-gen": {
"command": "node",
"args": ["/absolute/path/to/mcp-image-gen/dist/index.js"],
"env": {
"GEMINI_API_KEY": "your_api_key_here"
}
}
}
}
Tool: generate_image
Generate an image from a text prompt.
Parameters
- prompt (required): Text description of the image to generate
- aspectRatio (optional): Aspect ratio -
"1:1","2:3","3:2","3:4","4:3","4:5","5:4","9:16","16:9","21:9" - imageSize (optional): Resolution -
"small"(1K),"medium"(2K),"large"(2K),"xlarge"(4K) - negativePrompt (optional): Describe what you DON'T want in the image
Example Usage in Claude
Generate an image of a serene mountain landscape at sunset with vibrant colors
Create a 16:9 image of a futuristic city skyline at night in xlarge size
Generate a portrait of a wise old wizard with a long beard, aspect ratio 3:4, medium size
Response Format
The tool returns a JSON response with:
{
"success": true,
"imagePath": "/Users/yourusername/gemini_images/1234567890_serene_mountain_landscape.png",
"prompt": "serene mountain landscape at sunset",
"model": "gemini-3-pro-image-preview",
"aspectRatio": "1:1",
"imageSize": "large",
"message": "Image generated successfully and saved to: /Users/yourusername/gemini_images/1234567890_serene_mountain_landscape.png"
}
Image Quality Notes
- All generated images include a SynthID watermark (Google's digital watermark)
- gemini-3-pro-image-preview: Best for high-quality, detailed images up to 4K
- gemini-2.5-flash-image: Best for quick generation, fixed at 1024px resolution
Development
Watch mode for development:
pnpm dev
Build for production:
pnpm build
Troubleshooting
"GEMINI_API_KEY environment variable is required"
Make sure you've set the GEMINI_API_KEY environment variable or added it to your MCP configuration.
Images not generating
- Check your API key is valid
- Verify you have internet connectivity
- Ensure the output directory is writable
Size options not working
The gemini-2.5-flash-image model only supports 1024px resolution regardless of the size parameter. Use gemini-3-pro-image-preview for higher resolutions.
License
MIT
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
E2B
Using MCP to run code via e2b.