Gemini Flash Image MCP Server

Gemini Flash Image MCP Server

Enables text-to-image generation, image editing, and multi-image composition using Google's Gemini 2.5 Flash Image API. Supports flexible aspect ratios and character consistency across generations.

Category
访问服务器

README

Gemini Flash Image 2.5 Tool (Nano Banana)

A tool for generating and editing images using Google's Gemini 2.5 Flash Image API (affectionately known as "Nano Banana").

Includes both a Python CLI tool and a Model Context Protocol (MCP) server for integration with AI assistants like Claude Code.

Features

  • Text-to-Image Generation: Create images from text prompts
  • Image Editing: Modify existing images with natural language instructions
  • Multi-Image Composition: Combine multiple images into one
  • Flexible Aspect Ratios: Support for 10 different aspect ratios
  • Character Consistency: Maintain character appearance across multiple generations
  • MCP Server: Integrate with Claude Code and other MCP clients
  • Command-Line Interface: Easy-to-use CLI for quick operations
  • Python API: Use as a library in your own projects

Installation

Option 1: MCP Server (Recommended for AI Assistants)

Simplest Install (using npx)

For Claude Code MCP configuration, you can reference the package directly via GitHub:

Add to your MCP settings (~/.config/claude/claude_desktop_config.json):

{
  "mcpServers": {
    "gemini-image": {
      "command": "npx",
      "args": ["-y", "github:brunoqgalvao/gemini-image-mcp-server"],
      "env": {
        "GEMINI_API_KEY": "your_api_key_here"
      }
    }
  }
}

Then restart Claude Code! The generate_image tool will be available instantly.

Local Install

# Clone the repository
git clone https://github.com/brunoqgalvao/gemini-image-mcp-server.git
cd gemini-image-mcp-server

# Run the installer
./install.sh

The installer will:

  • Install Node.js dependencies
  • Create a .env file from template
  • Run validation tests
  • Show you the MCP configuration to add to Claude Code

Manual Install

  1. Clone or download this repository

  2. Install Node.js dependencies:

npm install
  1. Get your API key from Google AI Studio

  2. Create a .env file in the project directory:

GEMINI_API_KEY=your_api_key_here
  1. Configure your MCP client (e.g., Claude Code):

For macOS/Linux - Add to ~/.config/claude/claude_desktop_config.json:

{
  "mcpServers": {
    "gemini-image": {
      "command": "node",
      "args": ["/absolute/path/to/agent-dispatcher/index.js"],
      "env": {
        "GEMINI_API_KEY": "your_api_key_here"
      }
    }
  }
}

For Windows - Add to %APPDATA%\Claude\claude_desktop_config.json:

{
  "mcpServers": {
    "gemini-image": {
      "command": "node",
      "args": ["C:\\absolute\\path\\to\\agent-dispatcher\\index.js"],
      "env": {
        "GEMINI_API_KEY": "your_api_key_here"
      }
    }
  }
}
  1. Restart Claude Code or your MCP client

Installing on Another Computer

Easiest way - Just use npx! On any computer with Node.js:

Add to Claude Code MCP settings:

{
  "mcpServers": {
    "gemini-image": {
      "command": "npx",
      "args": ["-y", "github:brunoqgalvao/gemini-image-mcp-server"],
      "env": {
        "GEMINI_API_KEY": "your_api_key_here"
      }
    }
  }
}

No cloning needed! npx will fetch and run it automatically.

Alternative: Local installation

# Clone and install
git clone https://github.com/brunoqgalvao/gemini-image-mcp-server.git
cd gemini-image-mcp-server
./install.sh

Option 2: Python CLI Tool

  1. Clone or download this repository

  2. Install Python dependencies:

pip install -r requirements.txt
  1. Get your API key from Google AI Studio

  2. Create a .env file in the project directory:

GEMINI_API_KEY=your_api_key_here

Usage

MCP Server

Once configured, the generate_image tool will be available in your MCP client:

