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-1PSIDTScookie expires frequently (sometimes in minutes). Follow these community-tested tips to maximize cookie lifespan:
Best Practices for Long-Lasting Cookies:
-
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
-
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
-
Use a Dedicated Google Account
- Cookies expire faster when the account is used actively elsewhere
- Consider creating a separate account just for API access
-
When Cookies Expire
- Usually only
__Secure-1PSIDTSexpires first - Try updating just PSIDTS using the
set_cookietool - If that fails, get fresh
__Secure-1PSIDas well
- Usually only
Steps to Get Cookies:
- Open Incognito window (Ctrl+Shift+N / Cmd+Shift+N)
- Go to gemini.google.com and log in
- Open DevTools (F12) โ Application โ Cookies
- Copy the value of
__Secure-1PSID(required) - Copy
__Secure-1PSIDTSif available (some accounts don't have it) - 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,allstyle:flat-design,modern,minimalist,3d-render,isometric,gradient,glassmorphismshape:squircle(iOS style),rounded,circle,squareremove_background:true/falsebackground_color: hex color like#FF5733or 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:
- Get cookies from incognito mode and close Gemini tab immediately
- Use
set_cookietool to update just the PSIDTS value - Update PSID as well - sometimes PSID itself expires (per community feedback)
- 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-1PSIDTSwhen 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e96c02a6625f5dece20a9b31f633d7373c2eeb026dcb7f9bf7b92229633decb
|
|
| MD5 |
a457efacc3b3eadfc56ea4d58d726aec
|
|
| BLAKE2b-256 |
b6b218347b6cf9376a71fccc4d3a451438bbd1612447609801154df0321345bf
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23d1e465858c0dc97e275b44eb1c40282426165cd8ec30233a175db65d0ab982
|
|
| MD5 |
c69d7db1e1cef69d512fdd960c3762d8
|
|
| BLAKE2b-256 |
ed808132d179b14ef1afc922dfca67795b4c445efe44d2e89640efedb4fe66e8
|