Back to MCP directory
publicPublicdnsLocal runtime

nano-banana-pro-mcp

一个基于Google Gemini图像生成模型的MCP服务器,允许AI代理通过文本提示生成、编辑和描述图像,支持多种模型和配置选项。

article

README

🚀 nano-banana-pro-mcp

nano-banana-pro-mcp 是一个 MCP 服务器,它能让像 Claude 这样的 AI 智能体借助 Google 的 Gemini 图像生成模型(包括 Nano Banana Pro - gemini-3-pro-image-preview)来生成图像。

注意:我觉得 Google Antigravity 能用 nanobanana 生成图像很酷,所以借鉴了这个想法。

🚀 快速开始

你可以参考下面的示例,使用本项目让 Claude 生成旅行页面的英雄图像。

💻 使用示例

基础用法

以下是 Claude Code 使用 MCP 为旅行着陆页生成英雄图像的示例:

Claude Code 使用 nano-banana-pro MCP

生成的精美结果如下:

生成的带有圣托里尼岛图像的旅行页面

📦 安装指南

Claude Code CLI

claude mcp add nano-banana-pro --env GEMINI_API_KEY=your_api_key_here -- npx @rafarafarafa/nano-banana-pro-mcp

请将 your_api_key_here 替换为你实际的 Gemini API 密钥。

Claude Desktop

将以下内容添加到你的 Claude Desktop 配置文件中:

  • macOS~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows%APPDATA%\Claude\claude_desktop_config.json
{
  "mcpServers": {
    "nano-banana-pro": {
      "command": "npx",
      "args": ["@rafarafarafa/nano-banana-pro-mcp"],
      "env": {
        "GEMINI_API_KEY": "your_api_key_here"
      }
    }
  }
}

Codex CLI

在你的项目目录中创建或编辑 .mcp.json 文件(若要进行全局配置,可编辑 ~/.mcp.json):

{
  "mcpServers": {
    "nano-banana-pro": {
      "command": "npx",
      "args": ["@rafarafarafa/nano-banana-pro-mcp"],
      "env": {
        "GEMINI_API_KEY": "your_api_key_here"
      }
    }
  }
}

Gemini CLI

创建或编辑 ~/.gemini/settings.json 文件:

{
  "mcpServers": {
    "nano-banana-pro": {
      "command": "npx",
      "args": ["@rafarafarafa/nano-banana-pro-mcp"],
      "env": {
        "GEMINI_API_KEY": "your_api_key_here"
      }
    }
  }
}

获取 API 密钥

你可以从 Google AI Studio 获取免费的 Gemini API 密钥。

📚 详细文档

可用工具

generate_image

根据文本提示生成图像。你还可以选择提供参考图像来引导风格或内容。

参数: | 属性 | 详情 | |------|------| | prompt(必需) | 要生成图像的描述 | | model(可选) | 要使用的 Gemini 模型(默认:gemini-3-pro-image-preview),可选值包括:
- gemini-3-pro-image-preview - Nano Banana Pro(最高质量)
- gemini-2.5-flash-preview-05-20 - Nano Banana(快速)
- gemini-2.0-flash-exp - 广泛可用的备用选项 | | aspectRatio(可选) | "1:1" | "3:4" | "4:3" | "9:16" | "16:9" | | imageSize(可选) | "1K" | "2K" | "4K"(仅适用于特定图像模型) | | images(可选) | 用于引导生成的参考图像数组,每个图像格式为 { data: "base64...", mimeType: "image/png" } | | outputPath(可选) | 保存生成图像的文件路径(例如,/path/to/image.png) |

示例提示

Generate an image of a sunset over mountains

Generate a logo in the style of this reference image [with image attached]

Generate a hero image and save it to ./assets/hero.png

edit_image

根据指令编辑一个或多个图像。

参数: | 属性 | 详情 | |------|------| | prompt(必需) | 编辑图像的指令 | | images(必需) | 要编辑的图像数组,每个图像格式为 { data: "base64...", mimeType: "image/png" } | | model(可选) | 要使用的 Gemini 模型(默认:gemini-3-pro-image-preview) | | outputPath(可选) | 保存编辑后图像的文件路径(例如,/path/to/image.png) |

示例提示

Add sunglasses to this photo

Remove the background from this image

Combine these two images into one scene

describe_image

分析并描述一个或多个图像,仅返回文本(不生成图像)。

参数: | 属性 | 详情 | |------|------| | images(必需) | 要分析的图像数组,每个图像格式为 { data: "base64...", mimeType: "image/png" } | | prompt(可选) | 自定义分析提示(默认:常规描述) | | model(可选) | 要使用的 Gemini 模型(默认:gemini-3-pro-image-preview) |

示例提示

[default] Describe this image in detail

What objects are in this image?

How many people are in this photo?

What's the dominant color in this image?

🔧 技术细节

开发设置

npm install
npm run build

测试

npm test              # 运行单元测试
npm run test:watch    # 以监听模式运行测试
npm run typecheck     # 进行类型检查但不输出文件

手动测试

# 生成一张真实图像并保存为 test-output.png
GEMINI_API_KEY=your_key npm run test:manual "a cute cat wearing sunglasses"

使用 MCP Inspector 进行测试

npx @modelcontextprotocol/inspector node dist/index.js

然后在检查器的环境中设置 GEMINI_API_KEY,并调用 generate_image 工具。

📄 许可证

本项目采用 MIT 许可证。

help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client