纳米香蕉API MCP
](https://www.npmjs.com/package/nanobanana-api-mcp)  ](https://nodejs.org/) 
MCP(模型上下文协议)服务器,用于使用Google Gemini API生成和编辑图像。
特性
- generate_image:使用Google Gemini AI从文本提示生成图像
- edit_image:根据文本描述编辑现有图像
- 支持参考图像以指导生成/编辑
- 多种型号选项(Pro和Normal)
- 使用TypeScript构建类型安全
- 通过CLI参数或环境变量进行灵活配置
图像生成示例
Generated image: "A serene mountain landscape at sunset with a lake in the foreground"
安装
NPM
npm install -g nanobanana-api-mcp铁匠铺
通过以下方式自动为任何客户端安装Nanobanana MCP服务器 铁匠铺:
npx -y @smithery/cli@latest install nanobanana-api-mcp --client 可用客户端: cursor, claude, vscode, windsurf, cline, zed等等。
光标示例:
npx -y @smithery/cli@latest install nanobanana-api-mcp --client cursor这将在您选择的客户端中自动配置MCP服务器。
先决条件
您需要一个访问Gemini模型的Google API密钥。从获取API密钥 谷歌人工智能工作室.
您可以通过CLI参数提供API密钥:
nanobanana-api-mcp --apiKey "your-api-key-here"或者将其设置为环境变量:
export GOOGLE_API_KEY="your-api-key-here"
nanobanana-api-mcpMCP客户端集成
Nanobanana MCP可以与支持模型上下文协议(MCP)的各种AI编码助手和IDE集成。
需求
- Node.js>=v18.0.0
- 使用Gemini访问的Google API密钥
- MCP兼容客户端(Cursor、Claude Code、VS Code、Windsurf等)
Install in Cursor
首选 Settings -> Cursor Settings -> MCP -> Add new global MCP server
将以下配置添加到您的 ~/.cursor/mcp.json 文件:
{
"mcpServers": {
"nanobanana": {
"command": "npx",
"args": ["-y", "nanobanana-api-mcp", "--apiKey", "your-api-key-here"]
}
}
}您可以选择修复用于所有操作的模型:
{
"mcpServers": {
"nanobanana": {
"command": "npx",
"args": [
"-y",
"nanobanana-api-mcp",
"--apiKey",
"your-api-key-here",
"--model",
"pro"
]
}
}
}Install in Claude Code
使用API密钥运行此命令:
claude mcp add nanobanana -- npx -y nanobanana-api-mcp --apiKey your-api-key-here或者使用固定型号:
claude mcp add nanobanana -- npx -y nanobanana-api-mcp --apiKey your-api-key-here --model proInstall in VS Code
将此添加到您的VS Code MCP配置文件中。看 VS代码MCP文档 了解更多信息。
"mcp": {
"servers": {
"nanobanana": {
"type": "stdio",
"command": "npx",
"args": ["-y", "nanobanana-api-mcp", "--apiKey", "your-api-key-here"]
}
}
}Install in Windsurf
将此添加到您的Windsurf MCP配置文件中:
{
"mcpServers": {
"nanobanana": {
"command": "npx",
"args": ["-y", "nanobanana-api-mcp", "--apiKey", "your-api-key-here"]
}
}
}Install in Cline
- 打开 克莱恩
- 点击汉堡菜单图标(☰)进入 MCP服务器 章节
- 选择 远程服务器 标签
- 点击 编辑配置 按钮
- 添加nanobanana
mcpServers:
{
"mcpServers": {
"nanobanana": {
"command": "npx",
"args": ["-y", "nanobanana-api-mcp", "--apiKey", "your-api-key-here"]
}
}
}Install in Claude Desktop
打开Claude Desktop开发人员设置并编辑您的 claude_desktop_config.json 文件:
{
"mcpServers": {
"nanobanana": {
"command": "npx",
"args": ["-y", "nanobanana-api-mcp", "--apiKey", "your-api-key-here"]
}
}
}Install in Zed
将此添加到您的Zed settings.json:
{
"context_servers": {
"nanobanana": {
"source": "custom",
"command": "npx",
"args": ["-y", "nanobanana-api-mcp", "--apiKey", "your-api-key-here"]
}
}
}Install in Roo Code
将此添加到Roo Code MCP配置文件中:
{
"mcpServers": {
"nanobanana": {
"command": "npx",
"args": ["-y", "nanobanana-api-mcp", "--apiKey", "your-api-key-here"]
}
}
}可用工具
Nanobanana MCP提供以下LLM可以使用的工具:
generate_image
使用Google Gemini API基于文本提示生成图像。
参数:
prompt(string,必填):要生成的图像的文本描述output_path(字符串,可选):保存生成图像的绝对路径。如果未提供,则返回base64编码的图像数据model(枚举,可选):要使用的模型-“pro”(默认)或“normal”(如果通过CLI提供--Model,则不显示)
- pro:gemini-3-图像预评价(更高质量) - normal:gemini-2.5-flash图像(更快)
reference_images_path(string\[\],可选):用于引导生成的绝对参考图像路径数组aspect_ratio(枚举,可选):图像的纵横比-“1:1”、“2:3”、“3:2”、“3:4”、”4:3“、”4:5“、”5:4“、”9:16“、”16:9“(默认)、”21:9“
示例(保存到文件):
{
"prompt": "A serene mountain landscape at sunset with a lake in the foreground",
"output_path": "/absolute/path/to/generated_image.png",
"model": "pro",
"aspect_ratio": "16:9"
}示例(返回base64):
{
"prompt": "A serene mountain landscape at sunset with a lake in the foreground",
"model": "pro",
"aspect_ratio": "16:9"
}参考图像:
{
"prompt": "An office group photo of these people, they are making funny faces",
"output_path": "/absolute/path/to/group_photo.png",
"model": "pro",
"reference_images_path": [
"/absolute/path/to/person1.jpg",
"/absolute/path/to/person2.jpg"
]
}edit_image
使用Google Gemini API基于文本提示编辑现有图像。
参数:
path(字符串,可选):要编辑的图像的绝对路径。要么path或image_base64必须提供image_base64(字符串,可选):要编辑的Base64编码图像数据。要么path或image_base64必须提供mime_type(字符串,可选):base64图像的MIME类型(例如,“image/png”、“image/jpeg”)。使用时需要image_base64prompt(字符串,必填):要进行的编辑的文本描述output_path(字符串,可选):保存编辑图像的绝对路径。如果未提供:
- 使用时 path:默认覆盖输入文件 - 使用时 image_base64:返回base64编码的图像数据
model(枚举,可选):要使用的模型-“pro”(默认)或“normal”(如果通过CLI提供--Model,则不显示)reference_images_path(string\[\],可选):用于指导编辑的绝对附加参考图像路径数组aspect_ratio(枚举,可选):图像的纵横比-“1:1”、“2:3”、“3:2”、“3:4”、”4:3“、”4:5“、”5:4“、”9:16“、”16:9“(默认)、”21:9“
示例(路径输入,保存到文件):
{
"path": "/absolute/path/to/original_image.png",
"prompt": "Add a blue sky with fluffy clouds in the background",
"output_path": "/absolute/path/to/edited_image.png",
"model": "pro"
}示例(路径输入,覆盖原始):
{
"path": "/absolute/path/to/image.png",
"prompt": "Make the colors more vibrant and increase contrast"
}示例(base64输入,返回base64):
{
"image_base64": "iVBORw0KGgoAAAANSUhEUgAA...",
"mime_type": "image/png",
"prompt": "Add a sunset filter to this image"
}示例(base64输入,保存到文件):
{
"image_base64": "iVBORw0KGgoAAAANSUhEUgAA...",
"mime_type": "image/png",
"prompt": "Add a sunset filter to this image",
"output_path": "/absolute/path/to/output.png"
}参考图像:
{
"path": "/absolute/path/to/portrait.jpg",
"prompt": "Apply the style and lighting from these reference images",
"output_path": "/absolute/path/to/styled_portrait.jpg",
"reference_images_path": [
"/absolute/path/to/style_ref1.jpg",
"/absolute/path/to/style_ref2.jpg"
]
}使用示例
示例1:生成一个简单的图像
在光标/克劳德代码中:
Generate an image of a futuristic cityscape with flying cars and save it to ./cityscape.png结果: 上面的命令将生成一个类似于我们演示的图像:
示例2:编辑现有图像
在光标/克劳德代码中:
Edit the image at ./photo.jpg and add a sunset sky background, save it as ./photo_sunset.jpg示例3:使用参考图像生成
在光标/克劳德代码中:
Create an office group photo using the face images at ./face1.jpg, ./face2.jpg, and ./face3.jpg.
Make them look like they're at a fun team meeting. Save to ./team_photo.png命令行用法
直接运行服务器:
# Using CLI argument for API key (recommended)
nanobanana-api-mcp --apiKey "your-api-key-here"
# Using environment variable for API key
export GOOGLE_API_KEY="your-api-key-here"
nanobanana-api-mcp
# Fix model for all operations
nanobanana-api-mcp --apiKey "your-api-key-here" --model pro
# Using HTTP transport
nanobanana-api-mcp --apiKey "your-api-key-here" --transport http --port 5000CLI选项:
--apiKey:用于图像生成的Google API密钥(也可以使用Google_API_key env var)- `--model
`:修复所有操作的模型(可选,对工具隐藏模型参数)
--transport:传输类型(默认值:stdio)--port:HTTP传输端口(默认值:5000)
发展
# Install dependencies
npm install
# Run in development mode
npm run dev
# Run tests
npm test
# Build
npm run build
# Type check
npm run typecheck
# Lint
npm run lint建筑
该项目采用模块化架构:
- 服务/:使用Google Gemini API的图像生成和编辑服务
- 工具/:MCP工具实现(generate_image、edit_image)
- 类型/:TypeScript类型定义
- server.ts:主MCP服务器设置和配置
支持的图像格式
- JPEG(.jpg、.JPEG)
- PNG(.PNG)
- GIF(.GIF)
- WebP(.WebP)
许可证
麻省理工学院
贡献
欢迎投稿!请随时提交拉取请求。
作者
choesumin
致谢
该项目使用 谷歌生成人工智能SDK 用于图像生成和编辑功能。
