Gemini 2.5 Flash Image MCP Server for Claude Code
Project description
๐ Nanobanana MCP Server
Gemini 2.5 Flash Image MCP Server for Claude Code
A Model Context Protocol (MCP) server that brings Google's powerful Gemini 2.5 Flash Image generation capabilities directly to Claude Code. Generate, edit, and blend images using natural language through Claude's intelligent interface.
โจ Features
๐จ Text-to-Image Generation
- Generate high-quality images from text prompts
- Multiple aspect ratios (1:1, 16:9, 9:16, etc.)
- Style control (photorealistic, digital-art, etc.)
- Batch generation (up to 4 images)
- Intelligent prompt optimization
โ๏ธ Image Editing
- Edit existing images with natural language
- Selective editing with mask support
- Background replacement
- Style transfer and modifications
- Preserve or modify specific elements
๐ญ Image Blending
- Combine multiple images (2-4 sources)
- Create artistic compositions
- Maintain character consistency
- Surreal and creative blending
- Style harmonization
๐ Server Management
- Real-time API status monitoring
- Usage statistics and cost tracking
- Performance metrics
- Health checks and diagnostics
- Automatic error recovery
๐ Quick Start
1. Installation
# Clone the repository
git clone https://github.com/your-username/nanobanana_mcp.git
cd nanobanana_mcp
# Create virtual environment
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
2. Configuration
# Copy environment template
cp .env.example .env
# Edit .env file with your Google AI API key
GOOGLE_AI_API_KEY=your_api_key_here
3. Claude Desktop Integration
Add to your Claude Desktop configuration (claude_desktop_config.json):
{
\"mcpServers\": {
\"nanobanana\": {
\"command\": \"python\",
\"args\": [\"-m\", \"src.server\"],
\"cwd\": \"/path/to/nanobanana_mcp\",
\"env\": {
\"GOOGLE_AI_API_KEY\": \"your_api_key_here\"
}
}
}
}
4. Start Using
# Test the server
python -m src.server --check-health
# Run basic usage example
python examples/basic_usage.py
๐ Usage Guide
Basic Image Generation
Ask Claude Code:
\"๋๋
ธ๋ฐ๋๋๋ฅผ ์ฌ์ฉํด์ ๊ณ ์์ด๊ฐ ๋ชจ์๋ฅผ ์ฐ๊ณ ์๋ ์ฌ์ง์ ์์ฑํด์ค\"
Claude will use:
nanobanana_generate(
prompt=\"A cat wearing a hat, photorealistic style\",
aspect_ratio=\"1:1\",
quality=\"high\"
)
Image Editing
Ask Claude Code:
\"์ด ์ด๋ฏธ์ง์ ๋ฐฐ๊ฒฝ์ ๋ฐ๋ค๋ก ๋ฐ๊ฟ์ค\"
Claude will use:
nanobanana_edit(
image_path=\"./image.png\",
edit_prompt=\"Change the background to ocean view\"
)
Image Blending
Ask Claude Code:
\"์ด ๋ ์ด๋ฏธ์ง๋ฅผ ํฉ์ฑํด์ ํ์์ ์ธ ํ๊ฒฝ์ ๋ง๋ค์ด์ค\"
Claude will use:
nanobanana_blend(
image_paths=[\"./mountain.png\", \"./castle.png\"],
blend_prompt=\"Create a fantasy landscape combining both images\"
)
๐ ๏ธ API Reference
nanobanana_generate
Generate images from text prompts using Gemini 2.5 Flash Image.
Parameters:
prompt(str, required): Text description of the image to generateaspect_ratio(str, optional): Image aspect ratio ("1:1", "16:9", "9:16")style(str, optional): Generation style ("photorealistic", "digital-art", etc.)quality(str, optional): Image quality ("auto", "high", "medium", "low")output_format(str, optional): Output format ("png", "jpeg", "webp")candidate_count(int, optional): Number of images to generate (1-4)additional_keywords(List[str], optional): Extra keywords for enhancementoptimize_prompt(bool, optional): Enable automatic prompt optimization
Returns:
{
\"success\": true,
\"images\": [
{
\"filepath\": \"./outputs/generated_20240101_120000.png\",
\"filename\": \"generated_20240101_120000.png\",
\"size\": [1024, 1024],
\"format\": \"PNG\",
\"file_size\": 2048576,
\"hash\": \"abc123def456\"
}
],
\"metadata\": {
\"request_id\": \"req_123\",
\"generation_time\": 3.2,
\"cost_usd\": 0.039,
\"optimized_prompt\": \"Enhanced prompt text\"
}
}
nanobanana_edit
Edit existing images with natural language instructions.
Parameters:
image_path(str, required): Path to the image file to editedit_prompt(str, required): Natural language editing instructionsmask_path(str, optional): Path to mask image for selective editingoutput_format(str, optional): Output format ("png", "jpeg", "webp")quality(str, optional): Output qualityoptimize_prompt(bool, optional): Enable prompt optimization
Returns:
{
\"success\": true,
\"edited_image\": {
\"filepath\": \"./outputs/edited_20240101_120000.png\",
\"original_path\": \"./inputs/original.png\",
\"edit_applied\": \"Changed background to ocean view\",
\"size\": [1024, 1024]
},
\"metadata\": {
\"editing_time\": 2.8,
\"cost_usd\": 0.039
}
}
nanobanana_blend
Blend multiple images into a new composition.
Parameters:
image_paths(List[str], required): List of 2-4 image paths to blendblend_prompt(str, required): Instructions for how to blend the imagesmaintain_consistency(bool, optional): Maintain character/style consistencyoutput_format(str, optional): Output formatquality(str, optional): Output qualityoptimize_prompt(bool, optional): Enable prompt optimization
Returns:
{
\"success\": true,
\"blended_image\": {
\"filepath\": \"./outputs/blended_20240101_120000.png\",
\"blend_description\": \"Fantasy landscape with castle on mountain\",
\"source_count\": 2
},
\"source_images\": [
{\"path\": \"./img1.png\", \"contribution\": 0.6},
{\"path\": \"./img2.png\", \"contribution\": 0.4}
],
\"metadata\": {
\"blend_time\": 4.1,
\"complexity_score\": 7.2
}
}
nanobanana_status
Check server status and API connectivity.
Parameters:
detailed(bool, optional): Include detailed system informationinclude_history(bool, optional): Include recent operation historyreset_stats(bool, optional): Reset performance statistics
Returns:
{
\"success\": true,
\"server_name\": \"nanobanana\",
\"version\": \"1.0.0\",
\"status\": \"healthy\",
\"uptime_seconds\": 3600,
\"api_status\": {
\"status\": \"healthy\",
\"model\": \"gemini-2.5-flash-image-preview\",
\"api_accessible\": true,
\"last_check\": \"2024-01-01T12:00:00\"
},
\"performance_stats\": {
\"total_requests\": 25,
\"total_images_generated\": 30,
\"total_cost_usd\": 1.17,
\"average_response_time\": 3.2,
\"success_rate\": 0.96
}
}
๐ง Configuration
Environment Variables
Create a .env file with the following variables:
# Required
GOOGLE_AI_API_KEY=your_google_ai_api_key
# Optional - Directories
NANOBANANA_OUTPUT_DIR=./outputs
NANOBANANA_TEMP_DIR=./temp
NANOBANANA_CACHE_DIR=./cache
# Optional - Image Settings
NANOBANANA_MAX_IMAGE_SIZE=10 # Max image size in MB
NANOBANANA_DEFAULT_QUALITY=high # Default image quality
NANOBANANA_DEFAULT_FORMAT=png # Default output format
# Optional - Behavior
NANOBANANA_OPTIMIZE_PROMPTS=true # Enable prompt optimization
NANOBANANA_AUTO_TRANSLATE=true # Auto-translate Korean to English
NANOBANANA_SAFETY_LEVEL=moderate # Content safety level
# Optional - Performance
NANOBANANA_ENABLE_CACHE=true # Enable result caching
NANOBANANA_CACHE_EXPIRY=24 # Cache expiry hours
NANOBANANA_MAX_CACHE_SIZE=1000 # Max cached items
NANOBANANA_MAX_CONCURRENT_REQUESTS=3 # Max concurrent API calls
NANOBANANA_REQUEST_TIMEOUT=300 # API timeout seconds
# Optional - Server
NANOBANANA_HOST=localhost # Server host
NANOBANANA_PORT=8000 # Server port
NANOBANANA_DEV_MODE=false # Development mode
NANOBANANA_LOG_LEVEL=INFO # Logging level
Claude Desktop Configuration
Windows
File location: %APPDATA%\\Claude\\claude_desktop_config.json
macOS
File location: ~/Library/Application Support/Claude/claude_desktop_config.json
Linux
File location: ~/.config/Claude/claude_desktop_config.json
๐ Project Structure
nanobanana_mcp/
โโโ src/
โ โโโ server.py # Main MCP server
โ โโโ gemini_client.py # Gemini API client
โ โโโ config.py # Configuration management
โ โโโ constants.py # Project constants
โ โโโ tools/ # MCP tools implementation
โ โ โโโ generate.py # Text-to-image generation
โ โ โโโ edit.py # Image editing
โ โ โโโ blend.py # Image blending
โ โ โโโ status.py # Server status
โ โโโ utils/ # Utility modules
โ โ โโโ image_handler.py # Image processing
โ โ โโโ prompt_optimizer.py # Prompt enhancement
โ โ โโโ file_manager.py # File management
โ โโโ models/
โ โโโ schemas.py # Pydantic models
โโโ tests/ # Unit tests
โโโ examples/ # Usage examples
โโโ outputs/ # Generated images
โโโ logs/ # Log files
โโโ requirements.txt # Python dependencies
โโโ pyproject.toml # Project configuration
โโโ README.md # This file
๐งช Development
Running Tests
# Run all tests
pytest
# Run with coverage
pytest --cov=src --cov-report=html
# Run specific test category
pytest -m \"not integration\" # Unit tests only
pytest -m \"integration\" # Integration tests only
Development Mode
# Start server in development mode
python -m src.server --dev --debug
# Run with custom settings
python -m src.server --host 0.0.0.0 --port 8080
# Check API health
python -m src.server --check-health
Code Quality
# Format code
black src/ tests/ examples/
# Lint code
flake8 src/ tests/ examples/
# Type checking
mypy src/
๐ Troubleshooting
Common Issues
MCP Server Not Appearing in Claude
-
Check Claude Desktop config location and syntax
# Validate JSON syntax python -c \"import json; json.load(open('claude_desktop_config.json'))\"
-
Verify project path
- Use absolute paths in
cwdfield - Ensure Python is in system PATH
- Use absolute paths in
-
Restart Claude Desktop completely
- Close all Claude windows
- Quit Claude Desktop application
- Restart
API Key Issues
-
Verify API key format
# Test API key python -m src.server --check-health
-
Check API quotas and billing
- Visit Google AI Studio
- Verify API usage limits
Image Generation Failures
-
Content Policy Violations
- Try rephrasing prompts
- Use English prompts for better results
- Avoid restricted content
-
File Permission Issues
# Check output directory permissions ls -la outputs/ chmod 755 outputs/
Debug Commands
# Health check
python -m src.server --check-health
# Debug mode with verbose logging
NANOBANANA_LOG_LEVEL=DEBUG python -m src.server --dev
# Test basic functionality
python examples/basic_usage.py
# Reset statistics
python -m src.server --reset-stats
Log Files
Logs are written to ./logs/nanobanana_mcp.log:
# View recent logs
tail -f logs/nanobanana_mcp.log
# Search for errors
grep ERROR logs/nanobanana_mcp.log
# View startup logs
grep \"Starting\\|Started\" logs/nanobanana_mcp.log
๐ค Contributing
We welcome contributions! Please see our Contributing Guidelines for details.
Development Setup
- Fork the repository
- Create a feature branch
- Set up development environment:
pip install -r requirements-dev.txt pre-commit install
- Make your changes
- Run tests and ensure they pass
- Submit a pull request
Coding Standards
- Follow PEP 8 style guidelines
- Add type hints for all functions
- Write docstrings for public APIs
- Include unit tests for new features
- Update documentation as needed
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- Google AI for the Gemini 2.5 Flash Image API
- Anthropic for Claude and MCP specifications
- FastMCP for the excellent MCP server framework
- Community for feedback and contributions
๐ Additional Resources
- Gemini API Documentation
- Model Context Protocol Specification
- Claude Code Documentation
- Google AI Studio
๐ Changelog
v1.0.0 (2024-08-28)
- Initial release
- Text-to-image generation with Gemini 2.5 Flash
- Image editing capabilities
- Multi-image blending
- Server status monitoring
- Complete Claude Code integration
- Comprehensive test suite
- Usage examples and documentation
Made with โค๏ธ for the Claude Code community
For questions, issues, or feature requests, please open an issue or start a discussion.
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 nanobanana_mcp-1.0.2.tar.gz.
File metadata
- Download URL: nanobanana_mcp-1.0.2.tar.gz
- Upload date:
- Size: 70.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f5a50d78b884de9c2dc217ed18940f9bfdd9acdf87991d82250dd328c66b6ea
|
|
| MD5 |
283e9a724775c34bef1e04a6a2c74901
|
|
| BLAKE2b-256 |
4458eeac3f88bcef4efea304523fc3176dd424746042c3bba0c312864837d012
|
File details
Details for the file nanobanana_mcp-1.0.2-py3-none-any.whl.
File metadata
- Download URL: nanobanana_mcp-1.0.2-py3-none-any.whl
- Upload date:
- Size: 78.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4828a789fc91b0187929879de29423ae3394850c6150b9cbcf3b7cc085c45c29
|
|
| MD5 |
c46d02da70edcbeca1c6287b9e79a4ed
|
|
| BLAKE2b-256 |
1cd047546b2517d53a98d1e40eddb1ed75caac11e452201301fafe24a4284b2f
|