Nanobanana Mcp Server

io.github.zhongweili由 GitHub 账号 zhongweili 发布v1.0.0更新于 Oct 24, 2026

An MCP server that provides image generation and editing capabilities

已验证STDIO仅桌面媒体与设计AI 与机器学习

概览

AI 生成的概览

本地 MCP 服务器,让助手用 Google Gemini 图像模型生成和编辑图片,并保存到本地磁盘。

可以做什么
  • 根据文字提示生成图片,可自动或指定模型、分辨率、宽高比与联网依据
  • 编辑已有图片,并支持以多张输入图片作为条件
  • 通过 Gemini Files API 上传和管理文件
  • 以 MCP 资源浏览提示词模板和文件元数据
  • 将结果保存到指定文件路径、目录或默认输出文件夹
适用场景
适合在会话中让助手直接产出或修改图片,例如营销素材、产品图、社交媒体尺寸和草稿,无需离开聊天客户端。
运行要求
以 Python 包在本地运行(uvx 或 pip)。需要 GEMINI_API_KEY 中的 Google Gemini API 密钥,或使用 Vertex AI 应用默认凭据并设置 NANOBANANA_AUTH_METHOD、GCP_PROJECT_ID 和 GCP_REGION。可选 IMAGE_OUTPUT_DIR 指定默认保存目录;需要访问 Google API 的网络连接。
安装前请注意
GEMINI_API_KEY 是可计费的凭据,以明文环境变量传入;生成图片可能产生费用。服务器会向磁盘写入图片文件,output_path 可指向进程有写权限的任意位置。提示词和上传文件会发送到 Google Gemini 服务,GEMINI_BASE_URL 可将流量改道到自定义端点。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Nanobanana Mcp Server,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

Nano Banana MCP Server 🍌

A production-ready Model Context Protocol (MCP) server that provides AI-powered image generation capabilities through Google's Gemini models with intelligent model selection.

⭐ NEW: Nano Banana 2 — Gemini 3.1 Flash Image! 🍌🚀

Nano Banana 2 (gemini-3.1-flash-image-preview) is now the default model — delivering Pro-level quality at Flash speed:

  • 🍌 Flash Speed + 4K Quality: Up to 3840px at Gemini 2.5 Flash latency
  • 🌐 Google Search Grounding: Real-world knowledge for factually accurate images
  • 🎯 Subject Consistency: Up to 5 characters and 14 objects per scene
  • ✍️ Precision Text Rendering: Crystal-clear text placement in images
  • 🏆 Gemini 3 Pro Image still available for maximum reasoning depth
[nanobanana-mcp-server MCP server]

✨ Features

  • 🎨 Multi-Model AI Image Generation: Three Gemini models with intelligent automatic selection
  • 🍌 Gemini 3.1 Flash Image (NB2): Default model — 4K resolution at Flash speed with grounding
  • 🏆 Gemini 3 Pro Image: Maximum reasoning depth for the most complex compositions
  • ⚡ Gemini 2.5 Flash Image: Legacy Flash model for high-volume rapid prototyping
  • 🤖 Smart Model Selection: Automatically routes to NB2 or Pro based on your prompt
  • 📐 Aspect Ratio Control ⭐ NEW: Specify output dimensions (1:1, 16:9, 9:16, 21:9, and more)
  • 📋 Smart Templates: Pre-built prompt templates for photography, design, and editing
  • 📁 File Management: Upload and manage files via Gemini Files API
  • 🔍 Resource Discovery: Browse templates and file metadata through MCP resources
  • 🛡️ Production Ready: Comprehensive error handling, logging, and validation
  • ⚡ High Performance: Optimized architecture with intelligent caching

🚀 Quick Start

Prerequisites

  1. Google Gemini API Key - Get one free here
  2. Python 3.11+ (for development only)

Installation

Option 1: From MCP Registry (Recommended) This server is available in the Model Context Protocol Registry. Search for "nanobanana" or use the MCP name below with your MCP client.

mcp-name: io.github.zhongweili/nanobanana-mcp-server

Option 2: Using uvx

bash
uvx nanobanana-mcp-server@latest

Option 3: Using pip

bash
pip install nanobanana-mcp-server

🔧 Configuration

Authentication Methods

Nano Banana supports two authentication methods via NANOBANANA_AUTH_METHOD:

  1. API Key (api_key): Uses GEMINI_API_KEY. Best for local development and simple deployments.
  2. Vertex AI ADC (vertex_ai): Uses Google Cloud Application Default Credentials. Best for production on Google Cloud (Cloud Run, GKE, GCE).
  3. Automatic (auto): Defaults to API Key if present, otherwise tries Vertex AI.
1. API Key Authentication (Default)

Set GEMINI_API_KEY environment variable.

2. Vertex AI Authentication (Google Cloud)

Required environment variables:

  • NANOBANANA_AUTH_METHOD=vertex_ai (or auto)
  • GCP_PROJECT_ID=your-project-id
  • GCP_REGION=global (default; required for Gemini 3 Pro Image and NB2. Use us-central1 only for the legacy 2.5 Flash Image model.)

Prerequisites:

  • Enable Vertex AI API: gcloud services enable aiplatform.googleapis.com
  • Grant IAM Role: roles/aiplatform.user to the service account.

Claude Desktop

Option 1: Using Published Server (Recommended)

Add to your claude_desktop_config.json:

json
{  "mcpServers": {    "nanobanana": {      "command": "uvx",      "args": ["nanobanana-mcp-server@latest"],      "env": {        "GEMINI_API_KEY": "your-gemini-api-key-here"      }    }  }}
Option 2: Using Local Source (Development)

If you are running from source code, point to your local installation:

json
{  "mcpServers": {    "nanobanana-local": {      "command": "uv",      "args": ["run", "python", "-m", "nanobanana_mcp_server.server"],      "cwd": "/absolute/path/to/nanobanana-mcp-server",      "env": {        "GEMINI_API_KEY": "your-gemini-api-key-here"      }    }  }}
Option 3: Using Vertex AI (ADC)

To authenticate with Google Cloud Application Default Credentials (instead of an API Key):

json
{  "mcpServers": {    "nanobanana-adc": {      "command": "uvx",      "args": ["nanobanana-mcp-server@latest"],      "env": {        "NANOBANANA_AUTH_METHOD": "vertex_ai",        "GCP_PROJECT_ID": "your-project-id",        "GCP_REGION": "global"      }    }  }}

Configuration file locations:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json

Claude Code (VS Code Extension)

Install and configure in VS Code:

  1. Install the Claude Code extension
  2. Open Command Palette (Cmd/Ctrl + Shift + P)
  3. Run "Claude Code: Add MCP Server"
  4. Configure:
    json
    {  "name": "nanobanana",  "command": "uvx",  "args": ["nanobanana-mcp-server@latest"],  "env": {    "GEMINI_API_KEY": "your-gemini-api-key-here"  }}

Cursor

Add to Cursor's MCP configuration:

json
{  "mcpServers": {    "nanobanana": {      "command": "uvx",      "args": ["nanobanana-mcp-server@latest"],      "env": {        "GEMINI_API_KEY": "your-gemini-api-key-here"      }    }  }}

OpenAI Codex

Add to ~/.codex/config.toml (global) or .codex/config.toml (project-scoped):

toml
[mcp_servers.nanobanana]command = "uvx"args = ["nanobanana-mcp-server@latest"]
[mcp_servers.nanobanana.env]GEMINI_API_KEY = "your-gemini-api-key-here"

Or add via the CLI:

bash
codex mcp add

Codex supports both the CLI and VSCode extension using the same config.toml. Once added, Codex can call generate_image, edit_image, and upload_file tools directly in your coding sessions.

Note: The Codex config file is shared by the CLI and the IDE extension. A TOML syntax error will break both simultaneously, so validate your edits carefully.

Continue.dev (VS Code/JetBrains)

Add to your config.json:

json
{  "mcpServers": [    {      "name": "nanobanana",      "command": "uvx",      "args": ["nanobanana-mcp-server@latest"],      "env": {        "GEMINI_API_KEY": "your-gemini-api-key-here"      }    }  ]}

Open WebUI

Configure in Open WebUI settings:

json
{  "mcp_servers": {    "nanobanana": {      "command": ["uvx", "nanobanana-mcp-server@latest"],      "env": {        "GEMINI_API_KEY": "your-gemini-api-key-here"      }    }  }}

Gemini CLI / Generic MCP Client

bash
# Set environment variableexport GEMINI_API_KEY="your-gemini-api-key-here"
# Run server in stdio modeuvx nanobanana-mcp-server@latest
# Or with pip installationpython -m nanobanana_mcp_server.server

🤖 Model Selection

Nano Banana supports three Gemini models with intelligent automatic selection:

🍌 NB2 — Nano Banana 2 (Gemini 3.1 Flash Image) ⭐ DEFAULT

Flash speed with Pro-level quality — the best of both worlds

  • Quality: Production-ready 4K output
  • Resolution: Up to 4K (3840px)
  • Speed: ~2-4 seconds per image (Flash-class latency)
  • Special Features:
    • 🌐 Google Search Grounding: Real-world knowledge for factually accurate images
    • 🎯 Subject Consistency: Up to 5 characters and 14 objects per scene
    • ✍️ Precision Text Rendering: Clear, well-placed text in images
  • Best for: Almost everything — production assets, marketing, photography, text overlays
  • model_tier: "nb2" (or "auto" — NB2 is the auto default)

🏆 Pro Model — Nano Banana Pro (Gemini 3 Pro Image)

Maximum reasoning depth for the most demanding compositions

  • Quality: Highest available
  • Resolution: Up to 4K (3840px)
  • Speed: ~5-8 seconds per image
  • Special Features:
    • 🧠 Advanced Reasoning: Configurable thinking levels (LOW/HIGH)
    • 🌐 Google Search Grounding: Real-world knowledge integration
    • 📐 Media Resolution Control: Fine-tune vision processing detail
  • Best for: Complex narrative scenes, intricate compositions, maximum reasoning required
  • model_tier: "pro"

⚡ Flash Model (Gemini 2.5 Flash Image)

Legacy model for high-volume rapid iteration

  • Speed: Very fast (2-3 seconds)
  • Resolution: Up to 1024px
  • Best for: High-volume generation, quick drafts where 4K is not needed
  • model_tier: "flash"

🤖 Automatic Selection (Recommended)

By default, the server uses AUTO mode which routes to NB2 unless Pro's deeper reasoning is clearly needed:

Pro Model Selected When:

  • Strong quality keywords: "4K", "professional", "production", "high-res", "HD"
  • High thinking level requested: thinking_level="HIGH"
  • Multi-image conditioning with multiple input images

NB2 Model Selected When (default):

  • Standard requests, everyday image generation
  • Speed keywords: "quick", "draft", "sketch", "rapid"
  • High-volume batch generation (n > 2)

Usage Examples

