
trevoruptain/gemini-image-mcp
Productivity workflowAn MCP server for Cursor to generate, store, and reuse images using Google Nano Banana Pro (better than Antigravity's image tool)
Overview
An MCP (Model Context Protocol) server optimized for web development that enables AI assistants to generate and edit images using Google's Gemini API. After adding the MCP server to Cursor, just prompt the AI to generate or edit images for you - the agent will do the rest. - - Generate images with aspect ratio presets (hero, square, portrait, landscape, banner, mobile) and resolutions up to 4K - - Edit existing images in your workspace with natural language - - Presets designed for common web development use cases - - Access generated images as MCP resources - - Express server for direct HTTP access to images - Node.js 18+ - A Google Gemini API key with access to image generation Use the MCP Inspector to test and debug your server: This will: 1. Build the TypeScript code 2. Launch the MCP Inspector in your browser 3. Allow you to test tools, view resources, and debug requests/responses Make sure your .env file is set up with GEMINI_API_KEY before running the inspector.
README
Gemini Image MCP
An MCP (Model Context Protocol) server optimized for web development that enables AI assistants to generate and edit images using Google’s Gemini API.
After adding the MCP server to Cursor, just prompt the AI to generate or edit images for you - the agent will do the rest.
Features
- Image Generation - Generate images with aspect ratio presets (hero, square, portrait, landscape, banner, mobile) and resolutions up to 4K
- Image Editing - Edit existing images in your workspace with natural language
- Web-Optimized - Presets designed for common web development use cases
- MCP Resources - Access generated images as MCP resources
- Static File Server - Express server for direct HTTP access to images
Prerequisites
- Node.js 18+
- A Google Gemini API key with access to image generation
Installation
git clone https://github.com/yourusername/gemini-image-mcp.git
cd gemini-image-mcp
npm install
npm run build
Configuration
Environment Variables
| Variable | Required | Default | Description |
|---|---|---|---|
GEMINI_API_KEY |
Yes | - | Your Google Gemini API key |
GEMINI_IMAGE_MODEL |
No | gemini-3-pro-image-preview |
Gemini image model to use. Use gemini-2.5-flash-image for the GA model. |
PORT |
No | 3001 |
Port for the Express static file server |
Cursor
Add to your ~/.cursor/mcp.json:
{
"mcpServers": {
"gemini-image": {
"command": "node",
"args": ["/path/to/gemini-image-mcp/dist/server.js"],
"env": {
"GEMINI_API_KEY": "your-api-key-here"
}
}
}
}
Antigravity
Add to your MCP server configuration:
{
"gemini-image": {
"command": "node",
"args": ["/path/to/gemini-image-mcp/dist/server.js"],
"env": {
"GEMINI_API_KEY": "your-api-key-here"
}
}
}
Claude Desktop
Add to your claude_desktop_config.json:
{
"mcpServers": {
"gemini-image": {
"command": "node",
"args": ["/path/to/gemini-image-mcp/dist/server.js"],
"env": {
"GEMINI_API_KEY": "your-api-key-here"
}
}
}
}
Testing with MCP Inspector
Use the MCP Inspector to test and debug your server:
npm run inspect
This will:
- Build the TypeScript code
- Launch the MCP Inspector in your browser
- Allow you to test tools, view resources, and debug requests/responses
Make sure your .env file is set up with GEMINI_API_KEY before running the inspector.
Tools
generate_image
Generate an image from a text prompt, optionally using reference images to guide the style or composition. The AI must determine the correct output path in your project before calling this tool.
| Parameter | Type | Required | Description |
|---|---|---|---|
prompt |
string | Yes | Text description of the image to generate |
outputPath |
string | Yes | Absolute path where the image should be saved (e.g., /Users/you/project/public/images/hero.png) |
referenceImages |
string[] | No | Array of absolute paths to reference images for style/composition guidance |
aspectRatio |
string | No | Preset: hero (16:9), square (1:1), portrait (3:4), landscape (4:3), banner (21:9), mobile (9:16) or explicit ratio |
resolution |
string | No | 1K (default), 2K, or 4K |
Example (text-to-image):
{
"prompt": "A modern hero image for a tech startup website with abstract geometric shapes",
"outputPath": "/Users/you/my-project/public/images/hero.png",
"aspectRatio": "hero",
"resolution": "2K"
}
Example (with reference images):
{
"prompt": "Create a new image in the same style as the reference, but with a mountain landscape",
"outputPath": "/Users/you/my-project/public/images/mountain.png",
"referenceImages": ["/Users/you/my-project/public/images/style-reference.png"],
"aspectRatio": "landscape"
}
Output:
{
"path": "/Users/you/my-project/public/images/hero.png",
"url": "http://localhost:3001/images/hero.png",
"aspectRatio": "16:9",
"resolution": "2K"
}
edit_image
Edit an existing image using natural language. The AI must determine the correct output path before calling this tool.
| Parameter | Type | Required | Description |
|---|---|---|---|
prompt |
string | Yes | Description of what to change |
sourceImage |
string | Yes | Absolute path to the source image file |
outputPath |
string | Yes | Absolute path where the edited image should be saved |
aspectRatio |
string | No | Optionally change aspect ratio during edit |
resolution |
string | No | 1K (default), 2K, or 4K |
Example:
{
"prompt": "Change the background color to a gradient of blue and purple",
"sourceImage": "/Users/you/my-project/public/images/hero.png",
"outputPath": "/Users/you/my-project/public/images/hero-edited.png"
}
Aspect Ratio Presets
| Preset | Ratio | Common Use Case |
|---|---|---|
hero |
16:9 | Hero sections, headers |
square |
1:1 | Thumbnails, avatars, icons |
portrait |
3:4 | Cards, profile images |
landscape |
4:3 | Blog images, galleries |
banner |
21:9 | Wide banners, headers |
mobile |
9:16 | Mobile screens, stories |
How It Works
Images are saved to two locations:
- Your project - At the
outputPathyou specify (e.g.,/Users/you/my-project/public/images/hero.png) - MCP server - Also saved to
./images/and served via Express athttp://localhost:3001/images/
This means:
- Images appear immediately in your project
- Images are also accessible via HTTP for previewing
- MCP resources list all generated images
Development
# Run in development mode with hot reload
npm run dev
# Build for production
npm run build
# Start production server
npm start
Project Structure
gemini-image-mcp/
├── server.ts # MCP server implementation
├── package.json
├── tsconfig.json
├── images/ # Generated images directory
└── dist/ # Compiled output
License
MIT
Install
This server does not publish a one-line install command.
Open the repository installation guide New to MCP? Start with the mcpskill.org guide →Configuration
{
"mcpServers": {
"gemini-image": {
"command": "node",
"args": ["/path/to/gemini-image-mcp/dist/server.js"],
"env": {
"GEMINI_API_KEY": "your-api-key-here"
}
}
}
}