Loading...
Loading...
AI image generation with Google Gemini via MCP - smart model selection, 4K output, aspect ratios, and templates
npx skill4agent add aradotso/mcp-skills nanobanana-mcp-image-generationSkill by ara.so — MCP Skills collection.
GEMINI_API_KEY=your-api-key-here~/Library/Application Support/Claude/claude_desktop_config.json%APPDATA%\Claude\claude_desktop_config.json{
"mcpServers": {
"nanobanana": {
"command": "uvx",
"args": ["nanobanana-mcp-server@latest"],
"env": {
"GEMINI_API_KEY": "your-gemini-api-key-here"
}
}
}
}{
"mcpServers": {
"nanobanana": {
"command": "uvx",
"args": ["nanobanana-mcp-server@latest"],
"env": {
"GEMINI_API_KEY": "your-gemini-api-key-here"
}
}
}
}~/.codex/config.toml[mcp_servers.nanobanana]
command = "uvx"
args = ["nanobanana-mcp-server@latest"]
[mcp_servers.nanobanana.env]
GEMINI_API_KEY = "your-gemini-api-key-here"config.json{
"mcpServers": [
{
"name": "nanobanana",
"command": "uvx",
"args": ["nanobanana-mcp-server@latest"],
"env": {
"GEMINI_API_KEY": "your-gemini-api-key-here"
}
}
]
}{
"mcpServers": {
"nanobanana": {
"command": "uvx",
"args": ["nanobanana-mcp-server@latest"],
"env": {
"NANOBANANA_AUTH_METHOD": "vertex_ai",
"GCP_PROJECT_ID": "your-project-id",
"GCP_REGION": "global"
}
}
}
}gcloud services enable aiplatform.googleapis.comroles/aiplatform.usergenerate_imagepromptmodel_tier"auto""nb2""pro""flash"resolution"4k""1k"aspect_ratio"1:1""16:9""9:16""21:9""4:3""3:4"nthinking_level"LOW""HIGH"enable_groundingoutput_pathnegative_promptuse_template"product_photo""portrait"seed# Simple image generation (auto selects NB2 by default)
generate_image(
prompt="A serene mountain landscape at sunset with a lake reflection"
)
# Generate with specific aspect ratio
generate_image(
prompt="Modern minimalist product photo of a coffee mug",
aspect_ratio="4:3"
)
# Generate multiple variations
generate_image(
prompt="Abstract geometric pattern in blue and gold",
n=3
)# High-quality 4K generation with NB2 (default)
generate_image(
prompt="Professional product photography of a luxury watch on marble surface",
model_tier="nb2",
resolution="4k",
aspect_ratio="16:9",
enable_grounding=True
)
# Maximum quality with Pro model
generate_image(
prompt="Cinematic scene: three characters in a tense standoff at dusk, dramatic lighting",
model_tier="pro",
resolution="4k",
thinking_level="HIGH",
enable_grounding=True,
negative_prompt="blurry, low quality, distorted faces"
)
# Fast generation with Flash model
generate_image(
prompt="Simple icon design for a mobile app",
model_tier="flash",
n=4
)
# Custom output path
generate_image(
prompt="Logo design for tech startup",
output_path="/path/to/output/logo.png",
aspect_ratio="1:1"
)
# Reproducible generation with seed
generate_image(
prompt="Fantasy castle in the clouds",
seed=42,
aspect_ratio="16:9"
)edit_imageimage_pathpromptmodel_tier"auto""nb2""pro""flash"mask_pathresolution"4k""1k"output_path# Basic image editing
edit_image(
image_path="/path/to/photo.jpg",
prompt="Add a sunset sky in the background"
)
# Masked editing (inpainting)
edit_image(
image_path="/path/to/portrait.jpg",
prompt="Change the shirt color to blue",
mask_path="/path/to/mask.png",
model_tier="pro"
)
# High-quality editing with Pro model
edit_image(
image_path="/path/to/landscape.jpg",
prompt="Add dramatic storm clouds and rain",
model_tier="pro",
resolution="4k",
output_path="/path/to/edited.jpg"
)upload_filefile_pathdisplay_name# Upload a reference image
upload_file(
file_path="/path/to/reference.jpg",
display_name="product_reference"
)
# Upload multiple references
upload_file(file_path="/path/to/style1.jpg", display_name="style_example_1")
upload_file(file_path="/path/to/style2.jpg", display_name="style_example_2")generate_image(
prompt="Create a similar product photo in the same style",
# The uploaded files are automatically available to the model context
model_tier="pro"
)generate_image(
prompt="Instagram post with text overlay: 'Summer Sale 50% Off'",
model_tier="nb2",
resolution="4k",
aspect_ratio="1:1",
enable_grounding=True
)generate_image(
prompt="Cinematic establishing shot: a dystopian city with three distinct districts visible, neon lights reflecting on wet streets, flying vehicles in the distance",
model_tier="pro",
resolution="4k",
thinking_level="HIGH",
enable_grounding=True
)generate_image(
prompt="Quick sketch of a user interface mockup",
model_tier="flash",
n=4 # Generate 4 variations quickly
)# Auto routes to NB2 by default
generate_image(prompt="A cat sitting on a windowsill")
# Auto routes to Pro for quality keywords
generate_image(prompt="Professional 4K product photography of a watch")
# Auto routes to NB2 for speed keywords (NB2 is fast enough)
generate_image(prompt="Quick product thumbnail", n=3)use_templateproduct_photoportraitlandscapefoodlogoillustrationabstracticonbackground_replacestyle_transferenhance# Product photography template
generate_image(
prompt="wireless headphones",
use_template="product_photo",
aspect_ratio="1:1"
)
# Portrait template
generate_image(
prompt="female executive, confident expression",
use_template="portrait",
resolution="4k"
)
# Logo design template
generate_image(
prompt="tech startup focusing on AI, modern and clean",
use_template="logo",
aspect_ratio="1:1"
)
# Background replacement template
edit_image(
image_path="/path/to/portrait.jpg",
prompt="office environment with natural light",
use_template="background_replace",
model_tier="pro"
)# Instagram post (square)
generate_image(
prompt="Motivational quote background: 'Dream Big' in elegant typography, pastel gradient",
model_tier="nb2",
aspect_ratio="1:1",
resolution="4k"
)
# YouTube thumbnail (16:9)
generate_image(
prompt="Eye-catching thumbnail: person with shocked expression, bright colors, text 'You Won't Believe This!'",
model_tier="nb2",
aspect_ratio="16:9",
enable_grounding=True
)
# Story/Reel (9:16)
generate_image(
prompt="Vertical video background: animated gradient with floating geometric shapes",
aspect_ratio="9:16",
resolution="4k"
)# Step 1: Generate base product image
generate_image(
prompt="Modern wireless earbuds on marble surface, studio lighting, professional product photography",
model_tier="nb2",
resolution="4k",
aspect_ratio="4:3",
output_path="/products/earbuds_base.jpg"
)
# Step 2: Generate variations with different angles
generate_image(
prompt="Same wireless earbuds, 45-degree angle, spotlight from top right",
model_tier="nb2",
resolution="4k",
n=3
)
# Step 3: Edit to add lifestyle context
edit_image(
image_path="/products/earbuds_base.jpg",
prompt="Add lifestyle context: gym environment in blurred background",
model_tier="pro"
)# Start with fast iterations
generate_image(
prompt="Logo concept for coffee shop, minimalist",
model_tier="flash",
n=4,
aspect_ratio="1:1"
)
# Refine selected concept with NB2
generate_image(
prompt="Coffee shop logo: simplified coffee cup icon with steam forming 'C' letter, earth tones",
model_tier="nb2",
resolution="4k",
seed=12345 # Use seed from preferred flash result
)
# Final high-quality version with Pro
generate_image(
prompt="Final coffee shop logo: refined coffee cup with elegant steam detail, warm brown and cream colors, professional branding quality",
model_tier="pro",
resolution="4k",
aspect_ratio="1:1"
)# Generate consistent style across multiple images
base_prompt = "e-commerce product photography, white background, soft shadows, professional lighting"
# Image 1: Hero shot
generate_image(
prompt=f"{base_prompt}, luxury watch close-up, central composition",
model_tier="nb2",
resolution="4k",
aspect_ratio="16:9",
seed=100
)
# Image 2: Detail shot
generate_image(
prompt=f"{base_prompt}, same luxury watch, focus on crown and dial details",
model_tier="nb2",
resolution="4k",
seed=100 # Same seed for consistency
)
# Image 3: Lifestyle context
generate_image(
prompt=f"{base_prompt}, same luxury watch on wrist, business attire visible",
model_tier="pro", # Pro for complex composition
resolution="4k",
seed=100
)# Upload original image
upload_file(
file_path="/raw/photo.jpg",
display_name="original_photo"
)
# Edit 1: Color correction
edit_image(
image_path="/raw/photo.jpg",
prompt="Enhance colors, increase saturation slightly, professional color grading",
output_path="/edited/step1_color.jpg"
)
# Edit 2: Background replacement
edit_image(
image_path="/edited/step1_color.jpg",
prompt="Replace background with modern office interior, maintain subject lighting",
use_template="background_replace",
model_tier="pro",
output_path="/edited/step2_background.jpg"
)
# Edit 3: Final touches
edit_image(
image_path="/edited/step2_background.jpg",
prompt="Add subtle vignette, enhance sharpness, professional portrait finish",
model_tier="pro",
resolution="4k",
output_path="/edited/final.jpg"
)| Ratio | Use Case | Example |
|---|---|---|
| Instagram posts, profile pics | Social media content |
| Classic photography | Product shots, portraits |
| Portrait orientation | Magazine covers |
| Widescreen, YouTube | Thumbnails, presentations |
| Mobile portrait | Phone wallpapers, Stories |
| Ultra-wide cinematic | Movie-style scenes |
| Photo print standard | Traditional prints |
| DSLR camera standard | Professional photography |
# Verify environment variable is set
echo $GEMINI_API_KEY
# For Claude Desktop, check config file has the key
cat ~/Library/Application\ Support/Claude/claude_desktop_config.jsonGCP_REGION=globalus-central1{
"env": {
"NANOBANANA_AUTH_METHOD": "vertex_ai",
"GCP_PROJECT_ID": "your-project",
"GCP_REGION": "global"
}
}# Use Pro model with high thinking level
generate_image(
prompt="[your prompt] - photorealistic, high detail, professional quality",
model_tier="pro",
resolution="4k",
thinking_level="HIGH",
negative_prompt="blurry, low quality, distorted, artificial"
)# Use seed for reproducibility
generate_image(
prompt="Your prompt here",
seed=42, # Same seed = similar style
model_tier="nb2"
)
# Or enable grounding for factual consistency
generate_image(
prompt="Your prompt here",
enable_grounding=True,
model_tier="nb2"
)# Check file exists and is readable
import os
assert os.path.isfile("/path/to/image.jpg"), "File not found"
# Supported formats: JPEG, PNG, GIF, WebP
# Max size: 20MB per file
upload_file(
file_path="/path/to/image.jpg",
display_name="my_reference"
)# If Pro times out, try NB2
generate_image(
prompt="Your complex prompt",
model_tier="nb2", # Faster than Pro
resolution="4k" # Still 4K quality
)import os
# Set custom output path for all generations
OUTPUT_DIR = "/path/to/my/images"
os.makedirs(OUTPUT_DIR, exist_ok=True)
generate_image(
prompt="Landscape photo",
output_path=f"{OUTPUT_DIR}/landscape_001.jpg"
)prompts = [
"Modern office interior",
"Coastal sunset landscape",
"Abstract geometric pattern"
]
for i, prompt in enumerate(prompts):
try:
generate_image(
prompt=prompt,
output_path=f"/batch/image_{i:03d}.jpg",
model_tier="nb2",
resolution="4k"
)
except Exception as e:
print(f"Failed to generate image {i}: {e}")
continue# Required (choose one authentication method)
GEMINI_API_KEY=your-api-key-here
# OR for Vertex AI
NANOBANANA_AUTH_METHOD=vertex_ai
GCP_PROJECT_ID=your-project-id
GCP_REGION=global
# Optional
NANOBANANA_LOG_LEVEL=INFO # DEBUG, INFO, WARNING, ERROR
NANOBANANA_OUTPUT_DIR=/custom/output/pathenable_grounding=Truethinking_level="HIGH"nupload_file