Skip to main content

MCP server for Nano Banana image generation using Gemini Web API

Project description

Nano Banana MCP

MCP Server for image generation using Gemini Web API (reverse-engineered).

โš ๏ธ Disclaimer: This project uses unofficial API access via browser cookies. Use at your own risk.

Features

  • ๐ŸŽจ Text-to-Image Generation: Create images from text prompts
  • โœ๏ธ Image Editing: Modify existing images with natural language
  • ๐Ÿ’ฌ Chat: Interact with Gemini for text and image generation
  • ๐ŸŽฏ App Icon Generation: Generate professional app icons with:
    • Automatic background removal (rembg/RMBG 2.0)
    • Platform presets (iOS, Android, macOS, Web)
    • Multiple sizes generation
    • Shape masks (squircle, rounded, circle)
  • ๐Ÿ”ฒ Pattern Generation: Create seamless patterns and textures
  • ๐Ÿ“Š Diagram Generation: Generate technical diagrams and flowcharts
  • ๐Ÿ–ผ๏ธ Banner/Thumbnail Generation: Social media and YouTube ready

Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     MCP Protocol     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   AI Client     โ”‚โ—„โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บโ”‚  nano-banana-mcp โ”‚
โ”‚ (Claude, etc.)  โ”‚                      โ”‚     (Python)     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                                  โ”‚
                                                  โ”‚ gemini_webapi
                                                  โ–ผ
                                         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                                         โ”‚  Gemini Web UI   โ”‚
                                         โ”‚  (Google Server) โ”‚
                                         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Prerequisites

  • Python 3.10+
  • Google account with Gemini access
  • Browser cookies from gemini.google.com

Installation

# Clone the repository
git clone <your-repo-url>
cd nano-banana-mcp

# Install with pip (basic)
pip install -e .

# Or with uv
uv pip install -e .

Optional Dependencies

Background Removal (for App Icons)

Choose one of the following options:

# Option 1: rembg (Recommended - lightweight, CPU-only)
pip install rembg[cpu]

# Option 2: rembg with GPU acceleration
pip install rembg[gpu]

# Option 3: RMBG 2.0 (Best quality - requires more resources)
pip install transformers torch torchvision

Background Removal Engines Comparison:

Engine Quality Speed Size GPU Required
rmbg2 (BRIA RMBG 2.0) Best (90%) Medium ~500MB Optional (faster with CUDA)
rembg + isnet-general-use Excellent Medium 170MB No
rembg + isnet-anime Excellent Medium 170MB No (best for icons)
rembg + silueta Good Fastest 43MB No
rembg + u2netp Good Fast 4.7MB No

Environment Variables for Background Removal:

# Choose engine: 'rembg' (default) or 'rmbg2' (best quality)
BG_REMOVAL_ENGINE=rembg

# Choose rembg model (if using rembg engine)
REMBG_MODEL=isnet-general-use  # Options: u2netp, isnet-general-use, isnet-anime, silueta, birefnet-general

Configuration

1. Get Your Cookies (Important!)

โš ๏ธ Cookie Expiration: The __Secure-1PSIDTS cookie expires frequently (sometimes in minutes). Follow these community-tested tips to maximize cookie lifespan:

Best Practices for Long-Lasting Cookies:

  1. Use Incognito Mode (Highly Recommended)

    • Open an incognito/private browser window
    • Log in to gemini.google.com
    • Get your cookies from there
    • Cookies obtained in incognito can last weeks/months
  2. Close Gemini Immediately After Getting Cookies

    • After copying cookies, close the Gemini tab immediately
    • Keeping Gemini open in browser causes cookies to expire faster
    • Don't visit gemini.google.com while using this tool
  3. Use a Dedicated Google Account

    • Cookies expire faster when the account is used actively elsewhere
    • Consider creating a separate account just for API access
  4. When Cookies Expire

    • Usually only __Secure-1PSIDTS expires first
    • Try updating just PSIDTS using the set_cookie tool
    • If that fails, get fresh __Secure-1PSID as well

