DEV Community

adamydwang
adamydwang

Posted on

Deploy Nano Banana MCP Service in 5 Minutes: Integrate AI Image Generation into Your Workflow

Want to add powerful AI image generation to your workflow tools like Dify, n8n, Claude, or Cursor? This guide shows you how to deploy a Nano Banana MCP (Model Context Protocol) server using genai-mcp in just minutes.

What is MCP and Why Should You Care?

Model Context Protocol (MCP) is an open protocol that enables AI assistants to securely access external tools and data sources. Think of it as a standardized way for AI tools to talk to your services.

genai-mcp is an open-source MCP server that wraps Google Gemini and compatible backends into a standardized HTTP endpoint. It provides:

  • Image generation from text prompts
  • Image editing with natural language instructions
  • S3/OSS integration for automatic image storage
  • Streamable HTTP transport compatible with major MCP clients
  • Multiple backend support: Works with Google Gemini official API and third-party Gemini-compatible backends (like Nano Banana)
  • Multiple AI model support: Supports various Generative AI models, including Tongyi Wanxiang 2.5 (faster and more cost-effective)

Prerequisites

Before we start, make sure you have:

  • Go 1.21+ (if building from source)
  • A Nano Banana API key (or Google Gemini API key, or Tongyi Wanxiang API key)
  • Optional: S3/OSS bucket for image storage

Step 1: Quick Deployment

Option A: Download Pre-built Binary (Recommended)

  1. Download the binary for your platform from the Releases page:
# For macOS (Apple Silicon)
wget https://github.com/adamydwang/genai-mcp/releases/download/release%2F0.2/genai-mcp.darwin.arm64
chmod +x genai-mcp.darwin.arm64
mv genai-mcp.darwin.arm64 genai-mcp

# For Linux
wget https://github.com/adamydwang/genai-mcp/releases/download/release%2F0.2/genai-mcp.linux.amd64
chmod +x genai-mcp.linux.amd64
mv genai-mcp.linux.amd64 genai-mcp
Enter fullscreen mode Exit fullscreen mode
  1. Create configuration file:
# Clone the repo to get env.example
git clone https://github.com/adamydwang/genai-mcp.git
cd genai-mcp
cp env.example .env
Enter fullscreen mode Exit fullscreen mode

Option B: Build from Source

git clone https://github.com/adamydwang/genai-mcp.git
cd genai-mcp
go build .
Enter fullscreen mode Exit fullscreen mode

Step 2: Configure Your Backend

genai-mcp supports multiple backends. Choose one based on your needs:

Option 1: Nano Banana (Third-party Gemini-compatible Backend)

Edit your .env file:

# Use Gemini provider (works with Nano Banana and other compatible backends)
GENAI_PROVIDER=gemini

# Point to your Nano Banana endpoint
GENAI_BASE_URL=https://your-nano-banana-endpoint.com

# Your Nano Banana API key
GENAI_API_KEY=your_nano_banana_api_key_here

# Model name (adjust based on your Nano Banana setup)
GENAI_GEN_MODEL_NAME=gemini-3-pro-image-preview
GENAI_EDIT_MODEL_NAME=gemini-3-pro-image-preview

# Request timeout (seconds)
GENAI_TIMEOUT_SECONDS=120

# Image output format: 'base64' or 'url'
GENAI_IMAGE_FORMAT=url
Enter fullscreen mode Exit fullscreen mode

Option 2: Google Gemini Official API

GENAI_PROVIDER=gemini
GENAI_BASE_URL=https://generativelanguage.googleapis.com
GENAI_API_KEY=your_google_gemini_api_key_here
GENAI_GEN_MODEL_NAME=gemini-3-pro-image-preview
GENAI_EDIT_MODEL_NAME=gemini-3-pro-image-preview
GENAI_TIMEOUT_SECONDS=120
GENAI_IMAGE_FORMAT=url
Enter fullscreen mode Exit fullscreen mode

Option 3: Tongyi Wanxiang 2.5 (Faster & More Cost-Effective)

For faster and more affordable image generation, use Tongyi Wanxiang:

# Use Wan provider
GENAI_PROVIDER=wan

# Tongyi Wanxiang endpoint
GENAI_BASE_URL=https://dashscope.aliyuncs.com

# Your DashScope API key
GENAI_API_KEY=your_dashscope_api_key_here

# Tongyi Wanxiang model names
GENAI_GEN_MODEL_NAME=wan2.5-t2i-preview
GENAI_EDIT_MODEL_NAME=wan2.5-i2i-preview

GENAI_TIMEOUT_SECONDS=120
GENAI_IMAGE_FORMAT=url
Enter fullscreen mode Exit fullscreen mode

Server & OSS Configuration

Add these to your .env:

# Server configuration
SERVER_ADDRESS=0.0.0.0
SERVER_PORT=8080

# OSS/S3 Configuration (required if GENAI_IMAGE_FORMAT=url)
OSS_ENDPOINT=oss-cn-beijing.aliyuncs.com  # or your S3 endpoint
OSS_REGION=us-east-1
OSS_ACCESS_KEY=your_access_key
OSS_SECRET_KEY=your_secret_key
OSS_BUCKET=your_bucket_name
Enter fullscreen mode Exit fullscreen mode

Step 3: Start the Server

./genai-mcp
Enter fullscreen mode Exit fullscreen mode

You should see:

INFO Starting GenAI MCP Server
INFO Server configuration loaded
INFO MCP server starting address=0.0.0.0:8080/mcp
Enter fullscreen mode Exit fullscreen mode

Your MCP endpoint is now available at: http://localhost:8080/mcp

Step 4: Test the Server

The project includes Python test scripts. First, install dependencies:

cd tests
pip install -r requirements.txt
Enter fullscreen mode Exit fullscreen mode

Test the connection:

# List available tools
python test_list_tools.py

# Generate an image
python test_generate_image.py "A futuristic cityscape at sunset"

# Edit an image
python test_edit_image.py "Make it more vibrant" "https://example.com/image.jpg"
Enter fullscreen mode Exit fullscreen mode

Step 5: Integrate into Your Workflow Tools

Integration with Cursor

Cursor supports MCP servers via HTTP. Add this to your Cursor settings:

{
  "mcpServers": {
    "genai-mcp": {
      "url": "http://localhost:8080/mcp",
      "transport": "http"
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Now you can use image generation directly in Cursor's AI chat!

Integration with Claude Desktop

Edit your Claude Desktop config (usually ~/Library/Application Support/Claude/claude_desktop_config.json on macOS):

{
  "mcpServers": {
    "genai-mcp": {
      "command": "curl",
      "args": [
        "-X", "POST",
        "http://localhost:8080/mcp"
      ],
      "env": {}
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Integration with Dify

Dify supports HTTP-based tools. In your Dify workflow:

  1. Go to ToolsAdd Custom Tool
  2. Configure as follows:
Name: Gemini Image Generator
Method: POST
URL: http://your-server:8080/mcp
Headers:
  Content-Type: application/json
Body:
  {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "tools/call",
    "params": {
      "name": "gemini_generate_image",
      "arguments": {
        "prompt": "{{prompt}}"
      }
    }
  }
Enter fullscreen mode Exit fullscreen mode

Integration with n8n

In n8n, create an HTTP Request node:

  1. Method: POST
  2. URL: http://localhost:8080/mcp
  3. Headers:
   {
     "Content-Type": "application/json"
   }
Enter fullscreen mode Exit fullscreen mode
  1. Body (JSON):
   {
     "jsonrpc": "2.0",
     "id": 1,
     "method": "tools/call",
     "params": {
       "name": "gemini_generate_image",
       "arguments": {
         "prompt": "{{ $json.prompt }}"
       }
     }
   }
Enter fullscreen mode Exit fullscreen mode

Integration with Custom Applications

Here's a simple Python example:

import requests
import json

def generate_image(prompt: str, mcp_url: str = "http://localhost:8080/mcp"):
    """Generate an image using the MCP server"""
    payload = {
        "jsonrpc": "2.0",
        "id": 1,
        "method": "tools/call",
        "params": {
            "name": "gemini_generate_image",
            "arguments": {
                "prompt": prompt
            }
        }
    }

    response = requests.post(mcp_url, json=payload)
    result = response.json()

    if "error" in result:
        raise Exception(f"MCP Error: {result['error']}")

    return result["result"]["content"][0]["text"]

# Usage
image_url = generate_image("A serene mountain landscape at dawn")
print(f"Generated image: {image_url}")
Enter fullscreen mode Exit fullscreen mode

Available MCP Tools

The server exposes different tools depending on your provider:

For Gemini/Nano Banana Backend

1. gemini_generate_image

Generates an image from a text prompt.

Parameters:

  • prompt (string, required): Description of the image to generate

Returns:

  • Base64 data URI (if GENAI_IMAGE_FORMAT=base64)
  • OSS/S3 URL (if GENAI_IMAGE_FORMAT=url)

2. gemini_edit_image

Edits an image based on a text prompt.

Parameters:

  • prompt (string, required): How to edit the image
  • image_urls (string, required): JSON array of image URLs or data URIs

Example:

{
  "prompt": "Make the sky more dramatic with storm clouds",
  "image_urls": "[\"https://example.com/image.jpg\"]"
}
Enter fullscreen mode Exit fullscreen mode

For Tongyi Wanxiang Backend

When using GENAI_PROVIDER=wan, the server exposes these tools:

  • wan_create_generate_image_task - Create an image generation task
  • wan_query_generate_image_task - Query the status of a generation task
  • wan_create_edit_image_task - Create an image editing task
  • wan_query_edit_image_task - Query the status of an editing task

Example: Dify Chatflow -- Nana Banana Pro vs Tongyi Wanxiang 2.5

Input Prompt: The headshot of the killer Leo


Why Choose genai-mcp?

  1. Flexible Backend Support: Works with Google Gemini official API, Nano Banana, and other Gemini-compatible third-party backends
  2. Multiple AI Models: Supports various Generative AI models, including Tongyi Wanxiang 2.5 for faster and more cost-effective image generation
  3. Easy Integration: Standard MCP protocol makes it easy to integrate with any MCP-compatible tool
  4. Production Ready: Built with Go for performance and reliability
  5. Open Source: Fully open source and actively maintained

What's Next?

Now that you have your MCP server running, you can:

  • Build custom workflows combining image generation with other tools
  • Create automated content pipelines in n8n or Dify
  • Enhance your development workflow with AI-powered image generation in Cursor
  • Experiment with different backends to find the best balance of speed, cost, and quality
  • Try Tongyi Wanxiang 2.5 for faster and more affordable image generation

Resources


Have questions or run into issues? Drop a comment below or open an issue on GitHub. Happy building! 🚀

Top comments (0)