GenImgMCP
# GenImgMCP ๐จ
Local **MCP (Model Context Protocol)** server for image generation and editing using the `google/gemini-3.1-flash-image` model via **OpenRouter**.
Designed specifically for **coding agents** (such as Antigravity, Claude Code, Cursor, and other MCP clients), saving images directly to the project's local file system and returning the file path and structured metadata in a lightweight manner (without cluttering the context window with Base64 strings).
---
## โจ Features
- ๐ผ๏ธ **Image Generation (`generate_image`)**: Create images from detailed text prompts.
- ๐๏ธ **Image Editing and Variations (`edit_image`)**: Transform, refine, or add elements to existing images on disk.
- ๐พ **Automatic Local Saving**: Saves image files directly to the project directory requested by the agent (or in `./generated_images/`).
- โก **Lightweight & Efficient Response**: Returns only the absolute file path and metadata (size, format, aspect ratio), preserving the caller LLM's context tokens.
- ๐ **Aspect Ratio & Format Control**: Supports multiple aspect ratios (`1:1`, `16:9`, `9:16`, `4:3`, `3:4`, `3:2`, `2:3`, `21:9`) and file formats (`png`, `webp`, `jpeg`).
- ๐ **Model Flexibility**: Defaults to `google/gemini-3.1-flash-image`, with support for any multimodal model available on OpenRouter.
---
## ๐ Installation and Build
### 1. Prerequisites
- Node.js 18 or higher
- [OpenRouter](https://openrouter.ai/keys) API Key
### 2. Install Dependencies and Build
```bash
# In the project root:
npm install
npm run build
```
---
## โ๏ธ Configuration
You can configure the API key in one of three ways:
1. **Environment Variable**: Set `OPENROUTER_API_KEY` in your environment.
2. **`.env` File**: Create a `.env` file in the root of the project:
```env
OPENROUTER_API_KEY=sk-or-v1-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
DEFAULT_IMAGE_MODEL=google/gemini-3.1-flash-image
DEFAULT_OUTPUT_DIR=./generated_images
```
3. **Command Line Argument**: Pass `--api-key <your_key>` in arguments when starting the server.
---
## ๐ ๏ธ Available Tools
### 1. `generate_image`
Generates a new image based on a text prompt.
| Parameter | Type | Required | Description |
| :--- | :--- | :---: | :--- |
| `prompt` | `string` | **Yes** | Detailed description of the image to generate. |
| `output_path` | `string` | No | File path where the image will be saved (e.g., `./assets/banner.png`). |
| `aspect_ratio` | `string` | No | Aspect ratio of the image (`1:1`, `16:9`, `9:16`, `4:3`, `3:4`, `3:2`, `2:3`, `21:9`). Default: `1:1`. |
| `output_format`| `string` | No | File format (`png`, `webp`, `jpeg`). Default: `png`. |
| `model` | `string` | No | Model on OpenRouter (Default: `google/gemini-3.1-flash-image`). |
### 2. `edit_image`
Modifies an existing image provided by local file path.
| Parameter | Type | Required | Description |
| :--- | :--- | :---: | :--- |
| `image_path` | `string` | **Yes** | Source image path (e.g., `./assets/logo.png`) or Data URL. |
| `prompt` | `string` | **Yes** | Modification instructions or elements to add. |
| `output_path` | `string` | No | Destination path for the edited image. |
| `aspect_ratio` | `string` | No | Desired aspect ratio for the resulting image. |
| `output_format`| `string` | No | Output file format (`png`, `webp`, `jpeg`). |
| `model` | `string` | No | Model on OpenRouter (Default: `google/gemini-3.1-flash-image`). |
---
## ๐ How to Integrate with MCP Clients
### Configuration in Claude Desktop (`claude_desktop_config.json`)
```json
{
"mcpServers": {
"genimg": {
"command": "node",
"args": [
"D:/MyProjs.Github/GenImgMCP/dist/index.js"
],
"env": {
"OPENROUTER_API_KEY": "sk-or-v1-your-key-here"
}
}
}
}
```
### Configuration in Antigravity / Cursor / MCP Config (`mcp_config.json`)
```json
{
"mcpServers": {
"genimg": {
"command": "node",
"args": [
"D:/MyProjs.Github/GenImgMCP/dist/index.js"
],
"env": {
"OPENROUTER_API_KEY": "sk-or-v1-your-key-here"
}
}
}
}
```
---
## ๐งช Testing the Server Locally
You can run the server directly in the terminal to verify startup:
```bash
node dist/index.js
```
*The server will start and wait for JSON-RPC messages on the stdio channel.*
---
## ๐ License
MIT
TDQS
Scored across 2 tools
generate_image and edit_image have clearly distinct purposes: one creates new images from a prompt, while the other transforms an existing local image. There is no meaningful overlap or ambiguity between the two tools.
Both tools follow a consistent verb_noun pattern: generate_image and edit_image. The naming is predictable, clear, and uniform.
Two tools is on the thin side for an image generation/editing server, even though both are core operations. The count is borderline but not unreasonable for a minimal focused toolset.
The server covers the two primary image operations: generation and editing. It lacks supporting operations like listing locally saved images or deleting them, but these are minor gaps that agents can work around using file paths.