Skip to main content
Glama

Gemini 图像 MCP

Gemini 图像 MCP 横幅

一个 MCP 服务器,用于使用 Google 的 Gemini 图像模型(Nano Banana、Nano Banana 2、Nano Banana Pro)生成和编辑图像。它公开了一个工具 generate_image,像 Claude、Codex 和 Cline 这样的 AI 工具可以使用您自己的 API 密钥调用它。

它能做什么

  • generate_image 处理文本到图像,以及当您传递参考图像(本地文件路径或 base64)时的编辑和合成。

  • 每次调用都会公开每个生成参数:temperature (1)、topP (0.95)、topKmaxOutputTokens(flash/lite 为 65536,pro 为 32768)、seedstopSequencespresencePenaltyfrequencyPenaltysystemInstructionthinkingLevel (minimal/high)、thinkingBudgetenableGoogleSearch(默认为 true)、imageSize (512/1K/2K/4K)、aspectRatio(默认 "auto" + 标准比例)、personGeneration

  • 附带一个 instructions 块和每个参数的描述,因此 MCP 客户端无需额外提示即可知道如何使用该工具。

  • 将图像保存到磁盘并返回文件路径。响应中没有 base64,因此 4K 图像不会占用客户端的上下文窗口。

  • 错误会附带提示信息(错误的密钥、速率限制、安全阻止、未知模型)返回,而不是原始的 API 转储。

  • 使用 stdio 传输,这是本地 MCP 服务器的常规设置。

要求

安装

bun install

配置

三个环境变量,通常在 MCP 客户端的配置中设置:

变量

必需

默认值

作用

GEMINI_API_KEY

是(或 GOOGLE_API_KEY

您的 Gemini API 密钥。如果两者都设置了,GEMINI_API_KEY 优先。

GEMINI_IMAGE_MODEL

gemini-3.1-flash-image

当调用未指定模型时使用的模型。

GEMINI_IMAGE_OUTPUT_DIR

<cwd>/generated-images

图像保存的位置。如果目录不存在则会创建。

您可以选择的模型:

模型

最大输出令牌

思维级别

Google 搜索

最大尺寸

说明

gemini-3.1-flash-image

65536

minimal / high

支持

2K

Nano Banana 2。快速、便宜、通用。默认选项。

gemini-3.1-flash-lite-image

65536

minimal / high

支持

2K

轻量级、高吞吐量模型。

gemini-3-pro-image

32768

(无)

支持

4K

Nano Banana Pro。最佳质量和图像内文本,也是唯一支持 4K 的模型。

模型也可以使用 models/ 前缀指定(例如 models/gemini-3.1-flash-image)。

客户端设置

Claude Desktop

将其添加到 ~/Library/Application Support/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "gemini-image": {
      "command": "bun",
      "args": ["run", "/absolute/path/to/gemini-image-mcp/index.ts"],
      "env": {
        "GEMINI_API_KEY": "YOUR_KEY_HERE"
      }
    }
  }
}

Cline (VS Code)

cline_mcp_settings.json

{
  "mcpServers": {
    "gemini-image": {
      "command": "bun",
      "args": ["run", "/absolute/path/to/gemini-image-mcp/index.ts"],
      "env": {
        "GEMINI_API_KEY": "YOUR_KEY_HERE"
      }
    }
  }
}

Codex

~/.codex/config.toml

[mcp_servers.gemini-image]
command = "bun"
args = ["run", "/absolute/path/to/gemini-image-mcp/index.ts"]
env = { GEMINI_API_KEY = "YOUR_KEY_HERE" }

从 npm (bunx/npx)

一旦包发布,将您的客户端指向 bunx 而不是:

{
  "mcpServers": {
    "gemini-image": {
      "command": "bunx",
      "args": ["gemini-image-mcp"],
      "env": { "GEMINI_API_KEY": "YOUR_KEY_HERE" }
    }
  }
}

generate_image 参数

只有 prompt 是必需的。其他所有参数都有适用于图像生成的合理默认值。

参数

类型

默认值

描述

prompt

string

(必需)

图像的叙述性描述,或者当提供 referenceImages 时的编辑描述。

model

string

环境变量 / gemini-3.1-flash-image

Gemini 图像模型(见上表)。接受 models/ 前缀。

referenceImages

array (≤14)

用于编辑/合成的源图像:{ path }{ base64, mimeType }

imageSize

"512" | "1K" | "2K" | "4K"

"1K"

输出分辨率:512(最快,轻量级)、1K(默认)、2K、4K(需要 gemini-3-pro-image)。

aspectRatio

enum

"auto"

"auto"(默认,从提示中推断或匹配参考图像)或显式:1:12:33:23:44:34:55:49:1616:921:91:44:11:88:1

personGeneration

enum

allow_all

allow_all / allow_adult / allow_none

thinkingLevel

enum

"minimal"(在 flash 模型上)

"minimal" / "high"。在 gemini-3.1-flash-imagegemini-3.1-flash-lite-image 上支持。Pro 不支持。

enableGoogleSearch

boolean

true

启用 Google 搜索基础工具,用于在所有模型上获取实时网络知识和准确性。

thinkingBudget

int

显式思考预算(0 = 关闭,-1 = 自动)。

temperature

number 0–2

1

采样随机性。

topP

number 0–1

0.95

核采样。

topK

int

Top-k 采样。

maxOutputTokens

int 1–65536

65536 (flash) / 32768 (pro)

输出令牌上限。

seed

int

尽力而为的可复现性。

stopSequences

string[] (≤5)

文本部分的停止序列。

presencePenalty / frequencyPenalty

number -2..2

令牌惩罚。

systemInstruction

string

风格/行为引导,例如 "flat vector style"。

outputDir

string

环境变量 / <cwd>/generated-images

保存位置。

fileName

string

gemini-image-<timestamp>

基础文件名(扩展名根据 MIME 类型自动添加)。

该工具返回一个文本摘要,其中包含保存的文件路径、模型、有效配置和令牌使用情况。它永远不会内联返回图像数据;打开文件查看结果。

您可以向 AI 询问的事情

  • "生成一张 16:9 的雨夜东京街道英雄图,电影级霓虹灯光。"

  • "编辑 /tmp/product.png:将其放在大理石桌上,带有柔和的晨光"(这使用了 referenceImages)。

  • "使用 gemini-3-pro-image 生成一张带有确切标题 'LAUNCH DAY' 的 4K 海报。"

开发

bun test              # unit tests (config, schema, request/response parsing)
bun run typecheck     # tsc --noEmit
bun run inspector     # interactive MCP inspector (needs GEMINI_API_KEY)
bun run start         # run the server on stdio

故障排除

  • "缺少 Gemini API 密钥":将 GEMINI_API_KEY 放入客户端 MCP 配置的 env 块中。在 shell 中设置它对于 Claude Desktop 等 GUI 应用是不够的,因为它们不读取您的 shell 环境。

  • 安全阻止:重新表述提示。如果涉及人物,请检查 personGeneration

  • 429 / 超出配额:等待并重试,或者坚持使用 gemini-3.1-flash-image,它的配额更高。

  • 日志:服务器仅将日志写入 stderr。stdout 承载 MCP 协议,因此不要在任何地方添加 console.log

作者

Thomi Jasir dev@venobi.com

许可证

MIT

-
license - not tested
-
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/thomijasir/gemini-image-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server