Steps to Get Cookies:

  1. Open Incognito window (Ctrl+Shift+N / Cmd+Shift+N)
  2. Go to gemini.google.com and log in
  3. Open DevTools (F12) โ†’ Application โ†’ Cookies
  4. Copy the value of __Secure-1PSID (required)
  5. Copy __Secure-1PSIDTS if available (some accounts don't have it)
  6. Close the Gemini tab immediately

2. Set Environment Variables

Create a .env file:

# Required
GEMINI_SECURE_1PSID=your_cookie_value_here

# Optional
GEMINI_SECURE_1PSIDTS=your_cookie_value_here
NANOBANANA_OUTPUT_DIR=./nanobanana-output
NANOBANANA_MODEL=gemini-2.0-flash-exp
NANOBANANA_TIMEOUT=60

3. Configure MCP Client

Add to your MCP client config (e.g., Claude Desktop):

{
  "mcpServers": {
    "nano-banana": {
      "command": "nano-banana-mcp",
      "env": {
        "GEMINI_SECURE_1PSID": "your_cookie_value"
      }
    }
  }
}

Or with Python directly:

{
  "mcpServers": {
    "nano-banana": {
      "command": "python",
      "args": ["-m", "nano_banana_mcp.server"],
      "cwd": "/path/to/nano-banana-mcp",
      "env": {
        "GEMINI_SECURE_1PSID": "your_cookie_value"
      }
    }
  }
}

Usage

Generate Image

Generate an image of a sunset over mountains

Edit Image

Edit my_photo.png: add sunglasses to the person

Generate Icon

Create an app icon for a music player app

Advanced icon generation:

Generate app icon for a fitness app with platform=ios, style=gradient, shape=squircle

Available options:

  • platform: ios, android, web, macos, all
  • style: flat-design, modern, minimalist, 3d-render, isometric, gradient, glassmorphism
  • shape: squircle (iOS style), rounded, circle, square
  • remove_background: true/false
  • background_color: hex color like #FF5733 or named color

Generate Pattern

Create a seamless geometric pattern in blue tones

Generate Diagram

Create a flowchart for user authentication

Available Tools

Tool Description
generate_image Generate images from text prompts with style/mood options
edit_image Edit existing images with natural language
chat General chat with image support
generate_app_icon Generate app icons with background removal & platform presets
generate_banner Generate banners (16:9, 21:9 aspect ratios)
generate_thumbnail Generate YouTube/video thumbnails
generate_logo Generate logo designs
generate_pattern Generate seamless patterns and textures
generate_diagram Generate technical diagrams and flowcharts
generate_illustration Generate artistic illustrations
generate_social_post Generate social media images
generate_product_photo Generate product photography
set_cookie Update expired cookies

Output

Generated images are saved to ./nanobanana-output/ by default.

Troubleshooting

"SECURE_1PSIDTS could get expired frequently"

This is the most common error. Solutions in order of priority:

  1. Get cookies from incognito mode and close Gemini tab immediately
  2. Use set_cookie tool to update just the PSIDTS value
  3. Update PSID as well - sometimes PSID itself expires (per community feedback)
  4. Use a dedicated Google account that isn't used elsewhere

"Missing GEMINI_SECURE_1PSID"

  • Ensure you copied the correct cookie value
  • Cookie value should start with g.a...

"Image generation failed"

  • Check if your Google account has Gemini access
  • Try a simpler prompt
  • Cookies may have expired - check the error message

Rate Limiting

  • Wait between requests if you encounter errors
  • Avoid rapid successive requests

Keep-Alive Feature

This MCP server includes an automatic keep-alive mechanism that helps extend cookie lifespan:

  • Sends background pings every 30 minutes
  • Automatically refreshes __Secure-1PSIDTS when possible
  • Requirement: The MCP server process must stay running continuously

The keep-alive works best with cookies obtained from incognito mode on a dedicated account.

Limitations

  • โš ๏ธ Cookies can expire (use incognito + dedicated account to minimize)
  • โš ๏ธ May be rate-limited by Google
  • โš ๏ธ API can change without notice
  • โš ๏ธ Not suitable for production use

License

MIT

Disclaimer

This project is for educational purposes only. It uses unofficial API access and may violate Google's Terms of Service. Use responsibly and at your own risk.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

iflow_mcp_lns2905_nano_banana_mcp-0.1.0.tar.gz (81.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file iflow_mcp_lns2905_nano_banana_mcp-0.1.0.tar.gz.

File metadata

  • Download URL: iflow_mcp_lns2905_nano_banana_mcp-0.1.0.tar.gz
  • Upload date:
  • Size: 81.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for iflow_mcp_lns2905_nano_banana_mcp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9e96c02a6625f5dece20a9b31f633d7373c2eeb026dcb7f9bf7b92229633decb
MD5 a457efacc3b3eadfc56ea4d58d726aec
BLAKE2b-256 b6b218347b6cf9376a71fccc4d3a451438bbd1612447609801154df0321345bf

See more details on using hashes here.

File details

Details for the file iflow_mcp_lns2905_nano_banana_mcp-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: iflow_mcp_lns2905_nano_banana_mcp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 50.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for iflow_mcp_lns2905_nano_banana_mcp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 23d1e465858c0dc97e275b44eb1c40282426165cd8ec30233a175db65d0ab982
MD5 c69d7db1e1cef69d512fdd960c3762d8
BLAKE2b-256 ed808132d179b14ef1afc922dfca67795b4c445efe44d2e89640efedb4fe66e8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page