python
# Automatic selection (recommended) — routes to NB2 by default"A cat sitting on a windowsill"             # → NB2 (default)"Quick sketch of a cat"                     # → NB2 (speed keyword, NB2 is fast enough)"Professional 4K product photo"             # → Pro (strong quality keywords)
# Explicit NB2 selectiongenerate_image(    prompt="Product photo on white background",    model_tier="nb2",              # Nano Banana 2 (Flash speed + 4K)    resolution="4k",    enable_grounding=True)
# Leverage Nano Banana Pro for complex reasoninggenerate_image(    prompt="Cinematic scene: three characters in a tense standoff at dusk",    model_tier="pro",              # Pro for deep reasoning    resolution="4k",    thinking_level="HIGH",         # Enhanced reasoning    enable_grounding=True)
# Legacy Flash for high-volume draftsgenerate_image(    prompt="Simple icon",    model_tier="flash"             # Fast 1024px generation)
# Control aspect ratio for different formats ⭐ NEW!generate_image(    prompt="Cinematic landscape at sunset",    aspect_ratio="21:9"            # Ultra-wide cinematic format)
generate_image(    prompt="Instagram post about coffee",    aspect_ratio="1:1"             # Square format for social media)
generate_image(    prompt="YouTube thumbnail design",    aspect_ratio="16:9"            # Standard video format)
generate_image(    prompt="Mobile wallpaper of mountain vista",    aspect_ratio="9:16"            # Portrait format for phones)

📐 Aspect Ratio Control

Control the output image dimensions with the aspect_ratio parameter:

Supported Aspect Ratios:

  • 1:1 - Square (Instagram, profile pictures)
  • 4:3 - Classic photo format
  • 3:4 - Portrait orientation
  • 16:9 - Widescreen (YouTube thumbnails, presentations)
  • 9:16 - Mobile portrait (phone wallpapers, stories)
  • 21:9 - Ultra-wide cinematic
  • 2:3, 3:2, 4:5, 5:4 - Various photo formats
python
# Examples for different use casesgenerate_image(    prompt="Product showcase for e-commerce",    aspect_ratio="3:4",    # Portrait format, good for product pages    model_tier="pro")
generate_image(    prompt="Social media banner for Facebook",    aspect_ratio="16:9"    # Landscape banner format)

Note: Aspect ratio works with both Flash and Pro models. For best results with specific aspect ratios at high resolution, use the Pro model with resolution="4k".

📁 Output Path Control ⭐ NEW!

Control where generated images are saved with the output_path parameter:

Three modes of operation:

  1. Specific file path - Save to an exact file location:
python
generate_image(    prompt="A beautiful sunset",    output_path="/path/to/sunset.png"  # Exact file location)
  1. Directory path - Use auto-generated filename in a specific directory:
python
generate_image(    prompt="Product photo",    output_path="/path/to/products/"  # Trailing slash indicates directory)
  1. Default location - Uses IMAGE_OUTPUT_DIR or ~/nanobanana-images:
python
generate_image(    prompt="Random image"    # output_path defaults to None)

Multiple images (n > 1): When generating multiple images with a file path, images are automatically numbered:

  • First image: /path/to/image.png
  • Second image: /path/to/image_2.png
  • Third image: /path/to/image_3.png

Precedence Rules:

  1. output_path parameter (if provided) - highest priority
  2. IMAGE_OUTPUT_DIR environment variable
  3. ~/nanobanana-images (default fallback)

IMAGE_OUTPUT_DIR is used only when output_path is omitted. A relative output_path such as images/sunset.png is resolved from the server process working directory, not from IMAGE_OUTPUT_DIR. ~/... expands to the home directory. A trailing slash selects directory mode even when that directory does not exist yet (outputs/), and the server creates it and generates the filename.

python
# Save to specific location with Pro modelgenerate_image(    prompt="Professional headshot",    model_tier="pro",    output_path="/Users/me/photos/headshot.png")
# Save multiple images to a directorygenerate_image(    prompt="Product variations",    n=4,    output_path="/path/to/products/"  # Each gets unique filename)

⚙️ Environment Variables

Configuration options:

bash
# Authentication (Required)# Method 1: API KeyGEMINI_API_KEY=your-gemini-api-key-here
# Method 2: Vertex AI (Google Cloud)NANOBANANA_AUTH_METHOD=vertex_aiGCP_PROJECT_ID=your-project-idGCP_REGION=global  # Required for gemini-3-pro-image-preview and NB2; use "us-central1" only for legacy 2.5 Flash Image
# Model Selection (optional)NANOBANANA_MODEL=auto  # Options: flash, nb2, pro, auto (default: auto → nb2)
# OptionalIMAGE_OUTPUT_DIR=/path/to/image/directory  # Default: ~/nanobanana-imagesGEMINI_BASE_URL=https://custom-api.example.com  # Custom API endpoint (for proxies/gateways)LOG_LEVEL=INFO                             # DEBUG, INFO, WARNING, ERRORLOG_FORMAT=standard                        # standard, json, detailed

🐛 Troubleshooting

Common Issues

"GEMINI_API_KEY not set"

  • Add your API key to the MCP server configuration in your client
  • Get a free API key at Google AI Studio

"Server failed to start"

  • Ensure you're using the latest version: uvx nanobanana-mcp-server@latest
  • Check that your client supports MCP (Claude Desktop 0.10.0+)

"Permission denied" errors

  • The server creates images in ~/nanobanana-images by default
  • Ensure write permissions to your home directory

Development Setup

For local development:

bash
# Clone repositorygit clone https://github.com/zhongweili/nanobanana-mcp-server.gitcd nanobanana-mcp-server
# Install with uvuv sync
# Set environmentexport GEMINI_API_KEY=your-api-key-here
# Run locallyuv run python -m nanobanana_mcp_server.server

📄 License

MIT License - see LICENSE for details.

🆘 Support

来源:README.md,提交 369a30f

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

1
  1. v1.0.0最新Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分