
Gemini Image
io.github.JimothySnicket由 GitHub 帳號 JimothySnicket 發布v0.6.2更新於 Oct 24, 2026
Google Gemini image generation, editing, and local processing via MCP
概覽
一個本機 MCP 伺服器,讓助理用 Google Gemini 模型生成與編輯圖像,並在本機處理圖像,結果儲存到磁碟。
- 可以做什麼
- 依文字提示、參考圖像或影片生成圖像,可設定模型、長寬比、解析度、隨機種子與思考深度,並可在一次呼叫中輸出透明 PNG 去背結果。透過工作階段 ID 進行多輪編輯,並可用 Google 搜尋結果作為生成依據。不需呼叫 API 即可在本機處理圖像:裁切、縮放、去除邊框、以色度鍵或閾值去除背景,以及在 PNG、JPEG 與 WebP 之間轉換。以有意義的檔名與子資料夾儲存輸出,並記錄每次生成的提示、參數與預估費用。
- 適用情境
- 適合讓助理製作或修改圖像,例如橫幅、產品圖、縮圖或透明素材,也適合快速在本機裁切、縮放與轉換格式,且圖像資料不經過模型上下文。
- 執行需求
- 以本機 stdio 程序執行,通常透過 npx 與 Node.js 啟動。需要來自 Google AI Studio 的 GEMINI_API_KEY 環境變數,並在該金鑰所屬的 Google Cloud 專案啟用按量計費,因為圖像生成沒有免費額度。生成需要連線至 Google API 的網路;本機處理可離線使用。選用設定包括 OUTPUT_DIR、DEFAULT_MODEL 與速率限制。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 Gemini Image,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
gemini-image-mcp
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).
Install
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:
Features
generate_image — AI-powered
- Text-to-image — describe what you want, get an image
- Image editing — provide reference images and an editing instruction
- Video-to-image — the model watches a video and synthesizes a new image from what it understood: YouTube thumbnails, posters from footage, summary infographics, style-transferred stills. See Advanced Features
- Thinking depth control —
thinkingLevel: "HIGH"for renders that depend on reasoning (infographics, diagrams, dense typography); cheapMINIMALdefault otherwise - Transparent assets in one call —
removeBackgroundreturns 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 cost - Multi-turn edits — pass a
sessionIdto refine an image across calls, with prior turns kept as context - Multi-image input — reference images for editing and character/style consistency (per-model limits; the API enforces)
- Cost reporting — every response includes token counts, estimated USD cost, and session totals
- Rate limiting — configurable per-hour caps on requests and cost to prevent runaway agents
- Auto model discovery — detects available image models from your API key at startup
- Seed — reproducible generation with integer seeds
- Search grounding — ground renders in live Google Search results;
"web+image"also pulls image-search results for mood boards and trend references, with sources returned for attribution. See Advanced Features
process_image — Local (free, no API calls)
- Crop — pixel-exact, aspect ratio (center), or focal point (attention/entropy)
- Resize — to width, height, or both (maintains aspect ratio)
- Background removal — threshold-based (white backgrounds) or chroma key (green screen, any solid colour)
- Chroma key pipeline — HSV keying with smoothstep feather, spill suppression, and edge anti-aliasing
- Trim — auto-remove whitespace borders
- Format conversion — PNG, JPEG, WebP with quality control
Both tools
- Output organization — meaningful filenames with auto-versioning, subfolders
- Generation manifest —
generations.jsonllogs every generation with prompt, params, cost - Full aspect ratio support — 1:1, 16:9, 9:16, 3:2, 2:3, 4:3, 3:4, 21:9
- Resolution control — 1K, 2K, 4K
Setup
1. Get a Gemini API Key
Go 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.
2. Set the API Key
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:
3. Connect to Your MCP Client
Pick the method that matches how you use MCP:
Claude Code (one-liner)
Claude Code will pick up GEMINI_API_KEY from your environment automatically.
Claude Code (manual .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.
Claude Desktop
Edit claude_desktop_config.json:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
Restart Claude Desktop after saving.
Other MCP Clients
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.
Security Notes
- Never commit your API key to version control. The
${GEMINI_API_KEY}syntax in config files references your environment — the key itself stays in your shell profile. - If your
.mcp.jsonis in a project repo, add it to.gitignoreor use the global config at~/.claude/.mcp.jsoninstead. - For extra security, you can use a wrapper script that reads the key from your OS keychain (macOS Keychain, Windows Credential Manager) and launches the server with it injected.
Configuration
All optional. The only required setup is GEMINI_API_KEY (covered above).
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.
Config File
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.
Tool: generate_image
Parameters
Example Response
Usage Examples
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.
Tool: process_image
Local image processing via sharp. Free, fast, no API calls.
Parameters
Crop Options
Background Removal Options
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.
Common Pipelines
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:
Advanced Features
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.
Video-to-image (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:
- YouTube thumbnails — "watch my video and make a click-worthy thumbnail" (the headline use case: no scrubbing for a non-blurry frame)
- Posters and cover art — gameplay footage → key art, a gig recording → gig poster, a product demo → a clean product shot
- Summary infographics — "diagram the key steps from this tutorial video"
- Style-transferred stills — a pencil-sketch of a dance video, a comic panel from home footage
- Supported on the gemini-3.1-flash family (
gemini-3.1-flash-image,gemini-3.1-flash-lite-image); other models reject it. - Accepts local files (
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). - Not combinable with
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). - Upload + server-side processing happen before the generation call and are bounded by a 120s-per-video processing cap, not by
REQUEST_TIMEOUT_MS(which only bounds the generation call itself). - You must have the necessary rights to any video you upload.
- Scope note: this is video input. Video generation is a different model family (Google's Veo, accessed via its own API) and is out of this server's scope.
Thinking depth (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.
Image-search grounding (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).
Models
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.
Development
License
MIT
來源:README.md,提交 866189f
工具
0版本歷史
2- v0.6.2最新Sep 16, 2026
- v0.5.0Sep 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分