Skip to main content
Glama

nanobanana-mcp

An MCP server for builders who want to generate and edit images with Google Gemini from Claude Code or any other MCP client.

A hardened MCP server for Gemini image generation. Fork of ConechoAI/Nano-Banana-MCP with security fixes, strict TypeScript, and model selection.

Version 1.0.0 License MIT Node.js 18+

Get started · Tools · Configuration · Security · Report an issue

Features

  • 3 tools: generate_image, edit_image, continue_editing

  • Model selection via NANOBANANA_MODEL env var with whitelist validation

  • Security hardened: path traversal protection, file size limits, no plaintext key storage

  • Strict TypeScript: zero any types, Zod validation on all inputs

Related MCP server: Nano-Banana MCP Server

Quick Start

Claude Code

Add to ~/.claude/settings.json:

{
  "mcpServers": {
    "nanobanana": {
      "command": "npx",
      "args": ["tsx", "/path/to/nanobanana-mcp/src/index.ts"],
      "env": {
        "GEMINI_API_KEY": "your-api-key",
        "NANOBANANA_MODEL": "gemini-2.5-flash-image"
      }
    }
  }
}

Other MCP Clients

GEMINI_API_KEY=your-key npx tsx src/index.ts

The server communicates over stdio using the MCP protocol.

Tools

generate_image

Generate a new image from a text prompt.

prompt (required): Text describing the image to create (max 10,000 chars)

edit_image

Edit an existing image with a text prompt.

imagePath (required): Full file path to the image to edit
prompt (required): Text describing the modifications (max 10,000 chars)
referenceImages (optional): Array of file paths to reference images

continue_editing

Continue editing the last generated/edited image in the current session.

prompt (required): Text describing changes to make (max 10,000 chars)
referenceImages (optional): Array of file paths to reference images

Configuration

All configuration is via environment variables. No config files are written to disk.

Variable

Required

Description

GEMINI_API_KEY

Yes

Google Gemini API key

NANOBANANA_GEMINI_API_KEY

No

Override for GEMINI_API_KEY (takes priority)

NANOBANANA_MODEL

No

Model to use (see below)

Available Models

Model ID

Description

gemini-2.5-flash-image

Fast generation, good for high-volume use (default)

gemini-3-pro-image-preview

Pro quality, complex prompts, better text rendering

gemini-3.1-flash-image-preview

Latest model, advanced features

Output

Generated images are saved to ~/nanobanana-images/ with unique filenames. The tool response includes both the file path and the image data inline.

Security

This fork addresses the following security issues from the original:

Issue

Fix

API key saved to disk in plaintext

Removed config file persistence entirely

configure_gemini_token tool accepts key via MCP

Tool removed; keys only via env vars

Path traversal in editImage

validatePath() checks paths resolve within $HOME or $TMPDIR

No prompt length validation

Capped at 10,000 chars via Zod

Hardcoded model

NANOBANANA_MODEL env var with whitelist

Silent swallowing of reference image errors

Errors now thrown and reported

Math.random() for filenames

crypto.randomUUID()

No file size limit on reads

Max 20MB

Verbose errors leak internal paths

Sanitized error messages

process.cwd() fallback for output dir

Fixed to ~/nanobanana-images/

Development

npm install
npm run typecheck   # Type check without emitting
npm run dev         # Run with tsx (hot reload)
npm run build       # Compile to dist/

Project Structure

src/
  index.ts          # MCP server entry point (3 tool handlers)
  gemini-client.ts  # Gemini API wrapper with model selection
  file-handler.ts   # Secure file I/O with path validation
  types.ts          # TypeScript interfaces and Zod schemas

License

MIT - Based on ConechoAI/Nano-Banana-MCP. Built by Dojo Coding.

Available Tools

3 tools
continue_editingA

Continue editing the LAST image generated or edited in this session. Automatically uses the previous image without needing a file path. Use for iterative improvements.

Inputs: prompt (required), referenceImages.

edit_imageB

Edit an existing image file with a text prompt, optionally using additional reference images. Use this when you have the exact file path of an image to modify.

Inputs: imagePath (required), prompt (required), referenceImages.

generate_imageA

Generate a NEW image from a text prompt using Gemini. Use this ONLY when creating a completely new image, not when modifying an existing one.

Inputs: prompt (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.1/5.0

    Scored across 3 tools

    Disambiguation5/5

    Each tool has a clearly distinct purpose: generate_image creates new images, edit_image modifies existing images with a file path, and continue_editing iteratively edits the last image without a file path. The descriptions explicitly differentiate when to use each tool, eliminating any ambiguity.

    Naming Consistency5/5

    All tool names follow a consistent verb_noun pattern (generate_image, edit_image, continue_editing), using snake_case throughout. The naming is predictable and aligns with the actions they perform, making the set easy to understand at a glance.

    Tool Count5/5

    With 3 tools, this server is well-scoped for image generation and editing tasks. Each tool earns its place by covering distinct aspects of the workflow: creation, modification with a file, and iterative editing without a file, avoiding redundancy or gaps.

    Completeness4/5

    The tool set covers core image operations: generate, edit with a file, and continue editing without a file. A minor gap is the lack of tools for deleting or managing images, but this is reasonable for a focused image editing server, as agents can work around this with external file handling.

    Maintenance

    ActivitySlowing
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers