AI图像生成服务

基于Google Gemini模型的AI图像生成服务,支持从文本生成图像或结合多张参考图像进行创作。

  • by gogainda
  • TypeScript
  • 本地部署
  • 2 星标
  • 更新于
在 GitHub 查看 gogainda/mcp-nano-banana

使用说明

mcp纳米香蕉

MCP服务器,用于使用Google Gemini模型生成AI驱动的图像。根据文本提示生成图像或组合多个参考图像。

特性

  • 文本到图像生成
  • 多图像组合(最多14个参考图像)
  • 根据速率限制从Pro自动回退到Flash型号
  • 将输出保存到文件或内联返回
  • 支持多种宽高比和输出格式
  • 生成一个完整的favicon包(PNG大小、favicon.ico、清单、README、可选ZIP)

用例

  • 生成插图 -为博客文章、文档或演示文稿创建图像
  • 编辑现有图像 -添加对象、更改背景或修改照片中的元素
  • 组合多个图像 -合并产品照片、创建合成或混合样式
  • 创建变体 -生成概念或设计的不同版本
  • 原型UI模型 -快速可视化界面创意或应用程序屏幕
  • 生成图标和资源 -为项目创建徽标、按钮或图形元素

安装

npm install -g @igorstechnoclub/mcp-nano-banana

重要提示: 别忘了设置你的 GEMINI_API_KEY 环境变量(请参阅下面的配置)。

配置

环境变量

设置Gemini API密钥:

export GEMINI_API_KEY=your-api-key

在以下位置获取API密钥:https://aistudio.google.com/apikey

Claude代码设置

使用CLI添加MCP服务器:

claude mcp add nano-banana -e GEMINI_API_KEY=your-api-key -- npx -y @igorstechnoclub/mcp-nano-banana@latest

或手动添加到 ~/.claude/claude_desktop_config.json:

{
  "mcpServers": {
    "nano-banana": {
      "command": "npx",
      "args": ["-y", "@igorstechnoclub/mcp-nano-banana@latest"],
      "env": {
        "GEMINI_API_KEY": "your-api-key"
      }
    }
  }
}

用法

工具: generate_image

参数 类型 必填 默认 说明
prompt string 是 - 文本描述或编辑说明
imagePaths string[] 否 - 参考图像路径(最多14个)
model string 否 gemini-3-pro-image-preview 要使用的模型
aspectRatio string 否 1:1 1:1, 16:9, 9:16, 4:3, 3:4
outputFormat string 否 png png, jpeg, webp
outputPath string 否 - 将图像保存到此路径

例子

从文本生成:

prompt: "A sunset over mountains"
outputPath: "/path/to/output.png"

合并图像:

prompt: "Put these glasses on this person's face"
imagePaths: ["/path/to/face.jpg", "/path/to/glasses.jpg"]
outputPath: "/path/to/result.png"

工具: generate_favicons

根据提示或现有图像生成完整的favicon包。

参数 类型 必填 默认 说明
prompt string 否* - 图标描述(如果是必需的 imagePath 未提供)
imagePath string 否* - 现有主图标图像的路径
model string 否 gemini-3-pro-image-preview 从提示生成时使用的模型
outputDir string 否 - 写入单个favicon文件的目录
outputPath string 否 - 将ZIP包保存到此路径
returnZipBase64 boolean 否 false 将ZIP作为base64文本返回
appName string 否 My App 清单 name
shortName string 否 App 清单 short_name
themeColor string 否 #ffffff 清单主题颜色
backgroundColor string 否 #ffffff 清单背景颜色
includeReadme boolean 否 true 包括 README.md 在包装中

从提示生成并写入文件+ZIP:

prompt: "A minimalist banana icon with a soft gradient"
outputDir: "/path/to/favicon"
outputPath: "/path/to/favicon.zip"

使用现有图像并返回base64 ZIP:

imagePath: "/path/to/master-icon.png"
returnZipBase64: true

Codex MCP使用(本地)

构建本地服务器:

npm install
npm run build

在Codex注册:

codex mcp add nano-banana --env GEMINI_API_KEY=your-api-key -- node /path/to/mcp-nano-banana/dist/index.js

请求示例:

Use MCP tool generate_favicons with:
prompt: "A bold, simple icon for VideoFix: a stylized play button combined with a small wrench, flat design, high contrast, centered on a soft off-white background."
appName: "VideoFix"
shortName: "VideoFix"
themeColor: "#1d1b18"
backgroundColor: "#f7f3ef"
outputDir: "/path/to/project/assets/favicon"

模型

  • gemini-3-pro-image-preview -高质量(默认)
  • gemini-2.5-flash-image -快速生成

如果Pro达到速率限制(429/403/402错误),服务器会自动回退到Flash。

发展

# Build
npm run build

# Test
npm test

# Run directly
node dist/index.js

博客文章

了解此项目的发展:https://igorstechnoclub.com/mcp-nano-banana/

作者

访问我的个人网站:https://igorstechnoclub.com

许可证

麻省理工学院