Skip to main content
Glama
Nano Banana MCP Server

Nano Banana MCP Server

by alohc
README.md
# Nano Banana MCP Server

<p align="center">
  <img src="assets/hero.png" alt="Nano Banana MCP Server" width="800" />
</p>

An MCP (Model Context Protocol) server for Google Gemini image generation. This server provides tools to generate and edit images using Gemini's native image generation capabilities.

## Features

- **Text-to-Image Generation**: Generate high-quality images from text prompts
- **Image Editing**: Modify existing images with text instructions
- **Multiple Models**: Support for both fast (Flash) and advanced (Pro) Gemini models
- **Flexible Output**: Various aspect ratios and resolutions up to 4K
- **Base64 Support**: Edit images provided as base64-encoded data

## Installation

### Using UV (recommended)

```bash
uv sync
```

### Using pip

```bash
pip install -e .
```

## Configuration

### Environment Variables

| Variable | Required | Description |
|----------|----------|-------------|
| `GEMINI_API_KEY` | Yes | Your Google Gemini API key |
| `NANO_BANANA_OUTPUT_DIR` | No | Directory for generated images (defaults to `./output`) |

Get your API key from [Google AI Studio](https://aistudio.google.com/apikey).

## Usage

### Running the Server

```bash
# Via entry point
nano-banana-mcp-server

# With verbose logging
nano-banana-mcp-server -v

# Via module
python -m nano_banana_mcp_server
```

### Claude Desktop Configuration

Add to your Claude Desktop config (`~/Library/Application Support/Claude/claude_desktop_config.json` on macOS):

```json
{
  "mcpServers": {
    "nano-banana": {
      "command": "uv",
      "args": ["--directory", "/path/to/nano-banana-mcp-server", "run", "nano-banana-mcp-server"],
      "env": {
        "GEMINI_API_KEY": "your-api-key-here"
      }
    }
  }
}
```

Images will be saved to `./output` relative to where the server runs. To use a different directory, add:
```json
"env": {
  "GEMINI_API_KEY": "your-api-key-here",
  "NANO_BANANA_OUTPUT_DIR": "/custom/path"
}
```

## Available Tools

### generate_image_from_text

Generate an image from a text prompt.

**Parameters:**
- `prompt` (required): Text description of the image to generate
- `model`: Model to use - `gemini-2.5-flash-image` (default, fast) or `gemini-3-pro-image-preview` (advanced)
- `aspect_ratio`: Image aspect ratio - `1:1`, `2:3`, `3:2`, `3:4`, `4:3`, `4:5`, `5:4`, `9:16`, `16:9`, `21:9`
- `image_size`: Resolution - `1K`, `2K`, `4K` (Pro model only)

**Example:**
```
Generate a photorealistic image of a sunset over the ocean with a sailboat
```

### edit_existing_image

Edit an existing image using a text prompt.

**Parameters:**
- `prompt` (required): Description of the edits to make
- `image_path` (required): Path to the input image file
- `model`: Model to use
- `aspect_ratio`: Output aspect ratio
- `image_size`: Output resolution (Pro model only)

**Example:**
```
Add a rainbow to the sky in this landscape photo
```

### edit_image_base64

Edit an image provided as base64-encoded data.

**Parameters:**
- `prompt` (required): Description of the edits to make
- `image_base64` (required): Base64-encoded image data
- `mime_type`: Image MIME type (default: `image/png`)
- `model`: Model to use
- `aspect_ratio`: Output aspect ratio
- `image_size`: Output resolution (Pro model only)

## Models

| Model | ID | Features |
|-------|------|----------|
| Flash | `gemini-2.5-flash-image` | Fast generation, good for most use cases |
| Pro | `gemini-3-pro-image-preview` | Advanced reasoning, 4K support, up to 14 reference images, Google Search grounding |

## Prompting Tips

### For Photorealistic Images

Use photography terminology:
```
A photorealistic close-up portrait of a golden retriever,
illuminated by soft window light, captured with an 85mm
portrait lens with shallow depth of field. The mood is
warm and peaceful.
```

### For Stylized Images

Be explicit about the style:
```
A kawaii-style sticker of a happy cat wearing a chef's hat,
featuring bold outlines, simple cel-shading, and a pastel
color palette on a white background.
```

### For Image Editing

Be specific about changes:
```
Change the color of the car from red to blue, keeping all
other elements exactly the same.
```

## Development

```bash
# Install with dev dependencies
uv sync --all-extras

# Run tests
uv run pytest

# Type checking
uv run pyright

# Linting
uv run ruff check .

# Formatting
uv run ruff format .
```

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.