
Gemini Image Generator
STDIOGenerate high-quality images from text prompts using Google's Gemini model
Generate high-quality images from text prompts using Google's Gemini model
Generate high-quality images from text prompts using Google's Gemini model through the MCP protocol.
This MCP server allows any AI assistant to generate images using Google's Gemini AI model. The server handles prompt engineering, text-to-image conversion, filename generation, and local image storage, making it easy to create and manage AI-generated images through any MCP client.
The server provides the following MCP tools for AI assistants:
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 generateReturns:
This dual return format allows AI assistants to either work with the image data directly or reference the saved file path.
Examples:
This image was generated using the prompt:
"Hi, can you create a 3d rendered image of a pig with wings and a top hat flying over a happy futuristic scifi city with lots of greenery?"
A 3D rendered pig with wings and a top hat flying over a futuristic sci-fi city filled with greenery
When using this MCP server with Claude Desktop Host:
Performance Issues: Using transform_image_from_encoded
may take significantly longer to process compared to other methods. This is due to the overhead of transferring large base64-encoded image data through the MCP protocol.
Path Resolution Problems: There may be issues with correctly resolving image paths when using Claude Desktop Host. The host application might not properly interpret the returned file paths, making it difficult to access the generated images.
For the best experience, consider using alternative MCP clients or the transform_image_from_file
method when possible.
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 imageReturns:
Example:
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 transformedprompt
: Text description of how you want to transform the imageReturns:
Examples:
Using the flying pig image created above, we applied a transformation with the following prompt:
"Add a cute baby whale flying alongside the pig"
Before:
After:
The original flying pig image with a cute baby whale added flying alongside it
To install Gemini Image Generator MCP for Claude Desktop automatically via Smithery:
npx -y @smithery/cli install @qhdrl12/mcp-server-gemini-image-gen --client claude
git clone https://github.com/your-username/mcp-server-gemini-image-generator.git cd mcp-server-gemini-image-generator
# Using uv (recommended) uv venv source .venv/bin/activate # On Windows: .venv\Scripts\activate uv pip install -e . # Or using regular venv python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate pip install -e .
Method A: Using .env file (optional)
# Create .env file in the project root cat > .env << 'EOF' GEMINI_API_KEY=your-gemini-api-key-here OUTPUT_IMAGE_PATH=/path/to/save/images EOF
Method B: Set directly in Claude Desktop config (recommended)
claude_desktop_config.json
(shown in configuration section below)Add the following to your claude_desktop_config.json
:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
{ "mcpServers": { "gemini-image-generator": { "command": "uv", "args": [ "--directory", "/absolute/path/to/mcp-server-gemini-image-generator", "run", "mcp-server-gemini-image-generator" ], "env": { "GEMINI_API_KEY": "your-actual-gemini-api-key-here", "OUTPUT_IMAGE_PATH": "/absolute/path/to/your/images/directory" } } } }
Important Configuration Notes:
Replace paths with your actual paths:
/absolute/path/to/mcp-server-gemini-image-generator
to the actual location where you cloned this repository/absolute/path/to/your/images/directory
to where you want generated images to be savedEnvironment Variables:
your-actual-gemini-api-key-here
with your real Gemini API key from Google AI StudioOUTPUT_IMAGE_PATH
to ensure images are saved correctlyExample with real paths:
{ "mcpServers": { "gemini-image-generator": { "command": "uv", "args": [ "--directory", "/Users/username/Projects/mcp-server-gemini-image-generator", "run", "mcp-server-gemini-image-generator" ], "env": { "GEMINI_API_KEY": "GEMINI_API_KEY", "OUTPUT_IMAGE_PATH": "OUTPUT_IMAGE_PATH" } } } }
Once installed and configured, you can ask Claude to generate or transform images using prompts like:
The generated/transformed images will be saved to your configured output path and displayed in Claude. With the updated return types, AI assistants can also work directly with the image data without needing to access the saved files.
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 MCP Inspector provides a convenient web interface where you can directly test the image generation tool without needing to use Claude or another MCP client. You can enter text prompts, execute the tool, and see the results immediately, which is helpful for development and debugging.
MIT License