nano-banana-mcp

nano-banana-mcp

MCP server that generates images using Gemini 3 Pro Image on Vertex AI, with support for reference images, task management, and GCS integration.

Category
访问服务器

README

nano-banana-mcp

Architecture Diagram

MCP server that generates images with Gemini 3 Pro Image on Vertex AI.

Requirements

  • Node.js 18+
  • Vertex AI API enabled in your GCP project
  • A service account with permission to call Vertex AI

Setup

npm install

Create a .env file or export the variables directly:

export GOOGLE_SERVICE_ACCOUNT_JSON='{"type":"service_account","project_id":"your-project","private_key":"...","client_email":"..."}'
# or point to a JSON file
export GOOGLE_SERVICE_ACCOUNT_JSON=/absolute/path/to/service-account.json

export VERTEX_PROJECT_ID=your-project
export VERTEX_LOCATION=global
export NANO_BANANA_MODEL=gemini-3-pro-image-preview
export NANO_BANANA_GCS_BUCKET=your-reference-bucket
export NANO_BANANA_GCS_PREFIX=nano-banana/refs
export NANO_BANANA_OUTPUT_GCS_BUCKET=your-output-bucket
export NANO_BANANA_OUTPUT_GCS_PREFIX=nano-banana/outputs
export NANO_BANANA_OUTPUT_DIR=~/nano-banana-outputs
export NANO_BANANA_PROGRESS_INTERVAL_MS=20000
export NANO_BANANA_AUTO_TASK_4K=false
export NANO_BANANA_AUTO_TASK_TTL_MS=1200000

Notes:

  • GOOGLE_SERVICE_ACCOUNT_JSON is required (JSON string or file path).
  • VERTEX_PROJECT_ID is optional if the service account JSON includes project_id.
  • The default model is gemini-3-pro-image-preview (Vertex preview). Override with another model ID if needed.
  • NANO_BANANA_GCS_BUCKET is required if you want the server to upload local reference images to GCS.
  • NANO_BANANA_GCS_PREFIX controls the object prefix for uploaded reference images (default: nano-banana/refs).
  • NANO_BANANA_OUTPUT_GCS_BUCKET controls the GCS bucket for generated images (defaults to NANO_BANANA_GCS_BUCKET).
  • NANO_BANANA_OUTPUT_GCS_PREFIX controls the object prefix for generated images (default: nano-banana/outputs).
  • NANO_BANANA_OUTPUT_DIR sets the local save root (defaults to ~/nano-banana-outputs). Relative outputDir values resolve under this path.
  • NANO_BANANA_PROGRESS_INTERVAL_MS controls how often progress notifications are emitted (ms) to keep long MCP calls alive. Set 0 to disable.
  • NANO_BANANA_AUTO_TASK_4K runs 4K generations in task mode automatically to avoid client timeouts (set true to enable).
  • NANO_BANANA_AUTO_TASK_TTL_MS controls how long auto-task results remain available (ms). Set 0 for no expiry.
  • If you use GCS fileUri references, grant Storage Object Viewer to the Vertex AI service agent for the bucket.
  • If you use referenceImagePaths, the MCP service account needs Storage Object Creator (or broader) on the bucket.
  • For generated image uploads, the MCP service account needs Storage Object Creator (or broader) on the output bucket.
  • If you see a 404 error with global, try a supported region like us-central1 or europe-west4.

Run

npm run dev

If you run via dist/ (e.g. npm start or an MCP config that points to dist/index.js), run npm run build after code changes.

Long-running calls

If your MCP client enforces the 60s default timeout, use progress notifications or task mode.

4K generations can be auto-run in task mode to avoid timeouts. Enable with NANO_BANANA_AUTO_TASK_4K=true if your client supports tasks. If your client does not support MCP tasks, auto-tasking returns a polling task ID via the normal tool response; call nano_banana_get_task to check status and retrieve the final result.

Progress (keeps a single request alive by resetting the timeout):

import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
import { CallToolResultSchema } from "@modelcontextprotocol/sdk/types.js";

const client = new Client(
  { name: "example-client", version: "0.1.0" },
  { capabilities: {} }
);

await client.connect(
  new StdioClientTransport({ command: "nano-banana-mcp" })
);

