A production-ready MCP server for AI-powered image generation using Gemini 2.5 Flash Image
Project description
Nano Banana MCP Server ๐
A production-ready Model Context Protocol (MCP) server that provides AI-powered image generation and editing capabilities through Google's Gemini 2.5 Flash Image model. Built with FastMCP for seamless integration with AI development tools like Claude Desktop, Cursor, and VS Code.
โจ Features
- ๐จ Image Generation: Create images from detailed text prompts
- โ๏ธ Image Editing: Conversational image editing with style preservation
- ๐ File Management: Upload and manage large files via Gemini Files API
- ๐ Template System: Pre-built prompt templates for common use cases
- ๐ Resource Discovery: Browse available templates and file metadata
- ๐ก๏ธ Production Ready: Comprehensive error handling, logging, and validation
- โก High Performance: Modular architecture with optimized processing
- ๐ Security: Input validation, sanitization, and safe error handling
๐ Quick Start
Prerequisites
- Python 3.11+
- Google Gemini API Key (Get one here)
- FastMCP CLI (for development)
Installation
Option 1: FastMCP CLI (Recommended for Development)
# Install FastMCP CLI
pip install fastmcp
# Clone the repository
git clone https://github.com/nano-banana/mcp-server.git
cd nanobanana-mcp-server
# Install with development dependencies
pip install -e .[dev]
# Set up environment
cp .env.example .env
# Edit .env to add your GEMINI_API_KEY
Option 2: Traditional Python Setup
# Clone the repository
git clone https://github.com/nano-banana/mcp-server.git
cd nanobanana-mcp-server
# Install dependencies with uv (recommended)
uv sync
Configuration
# Copy environment template
cp .env.example .env
# Edit .env file with your API key
GEMINI_API_KEY=your_gemini_api_key_here
# Optional configuration
LOG_LEVEL=INFO
LOG_FORMAT=standard
FASTMCP_TRANSPORT=stdio
Run the Server
Using FastMCP CLI (Recommended)
# Install FastMCP CLI
pip install fastmcp
# Run with development mode (includes MCP Inspector)
fastmcp dev server:create_app
# Run in production mode
fastmcp run server:create_app
# Run with specific environment variables
GEMINI_API_KEY=your_key fastmcp dev server:create_app
# Run with HTTP transport
FASTMCP_TRANSPORT=http fastmcp run server:create_app
Direct Python Execution
# Standard mode (STDIO transport)
python server.py
# HTTP mode (for remote access)
FASTMCP_TRANSPORT=http FASTMCP_PORT=8000 python server.py
# With custom logging
LOG_LEVEL=DEBUG LOG_FORMAT=json python server.py
FastMCP CLI Advanced Usage
# Install server in MCP clients (Claude Desktop, etc.)
fastmcp install
# Inspect server capabilities
fastmcp inspect server:create_app
# Create persistent project environment
fastmcp project prepare fastmcp.json
# Run with additional dependencies
fastmcp dev server:create_app --with pillow==10.4.0
# Run with configuration file
fastmcp run --config fastmcp.json
๐ ๏ธ Usage
Tools Available
1. generate_image
Generate images from text prompts with optional input image conditioning.
{
"prompt": "A photorealistic mountain landscape at sunset",
"n": 2,
"aspect_hint": "16:9",
"negative_prompt": "blurry, low quality"
}
2. edit_image
Edit existing images using natural language instructions.
{
"instruction": "Add a wizard hat to the cat",
"base_image_b64": "iVBORw0KGgoAAAANSUhEUgAA...",
"mime_type": "image/png"
}
3. upload_file
Upload files to Gemini Files API for reuse across prompts.
{
"path": "/path/to/image.jpg",
"display_name": "Reference Image"
}
Resources Available
1. gemini://files/{name}
Access file metadata from Gemini Files API.
2. nano-banana://prompt-templates
Browse available prompt templates with examples.
Prompt Templates
The server includes 6 pre-built prompt templates:
photorealistic_shot- High-quality photographylogo_text- Logo design with text renderingproduct_shot- E-commerce product photographysticker_flat- Kawaii/flat sticker designsiterative_edit_instruction- Precise image editingcomposition_and_style_transfer- Artistic style transfer
Example Usage in MCP Client
# Generate a professional product shot
result = mcp_client.call_tool("generate_image", {
"prompt": mcp_client.get_prompt("product_shot", {
"product": "wireless headphones",
"background": "gradient backdrop",
"lighting_setup": "three-point lighting",
"angle": "45-degree angle",
"aspect_hint": "Square image"
})
})
๐งช Development Workflow
FastMCP CLI Development
The project is optimized for FastMCP CLI development workflow:
# 1. Clone and setup
git clone <repository-url>
cd nanobanana-mcp-server
# 2. Install FastMCP CLI
pip install fastmcp
# 3. Set up environment
cp .env.example .env
# Edit .env to add your GEMINI_API_KEY
# 4. Run in development mode (with MCP Inspector)
fastmcp dev server:create_app
# 5. Test tools interactively via MCP Inspector
# - Visit the Inspector URL shown in console
# - Test image generation tools
# - Inspect server capabilities
# 6. Install in Claude Desktop for production testing
fastmcp install
Quick Development Commands
# Development with hot reload
fastmcp dev server:create_app --with-editable .
# Run with debug logging
LOG_LEVEL=DEBUG fastmcp dev server:create_app
# Test specific functionality
fastmcp inspect server:create_app
# Package for distribution
fastmcp project prepare fastmcp.json
๐ Project Structure
nanobanana-mcp-server/
โโโ server.py # Main entry point & factory function
โโโ fastmcp.json # FastMCP CLI configuration
โโโ pyproject.toml # Project configuration
โโโ ruff.toml # Ruff linting configuration
โโโ .env.example # Environment template
โโโ config/ # Configuration management
โ โโโ settings.py # Server & API settings
โ โโโ constants.py # Application constants
โโโ core/ # Core functionality
โ โโโ server.py # FastMCP server setup
โ โโโ exceptions.py # Custom exceptions
โ โโโ validation.py # Input validation
โโโ services/ # Business logic services
โ โโโ gemini_client.py # Gemini API wrapper
โ โโโ image_service.py # Image processing
โ โโโ file_service.py # File management
โโโ tools/ # MCP tools implementation
โ โโโ generate_image.py # Image generation tool
โ โโโ edit_image.py # Image editing tool
โ โโโ upload_file.py # File upload tool
โโโ resources/ # MCP resources
โ โโโ file_metadata.py # File metadata resource
โ โโโ template_catalog.py # Template catalog
โโโ prompts/ # Prompt templates
โ โโโ photography.py # Photo templates
โ โโโ design.py # Design templates
โ โโโ editing.py # Editing templates
โโโ utils/ # Utility functions
โ โโโ image_utils.py # Image processing utilities
โ โโโ logging_utils.py # Logging configuration
โ โโโ validation_utils.py # Additional validation
โโโ tests/ # Test suite
โโโ ...
๐ง Development
Setup Development Environment
# Install with development dependencies
pip install -e .[dev]
# Install pre-commit hooks
pre-commit install
# Run code formatting
ruff format .
# Run linting
ruff check .
# Run type checking
mypy .
Run Tests
# Run test suite
pytest
# Run with coverage
pytest --cov=. --cov-report=html
# Run specific test categories
pytest -m unit
pytest -m integration
Code Quality
The project uses:
- Ruff for linting and formatting
- MyPy for type checking
- pytest for testing
- pre-commit for git hooks
๐ Deployment
Local Production
# Production settings
export GEMINI_API_KEY=your_production_key
export LOG_LEVEL=INFO
export LOG_FORMAT=json
export FASTMCP_MASK_ERRORS=true
# Run server
python server.py
Docker Deployment
FROM python:3.11-slim
# Install uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv
WORKDIR /app
COPY pyproject.toml uv.lock ./
RUN uv sync --frozen
COPY . .
CMD ["uv", "run", "python", "-m", "nanobanana_mcp_server.server"]
Process Management
# Using systemd
sudo systemctl start nanobanana-mcp-server
sudo systemctl enable nanobanana-mcp-server
# Using PM2
pm2 start "python server.py" --name nanobanana-mcp-server
๐ Monitoring
The server provides comprehensive logging:
# Standard logging
2024-01-15 10:30:00 - core.server - INFO - Server started successfully
# JSON structured logging
{"timestamp": "2024-01-15T10:30:00Z", "level": "INFO", "message": "Image generated", "duration_ms": 3420}
Health Monitoring
- Server startup validation
- API connectivity checks
- Resource usage tracking
- Error rate monitoring
๐ค Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run tests and linting
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Support
- Documentation: docs.nanobanana.dev
- Issues: GitHub Issues
- Discussions: GitHub Discussions
๐ Acknowledgments
- Built with FastMCP framework
- Powered by Google Gemini 2.5 Flash Image
- Inspired by the Model Context Protocol specification
Made with โค๏ธ by the Nano Banana Team
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_server-0.1.3.tar.gz.
File metadata
- Download URL: nanobanana_mcp_server-0.1.3.tar.gz
- Upload date:
- Size: 195.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1c0225d7e4d291434a41efcfba327752922dfaf8895128aaae312337ed738c4
|
|
| MD5 |
02734c7f4edad91fe50acfd9208b4fe1
|
|
| BLAKE2b-256 |
049f993154bcabc3ebb5d8b723ce35a8f497ddf0445d09667a26622ba38d63c7
|
File details
Details for the file nanobanana_mcp_server-0.1.3-py3-none-any.whl.
File metadata
- Download URL: nanobanana_mcp_server-0.1.3-py3-none-any.whl
- Upload date:
- Size: 69.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ad2cab30509e2d4f34a39a9f9276076d1051e56cba57b0d360f7c5e03ee853c
|
|
| MD5 |
33afcbc7baa8465c09c26caffae4c14a
|
|
| BLAKE2b-256 |
cb64613c66d7b5deec04dfbbc8a3f77038944ef1fe0b7133ed64d23d7ffce9f4
|