The full upstream README, mirrored here for reference. Install config, tool schemas, adoption signals, and an original overview live on the Gemini Image listing page.
A simple, focused MCP server for Google Gemini's native image generation — the "Nano Banana" models. Generate, edit, and locally process images from Claude Code, Claude Desktop, or any stdio-based MCP client. Two tools, no bloat.
Built for agents: a single call returns a saved image — or, with one-call background removal, a ready-to-use transparent PNG — without streaming image data through your agent's context. Uses Gemini's generateContent API (not the deprecated Imagen API).
Or use directly with npx:
Claude Code (one command):
Requires a GEMINI_API_KEY environment variable — see Setup for details.
Set up a config file (optional):
Creates ~/.gemini-image-mcp.json with commented defaults. For project-specific overrides:
thinkingLevel: "HIGH" for renders that depend on reasoning (infographics, diagrams, dense typography); cheap MINIMAL default otherwiseremoveBackground returns a clean transparent PNG: a local AI matte (works on any subject; optional add-on, see below) by default, or built-in green-screen / white-threshold keying. No extra API costsessionId to refine an image across calls, with prior turns kept as context"web+image" also pulls image-search results for mood boards and trend references, with sources returned for attribution. See Advanced Featuresgenerations.jsonl logs every generation with prompt, params, costGo to Google AI Studio and create an API key.
Billing required: image generation has no free tier — free-tier keys get
429 RESOURCE_EXHAUSTED(quota limit 0) on every image model. Enable pay-as-you-go billing on the key's Google Cloud project (usage & billing). Images cost ~$0.03–$0.24 each depending on model and resolution; the cheapest model (gemini-3.1-flash-lite-image, the default) is ~$0.034 per image.
The server reads your key from the GEMINI_API_KEY environment variable. Set it once so it's available in every session:
Windows (PowerShell — run as admin):
Then restart your terminal.
macOS / Linux:
(Use ~/.zshrc if you're on zsh.)
Verify it's set:
Pick the method that matches how you use MCP:
Claude Code will pick up GEMINI_API_KEY from your environment automatically.
.mcp.json)Add to .mcp.json in your project root or ~/.claude/.mcp.json for global access:
The ${GEMINI_API_KEY} syntax reads the value from your shell environment — your actual key never gets written into config files.
Edit claude_desktop_config.json:
~/Library/Application Support/Claude/claude_desktop_config.json%APPDATA%\Claude\claude_desktop_config.jsonRestart Claude Desktop after saving.
Any client that supports stdio transport works. Point it at npx -y @jimothy-snicket/gemini-image-mcp and pass GEMINI_API_KEY in the environment.
${GEMINI_API_KEY} syntax in config files references your environment — the key itself stays in your shell profile..mcp.json is in a project repo, add it to .gitignore or use the global config at ~/.claude/.mcp.json instead.All optional. The only required setup is GEMINI_API_KEY (covered above).
| Variable | Default | Description |
|---|---|---|
OUTPUT_DIR | ~/gemini-images | Default directory for saved images |
DEFAULT_MODEL | gemini-3.1-flash-lite-image | Default Gemini model |
LOG_LEVEL | info | debug, info, or error |
REQUEST_TIMEOUT_MS | 60000 | API request timeout in milliseconds |
MAX_REQUESTS_PER_HOUR | 0 (unlimited) | Max image generations per rolling hour |
MAX_COST_PER_HOUR | 0 (unlimited) | Max estimated cost (USD) per rolling hour |
SESSION_TIMEOUT_MS | 1800000 (30min) | Multi-turn session expiry |
GEMINI_IMAGE_AUTO_INSTALL | 1 (on) | Auto-install the AI matte engine on first removeBackground: { mode: "auto" } use. Set 0 to disable (then auto falls back to chroma/threshold with instructions) |
Set these the same way as GEMINI_API_KEY, or pass them in the env block of your MCP config.
Rate limiting is recommended when agents have access to this tool. An agent in a loop can generate images quickly — set MAX_REQUESTS_PER_HOUR=20 and MAX_COST_PER_HOUR=5 as sensible defaults.
Instead of environment variables, you can use a JSON config file. Create one with:
This creates ~/.gemini-image-mcp.json with all defaults and inline documentation. Edit it to set your preferences.
Priority: env vars > local config (.gemini-image-mcp.json in CWD) > global config (~/.gemini-image-mcp.json) > defaults.
You can also set per-tool defaults so every request uses your preferred settings:
Per-request parameters always override config defaults.
Custom pricing. Cost estimates come from a built-in per-token rate table (there's no pricing API to fetch live). If you use a model the table doesn't know yet — or Google changes a rate before this package updates — add pricingOverrides so cost reporting stays accurate without waiting for a release:
Models with no entry (built-in or override) still generate — their cost is reported as unknown rather than guessed.
generate_image| Parameter | Required | Description |
|---|---|---|
prompt | Yes | Text description or editing instruction |
images | No | Array of file paths to input/reference images |
model | No | Gemini model ID |
aspectRatio | No | 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9, plus 1:4, 4:1, 1:8, 8:1 (gemini-3.1-flash-image). Validated by the API. |
resolution | No | 512 (gemini-3.1-flash-image only), 1K, 2K, 4K |
outputDir | No | Override output directory for this request |
filename | No | Base name for saved file (e.g. hero-banner). Auto-versioned if duplicate. |
subfolder | No | Subfolder within output directory (e.g. landing-page) |
sessionId | No | Continue a multi-turn editing session from a previous response |
seed | No | Integer seed for reproducible generation |
grounding | No | "web" = Google Search grounding; "web+image" adds image-search results (gemini-3.1-flash-image only). See Advanced Features |
useSearchGrounding | No | Legacy alias for grounding: "web" |
thinkingLevel | No | "MINIMAL" (default) or "HIGH" — thinking depth on the gemini-3.1-flash family. See Advanced Features |
videos | No | Array of file paths to input videos for video-to-image (gemini-3.1-flash family). See Advanced Features |
removeBackground | No | Return a transparent PNG cutout. { "mode": "auto" } = local AI matte (any subject; default); { "mode": "chroma" } = green screen; { "mode": "threshold" } = white removal (line art). No extra API cost |
Text-to-image:
"Generate a hero image for a SaaS landing page, modern gradient style, 16:9"
Image editing:
"Take this screenshot and redesign the header with a dark theme" (with image paths)
Iterative editing (multi-turn):
Generate an image, then call again with the returned
sessionIdand a refinement like "make it more minimal" — the prior image stays in context.
Organized output:
"Generate a hero banner" with
filename: "hero",subfolder: "landing-page"→ saves to~/gemini-images/landing-page/hero.png
High quality:
"A photorealistic product shot of headphones on marble, 4K" (using gemini-3-pro-image)
Transparent asset (one call):
"A glossy red sneaker, product shot" with
removeBackground: { "mode": "auto" }→ a ready-to-place transparent PNG. The local AI matte works on any subject — no green screen needed.
process_imageLocal image processing via sharp. Free, fast, no API calls.
| Parameter | Required | Description |
|---|---|---|
imagePath | Yes | Path to the image file to process |
crop | No | Crop by pixel dimensions, aspect ratio, or focal point strategy |
resize | No | Resize to width/height (maintains aspect ratio) |
removeBackground | No | Remove background: { "mode": "auto" } (AI matte, any subject), { "mode": "chroma" } (green screen), or { "mode": "threshold" } (white). Defaults to chroma if color set, else threshold |
trim | No | Auto-remove whitespace/transparent borders |
format | No | Convert to png, jpeg, or webp |
quality | No | Output quality for JPEG/WebP (1-100) |
filename | No | Base name for saved file. Auto-versioned if duplicate. |
subfolder | No | Subfolder within output directory |
outputDir | No | Override output directory |
mode: "auto" runs a local BiRefNet matte that isolates the subject semantically — so it handles hair, glass, and green/yellow subjects that chroma key can't. The matte engine isn't bundled (keeps the base install ~65 MB). On your first auto call the server auto-installs it (@huggingface/transformers, ~340 MB) plus the fp16 model (~109 MB) — a one-time pause of a minute or two, then it runs locally with no extra API cost. Set GEMINI_IMAGE_AUTO_INSTALL=0 to disable auto-install (then auto falls back to returning the image with instructions to install it manually). chroma and threshold need nothing extra.
Chroma key (mode: "chroma") uses HSV keying with smoothstep feathering, spill suppression, and 5-pass edge anti-aliasing (default tolerance 80). Use #00FF00 for AI-generated green screens — it works better than matching the exact shade Gemini produces.
Note: Chroma key destroys subjects that share the key colour (green/yellow) and transparent/reflective subjects (glass) — the green parrot vanishes. For those, use mode: "auto" (the AI matte preserves them), or the canvas approach: feed a solid-colour background image to generate_image and let Gemini place the subject with correct lighting. The canvas approach is still best for truly transparent objects like glass, which should transmit the final background rather than be cut out.
Subject on a specific background (canvas approach):
One API call. Best for yellow, green, or glass subjects where chroma key struggles.
Transparent asset (one call):
One API call → a transparent PNG. The local AI matte works on any subject. (For truly transparent/reflective objects like glass, the canvas approach above is still best.)
Transparent asset from green screen (zero-dependency):
Avoids the matte model entirely — best for high-contrast subjects on locked-down/offline machines.
Favicon from a generated logo:
Social card from a photo:
WebP conversion for web:
These are opt-in knobs on generate_image. Most requests don't need them — they're documented here rather than in the tool schema to keep agent context small.
videos)The model watches your video and synthesizes a new image from what it understood — the subject, mood, colors, and action — rather than copying a frame. If you just want a frame, use ffmpeg; this is for images that require understanding the footage:
gemini-3.1-flash-image, gemini-3.1-flash-lite-image); other models reject it.mp4, mov, webm, avi, mpeg, wmv, flv, 3gpp), max 500MB each, up to 3 per call. Each video is uploaded to Google's Files API, polled until processed, used for the call, then deleted. Video tokens count as input (a 2s clip ≈ 140 tokens).sessionId — sessions are text+image only, and video turns don't create sessions (the upload is deleted after the call, so a stored session would replay a dead reference).REQUEST_TIMEOUT_MS (which only bounds the generation call itself).thinkingLevel)All Gemini 3 image models "think" before rendering. The default MINIMAL keeps cost and latency down. Use "HIGH" for renders where quality depends on reasoning: infographics, diagrams, menus, dense typography, multi-step compositions.
Supported on the gemini-3.1-flash family (API validates elsewhere). Can be set as a project default via defaults.generate.thinkingLevel in the config file.
grounding: "web+image")grounding: "web" grounds the render in live Google Search results (weather, stock charts, current events). "web+image" — exclusive to gemini-3.1-flash-image — also pulls in image-search results, useful for mood boards and trend references.
When grounding is used, the response includes a grounding object: source chunks (URI + title, up to 5), searchQueries, and searchEntryPointHtml. Google's Terms of Service require displaying the search suggestions entry point when you show grounded results — pass searchEntryPointHtml through to the user (it is render-ready HTML provided by Google for exactly this purpose).
Not supported on gemini-3.1-flash-lite-image (the API rejects grounding there).
| Model | Strengths | Resolution | Notes |
|---|---|---|---|
gemini-3.1-flash-lite-image | Cheapest (~$0.034/image), video input | 1K | Default (Nano Banana 2 Lite). No search grounding; up to 14 reference images but not optimized for multi-image or multi-turn editing — prefer 3.1-flash for those |
gemini-3.1-flash-image | Speed + quality, search grounding (web + image), video input | 512, 1K, 2K, 4K | ~$0.07/1K image. Up to 10 object + 4 character + 3 style reference images |
gemini-3-pro-image | Best quality, text rendering | 1K, 2K, 4K | ~$0.13/1K image. Up to 6 object + 5 character reference images |
gemini-2.5-flash-image | Legacy | 1K | Shuts down 2026-10-02 |
The retired -preview IDs (gemini-3-pro-image-preview, gemini-3.1-flash-image-preview) may still appear in your key's model list but were retired 2026-06-25 — use the GA IDs above. The server discovers whichever image models your API key supports at startup and validates each request against that live list, so new models work without an update.
MIT