Gemini Image Generator MCP server

Enables AI image generation using Google's Gemini 2.0 Flash model with intelligent prompt engineering, automatic filename creation, and configurable local storage.
Back to servers
Provider
qhdrl12
Release date
Mar 24, 2025
Language
Python
Stats
5 stars

This MCP server lets you generate and transform images using Google's Gemini model through a simple interface that works with any MCP client. It handles text-to-image conversion, intelligent filename creation, and local image storage automatically.

Features

  • Text-to-image generation using Gemini 2.0 Flash
  • Image-to-image transformation with text prompts
  • Support for both file-based and base64-encoded images
  • Automatic intelligent filename generation
  • Automatic translation of non-English prompts
  • Local image storage with configurable path

Setup

Prerequisites

  • Python 3.11+
  • Google AI API key (Gemini)
  • MCP host application (Claude Desktop App, Cursor, or other MCP-compatible clients)

Getting a Gemini API Key

  1. Visit Google AI Studio API Keys page
  2. Sign in with your Google account
  3. Click "Create API Key"
  4. Copy your new API key for use in the configuration
  5. Note: The API key provides a certain quota of free usage per month

Installation

  1. Clone the repository:

    git clone https://github.com/your-username/gemini-image-generator.git
    cd gemini-image-generator
    
  2. Create a virtual environment and install dependencies:

    # Using regular venv
    python -m venv .venv
    source .venv/bin/activate
    pip install -e .
    
    # Or using uv
    uv venv
    source .venv/bin/activate
    uv pip install -e .
    
  3. Copy the example environment file and add your API key:

    cp .env.example .env
    
  4. Edit the .env file to include your Google Gemini API key and preferred output path:

    GEMINI_API_KEY="your-gemini-api-key-here"
    OUTPUT_IMAGE_PATH="/path/to/save/images"
    

Configure Claude Desktop

Add the following to your claude_desktop_config.json:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
{
    "mcpServers": {
        "gemini-image-generator": {
            "command": "uv",
            "args": [
                "--directory",
                "/absolute/path/to/gemini-image-generator",
                "run",
                "server.py"
            ],
            "env": {
                "GEMINI_API_KEY": "GEMINI_API_KEY",
                "OUTPUT_IMAGE_PATH": "OUTPUT_IMAGE_PATH"
            }
        }
    }
}

Usage

Once installed and configured, you can ask Claude to generate or transform images using prompts.

Available MCP Tools

Tool 1: generate_image_from_text

Creates a new image from a text prompt description.

generate_image_from_text(prompt: str) -> Tuple[bytes, str]

Parameters:

  • prompt: Text description of the image you want to generate

Returns:

  • A tuple containing:
    • Raw image data (bytes)
    • Path to the saved image file (str)

Example prompts:

  • "Generate an image of a sunset over mountains"
  • "Create a photorealistic flying pig in a sci-fi city"

Tool 2: transform_image_from_encoded

Transforms an existing image based on a text prompt using base64-encoded image data.

transform_image_from_encoded(encoded_image: str, prompt: str) -> Tuple[bytes, str]

Parameters:

  • encoded_image: Base64 encoded image data with format header (must be in format: "data:image/[format];base64,[data]")
  • prompt: Text description of how you want to transform the image

Returns:

  • A tuple containing:
    • Raw transformed image data (bytes)
    • Path to the saved transformed image file (str)

Example prompts:

  • "Add snow to this landscape"
  • "Change the background to a beach"

Tool 3: transform_image_from_file

Transforms an existing image file based on a text prompt.

transform_image_from_file(image_file_path: str, prompt: str) -> Tuple[bytes, str]

Parameters:

  • image_file_path: Path to the image file to be transformed
  • prompt: Text description of how you want to transform the image

Returns:

  • A tuple containing:
    • Raw transformed image data (bytes)
    • Path to the saved transformed image file (str)

Example prompts:

  • "Add a llama next to the person in this image"
  • "Make this daytime scene look like night time"

Example Usage in Claude

To generate a new image:

  • "Generate an image of a sunset over mountains"
  • "Create an illustration of a futuristic cityscape"
  • "Make a picture of a cat wearing sunglasses"

To transform existing images:

  • "Transform this image by adding snow to the scene"
  • "Edit this photo to make it look like it was taken at night"
  • "Add a dragon flying in the background of this picture"

The generated/transformed images will be saved to your configured output path and displayed in Claude.

Testing

You can test the application by running the FastMCP development server:

fastmcp dev server.py

This command starts a local development server and makes the MCP Inspector available at http://localhost:5173/. The inspector provides a web interface where you can test the image generation tools without needing to use Claude or another MCP client.

Known Issues

When using this MCP server with Claude Desktop Host:

  1. Performance Issues: Using transform_image_from_encoded may take significantly longer to process compared to other methods due to the overhead of transferring large base64-encoded image data.

  2. Path Resolution Problems: There may be issues with correctly resolving image paths when using Claude Desktop Host.

For the best experience, consider using alternative MCP clients or the transform_image_from_file method when possible.

How to add this MCP server to Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "cursor-rules-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "cursor-rules-mcp"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later