const result = await client.request(
  {
    method: "tools/call",
    params: {
      name: "nano_banana_generate_image",
      arguments: {
        prompt: "A cinematic landscape at golden hour",
        aspectRatio: "16:9",
      },
    },
  },
  CallToolResultSchema,
  {
    onprogress: (progress) => {
      console.log(progress.message ?? progress.progress);
    },
    resetTimeoutOnProgress: true,
  }
);

Tasks (returns immediately, then poll/stream the result):

const stream = client.experimental.tasks.callToolStream(
  {
    name: "nano_banana_generate_image",
    arguments: {
      prompt: "A cinematic landscape at golden hour",
      aspectRatio: "16:9",
    },
  },
  CallToolResultSchema,
  {
    task: {
      ttl: 15 * 60 * 1000,
      pollInterval: 1000,
    },
  }
);

for await (const message of stream) {
  if (message.type === "taskStatus") {
    console.log(message.task.status, message.task.statusMessage ?? "");
  }
  if (message.type === "result") {
    console.log(message.result);
  }
}

Notes:

  • Task state is stored in memory; tasks are lost when the server restarts.
  • Task mode still benefits from progress notifications if the client subscribes.

Polling fallback (for clients without MCP task support):

const start = await client.request(
  {
    method: "tools/call",
    params: {
      name: "nano_banana_generate_image",
      arguments: {
        prompt: "A cinematic landscape at golden hour",
        imageSize: "4K",
        aspectRatio: "16:9",
      },
    },
  },
  CallToolResultSchema
);

// extract taskId from start.structuredContent or the text response
const poll = await client.request(
  {
    method: "tools/call",
    params: {
      name: "nano_banana_get_task",
      arguments: { taskId: "<taskId>" },
    },
  },
  CallToolResultSchema
);

Notes:

  • Polling tasks are stored in memory and are cleared on server restart.
  • Polling tasks expire after NANO_BANANA_AUTO_TASK_TTL_MS (set 0 to disable expiry).
  • Completed polling responses include structuredContent with outputImageUris, outputImageUrls, and savedPaths when available.
  • Wait a few seconds between nano_banana_get_task polls to avoid hammering the server.

MCP tool

Tool name: nano_banana_generate_image Tool name: nano_banana_get_task (polling fallback for auto-task 4K requests)

Example arguments:

{
  "prompt": "A cozy ramen shop on a rainy night, cinematic lighting",
  "aspectRatio": "16:9",
  "includeText": false
}

Responses include GCS URIs (and HTTP URLs) for generated images; image bytes are uploaded to GCS to avoid large MCP payloads. Generated images are also saved locally under NANO_BANANA_OUTPUT_DIR (or outputDir).

Optional fields:

  • referenceImages: array of { "mimeType": "image/png", "data": "<base64>" } (legacy; prefer URIs or local paths)
  • referenceImageUris: array of { "mimeType": "image/png", "fileUri": "gs://bucket/path.png" }
  • referenceImagePaths: array of { "path": "/abs/path.png", "mimeType": "image/png" } (uploads to GCS)
  • responseModalities: ["IMAGE"] or ["TEXT", "IMAGE"]
  • candidateCount: integer 1-8
  • imageSize: 1K, 2K, 4K (for models that support it)
  • model, location, projectId: overrides
  • gcsBucket: override the GCS bucket for uploads
  • gcsUploadPrefix: override the GCS object prefix for uploads
  • outputGcsBucket: override the GCS bucket for generated image uploads
  • outputGcsPrefix: override the GCS object prefix for generated image uploads
  • outputDir: directory to save generated images on disk (relative paths resolve under NANO_BANANA_OUTPUT_DIR)
  • outputFilePrefix: filename prefix used when saving images and naming GCS objects

Example with a GCS reference image:

{
  "prompt": "Use the reference image for style, generate a new scene.",
  "referenceImageUris": [
    {
      "mimeType": "image/png",
      "fileUri": "gs://my-bucket/reference.png"
    }
  ]
}

Example uploading a local image and using it as a reference:

{
  "prompt": "Transform this into an isometric game scene.",
  "referenceImagePaths": [
    {
      "path": "/absolute/path/to/reference.jpg"
    }
  ]
}

References

  • Gemini 3 Pro Image model card: https://docs.cloud.google.com/vertex-ai/generative-ai/docs/models/gemini/3-pro-image
  • Gemini image generation docs (model IDs, response format): https://ai.google.dev/gemini-api/docs/image-generation

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选