Parameters:

  • prompt (required): Text description of the image to generate or edits to make
  • output_path (required): Path where the image will be saved (must end in .png)
  • input_images (optional): Array of paths to input images for editing/composition
  • aspect_ratio (optional): One of: 1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9
  • image_only (optional): Set to true for image-only output without text

Example usage in Claude Code:

"Generate a sunset over mountains and save it to sunset.png"

The MCP server will handle the API call and save the image automatically.

Command Line

Basic text-to-image generation:

python gemini_image_tool.py "A cat eating a banana in space" -o cat_banana.png

Edit an existing image:

python gemini_image_tool.py "Remove the background" -i photo.jpg -o edited.png

Compose multiple images:

python gemini_image_tool.py "Combine these into a collage" -i img1.jpg -i img2.jpg -o collage.png

Specify aspect ratio:

python gemini_image_tool.py "A cinematic landscape" -o wide.png --aspect-ratio 21:9

Image-only output (no text response):

python gemini_image_tool.py "A red apple" -o apple.png --image-only

Save full API response:

python gemini_image_tool.py "A sunset" -o sunset.png --save-json response.json

Python API

from gemini_image_tool import GeminiImageTool

# Initialize the tool
tool = GeminiImageTool(api_key="your_api_key_here")

# Generate an image
result = tool.generate_content(
    prompt="A futuristic city at night",
    aspect_ratio="16:9",
    output_path="city.png"
)

# Edit an image
result = tool.generate_content(
    prompt="Make the sky purple",
    input_images=["city.png"],
    output_path="city_purple.png"
)

# Combine multiple images
result = tool.generate_content(
    prompt="Create a before/after comparison",
    input_images=["before.jpg", "after.jpg"],
    aspect_ratio="2:1",
    output_path="comparison.png"
)

Available Aspect Ratios

  • 1:1 - Square (default)
  • 2:3 - Portrait
  • 3:2 - Landscape
  • 3:4 - Portrait
  • 4:3 - Landscape
  • 4:5 - Portrait
  • 5:4 - Landscape
  • 9:16 - Vertical (social media)
  • 16:9 - Widescreen
  • 21:9 - Cinematic

Supported Image Formats

Input: JPG, JPEG, PNG, WebP, GIF Output: PNG

Pricing

As of 2025, Gemini 2.5 Flash Image is priced at:

  • $30.00 per 1 million output tokens
  • Each image = 1290 output tokens
  • Cost per image: ~$0.039

Use Cases

  • E-commerce: Product photography and variations
  • Content Creation: Social media graphics, blog images
  • Marketing: Ad creatives, promotional materials
  • Storytelling: Consistent character illustrations
  • Photo Editing: Background removal, color correction, object removal
  • Design: Logo variations, mockups, concept art

Command-Line Arguments

positional arguments:
  prompt                Text prompt for image generation/editing

optional arguments:
  -h, --help            Show help message
  -i INPUT, --input INPUT
                        Input image file path (can be specified multiple times)
  -o OUTPUT, --output OUTPUT
                        Output image file path (default: output.png)
  -a ASPECT_RATIO, --aspect-ratio ASPECT_RATIO
                        Output aspect ratio (default: 1:1)
  --image-only          Request image-only output (no text response)
  --api-key API_KEY     Google AI API key (or set GEMINI_API_KEY env variable)
  --save-json SAVE_JSON
                        Save full API response to JSON file

Error Handling

The tool includes comprehensive error handling for:

  • Missing API keys
  • Invalid image paths
  • Unsupported image formats
  • Invalid aspect ratios
  • API request failures
  • Network errors

Notes

  • All generated images include a SynthID watermark (added by Google)
  • The model benefits from Gemini's world knowledge for enhanced generation
  • Character consistency works best with clear, descriptive prompts
  • For best results, be specific in your prompts

Documentation

For more information about Gemini 2.5 Flash Image:

License

This tool is provided as-is for use with the Gemini API. See Google's terms of service for API usage restrictions.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选