Skip to main content

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:

  1. photorealistic_shot - High-quality photography
  2. logo_text - Logo design with text rendering
  3. product_shot - E-commerce product photography
  4. sticker_flat - Kawaii/flat sticker designs
  5. iterative_edit_instruction - Precise image editing
  6. composition_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

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Run tests and linting
  5. Commit your changes (git commit -m 'Add amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ†˜ Support

๐Ÿ™ Acknowledgments


Made with โค๏ธ by the Nano Banana Team

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

nanobanana_mcp_server-0.1.3.tar.gz (195.4 kB view details)

Uploaded Source

Built Distribution

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

nanobanana_mcp_server-0.1.3-py3-none-any.whl (69.4 kB view details)

Uploaded Python 3

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

Hashes for nanobanana_mcp_server-0.1.3.tar.gz
Algorithm Hash digest
SHA256 c1c0225d7e4d291434a41efcfba327752922dfaf8895128aaae312337ed738c4
MD5 02734c7f4edad91fe50acfd9208b4fe1
BLAKE2b-256 049f993154bcabc3ebb5d8b723ce35a8f497ddf0445d09667a26622ba38d63c7

See more details on using hashes here.

File details

Details for the file nanobanana_mcp_server-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for nanobanana_mcp_server-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 3ad2cab30509e2d4f34a39a9f9276076d1051e56cba57b0d360f7c5e03ee853c
MD5 33afcbc7baa8465c09c26caffae4c14a
BLAKE2b-256 cb64613c66d7b5deec04dfbbc8a3f77038944ef1fe0b7133ed64d23d7ffce9f4

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