This MCP server enables AI assistants to generate high-quality images using Google's Gemini model. Through the Model Context Protocol (MCP), it handles text-to-image conversion, image transformation, and provides both the image data and file storage path for seamless integration with AI assistants.
Before installing the Gemini Image Generator MCP server, you'll need:
To install 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
as shown belowAdd 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:
{
"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"
}
}
}
}
The server provides three main tools for generating and transforming images:
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:
Example prompts:
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 headerprompt
: Text description of how you want to transform the imageExample prompts:
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 imageExample prompts:
Once installed and configured, you can ask Claude to generate or transform images using natural language prompts:
The generated/transformed images will be saved to your configured output path and displayed in Claude. The dual return format allows AI assistants to either work with the image data directly or reference the saved file path.
You can test the application using the FastMCP development server:
fastmcp dev server.py
This starts a local development server with the MCP Inspector available at http://localhost:5173/. The web interface lets you test the image generation tools directly without needing Claude or another MCP client.
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "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"}}'
See the official Claude Code MCP documentation for more details.
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.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"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"
}
}
}
}
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.
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 explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"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"
}
}
}
}
3. Restart Claude Desktop for the changes to take effect