A FastMCP HTTP server that generates and edits images using the Google Gemini image model.
Generating an image — Claude calls generate_image and the result renders inline:
Editing an image — following up with edit_image to reformat for Instagram:
| File / Directory | Purpose |
|---|---|
image_gen_mcp/ |
The MCP server package |
image_gen_mcp/config.py |
Environment variable configuration and validation |
image_gen_mcp/types.py |
AspectRatio and Resolution type aliases |
image_gen_mcp/ui.py |
Prefab UI CSP patching for inline image rendering |
image_gen_mcp/client.py |
Google GenAI client initialization |
image_gen_mcp/image_utils.py |
Image loading, saving, and result-collection helpers |
image_gen_mcp/tools.py |
MCP tool definitions (generate_image, edit_image) |
image_gen_mcp/server.py |
Transport entry point (stdio / HTTP) |
pyproject.toml |
Package metadata and entry point |
requirements.txt |
Python dependencies |
From GitHub (recommended):
pip install git+https://github.com/AByteCoder/Image-Gen-MCP.gitFrom a local clone:
pip install /path/to/image-gen-mcpOr in editable mode for development:
pip install -e /path/to/image-gen-mcpFrom requirements only:
pip install -r requirements.txtOption A — Gemini API key
- Go to Google AI Studio and sign in.
- Click Get a Gemini API key and create a new key (or copy an existing one).
- Store the key somewhere safe; you will pass it as
GEMINI_API_KEY.
Option B — Google service account (Vertex AI)
- In the Google Cloud Console, open the project you want to use and enable the Vertex AI API.
- Navigate to IAM & Admin → Service Accounts and click Create service account.
- Fill in a name, then on the Grant access step assign the Vertex AI User role (
roles/aiplatform.user). - After creating the account, open it, go to the Keys tab, click Add Key → Create new key, and choose JSON.
- Download the JSON file; you will pass its path as
GOOGLE_SERVICE_ACCOUNT_FILE.
| Variable | Required | Default | Description |
|---|---|---|---|
GEMINI_API_KEY |
Yes (or service account) | — | Your Google Gemini API key |
GOOGLE_SERVICE_ACCOUNT_FILE |
Yes (or API key) | — | Path to a Google service account JSON key file (alternative to API key) |
GOOGLE_VERTEX_LOCATION |
No | global |
Vertex AI location; only used when authenticating via service account |
IMAGE_OUTPUT_DIR |
No | ./images |
Directory where generated/edited images are saved |
IMAGE_MODEL |
No | gemini-3.1-flash-image-preview |
Gemini model to use for image generation |
HOST |
No | 0.0.0.0 |
Bind address for the HTTP server |
PORT |
No | 56789 |
Listen port for the HTTP server |
MCP_TRANSPORT |
No | http |
Default transport when --transport flag is absent: stdio or http |
BASE_URL |
No | http://localhost:{PORT} |
Public base URL used to construct image URLs returned to the LLM |
MCP_PATH |
No | /mcp |
Mount path for the MCP endpoint |
Either GEMINI_API_KEY or GOOGLE_SERVICE_ACCOUNT_FILE must be set; the server will raise an error on startup if neither is present.
API key auth:
export GEMINI_API_KEY=your_api_key_here
export IMAGE_OUTPUT_DIR=/path/to/your/images # optionalService account auth (Vertex AI):
export GOOGLE_SERVICE_ACCOUNT_FILE=/path/to/service_account_key.json
export GOOGLE_VERTEX_LOCATION=us-central1 # optional, defaults to globalstdio transport (default — for MCP hosts that manage the process):
image-gen-mcp --transport stdioHTTP transport (for persistent or remote MCP hosts):
image-gen-mcp --transport httpOr using the Python module directly:
python -m image_gen_mcp --transport stdio
python -m image_gen_mcp --transport httpThe server supports two transports. Choose the one your MCP host requires.
HTTP transport — add to your MCP host config (e.g. Claude Desktop config.json):
{
"mcpServers": {
"image-gen-mcp": {
"type": "http",
"url": "http://localhost:56789/mcp"
}
}
}Adjust url if you changed HOST, PORT, or MCP_PATH.
stdio transport — add to your MCP host config:
{
"mcpServers": {
"image-gen-mcp": {
"type": "stdio",
"command": "image-gen-mcp",
"args": ["--transport", "stdio"],
"env": {
"GEMINI_API_KEY": "your_api_key_here"
}
}
}
}Generate a new image from a text prompt.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
prompt |
string | Yes | — | Text description of the image to generate |
filename_prefix |
string | No | generated |
Prefix for the saved filename |
aspect_ratio |
string | No | — | Output aspect ratio (see values below) |
resolution |
string | No | 1K |
Output resolution: 512px, 1K, 2K, 4K |
Edit one or more existing images using a text prompt.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
image_path |
list[string] | Yes | — | Absolute file paths or HTTP(S) URLs to the source image(s) |
prompt |
string | Yes | — | Text description of the desired edits |
filename_prefix |
string | No | edited |
Prefix for the saved filename |
aspect_ratio |
string | No | — | Output aspect ratio (see values below) |
resolution |
string | No | 1K |
Output resolution: 512px, 1K, 2K, 4K |
1:1, 1:4, 1:8, 2:3, 3:2, 3:4, 4:1, 4:3, 4:5, 5:4, 8:1, 9:16, 16:9, 21:9
- Images are saved as PNG with a timestamp suffix, e.g.
generated_20260307_143022.png. - The model defaults to
gemini-3.1-flash-image-preview. Override it with theIMAGE_MODELenv variable. - Each tool response includes an absolute
file_pathand aurlpointing to the served image. - Generated images are served as static files at
{BASE_URL}/images/<filename>. - A
/healthendpoint is available for liveness checks. - Multiple images passed to
edit_imageare composited or used as references within a single generation request.

