mcp-duojie-image
v0.5.0
Published
MCP server for image generation via duojie.games
Maintainers
Readme
mcp-duojie-image
MCP server for image generation via duojie.games API (Gemini Flash Image).
Features
- Text-to-image generation — generate images from prompts with configurable size and aspect ratio
- Reference image support — provide local image files as visual references (auto-compressed to 1024px long-side)
- Async mode — for long-running generations (especially with reference images), use
async_mode: trueto get atask_idimmediately and poll for completion; prevents MCP client timeout - Sync mode — for simple text-to-image generation without reference images, the default sync mode returns the result directly
- File saving — automatic output directory creation, conflict handling (
overwriteflag, auto-incrementing filename suffix) - Configurable output — size (512px/1K/2K/4K), aspect ratio, format
Installation
npx mcp-duojie-imageOr with a specific version:
npx [email protected]Configuration
Set the DUOJIE_API_KEY environment variable:
export DUOJIE_API_KEY=sk-your-key-hereOr configure in your MCP client (e.g., Claude Desktop, Factory):
{
"mcpServers": {
"duojie-image": {
"command": "node",
"args": ["/path/to/mcp-duojie-image/dist/index.js"],
"env": {
"DUOJIE_API_KEY": "sk-your-key-here"
}
}
}
}Optional environment variables:
| Variable | Default | Description |
|----------|---------|-------------|
| DUOJIE_API_KEY | (required) | API key |
| DUOJIE_BASE_URL | https://api.duojie.ai/v1 | API endpoint |
| DUOJIE_MODEL | gemini-2.0-flash-exp-image-generation | Model to use |
Tools
generate_image
Generate an image and save it to disk.
Required parameters:
prompt(string) — Image descriptionoutput_dir(string) — Output directory (absolute path)output_filename(string) — Output filename (no extension needed)
Optional parameters:
reference_images(string[]) — Local image paths for reference. Images are auto-compressed to max 1024px long-side before sending to API.size("512px" | "1K" | "2K" | "4K") — Output image size. Default:1Kaspect_ratio(string) — e.g.,"16:9","1:1"format(string) — Output format. Default:"png"model(string) — Model overrideoverwrite(boolean) — Overwrite existing file. Default:false(auto-increments filename)negative_prompt(string) — What to avoid in the imageasync_mode(boolean) — Whentrue, returnstask_idimmediately and generates in background. Recommended when usingreference_imagesto avoid MCP client timeout. Default:false
Response (sync mode):
{ "success": true, "saved_path": "/absolute/path/to/image.png", "model": "gemini-..." }Response (async mode):
{ "task_id": "uuid", "status": "pending" }check_image_task
Check the status of an async image generation task.
Required parameters:
task_id(string) — Task ID returned bygenerate_imagewithasync_mode: true
Polling workflow:
- Call
generate_imagewithasync_mode: true→ gettask_id - Call
check_image_taskwithtask_idevery few seconds - When
statusis"done", retrievesaved_pathfrom the response - If
statusis"failed", checkerrorandmessagefields
Response:
{ "task_id": "uuid", "status": "done", "saved_path": "/path/to/image.png", "model": "gemini-..." }Usage Examples
Simple text-to-image (sync)
generate_image(
prompt="A sunset over the ocean, photorealistic",
output_dir="/tmp/images",
output_filename="sunset"
)With reference image (use async_mode to avoid timeout)
generate_image(
prompt="Same style as reference, but with mountains instead",
reference_images=["/path/to/reference.png"],
output_dir="/tmp/images",
output_filename="mountain_scene",
async_mode=true
)
→ { "task_id": "abc-123", "status": "pending" }
check_image_task(task_id="abc-123")
→ { "status": "running" } # poll again
check_image_task(task_id="abc-123")
→ { "status": "done", "saved_path": "/tmp/images/mountain_scene.png" }Development
# Install dependencies
npm install
# Build
npm run build
# Run tests
npm test
# Type check / lint
npm run lintArchitecture
src/
index.ts — MCP server, tool registration (generate_image, check_image_task)
provider.ts — HTTP client for image generation API
resizer.ts — Reference image compression (jimp, max 1024px long-side)
task-queue.ts — In-memory async task state machine (pending→running→done/failed, 30min TTL)
config.ts — Environment variable loading
saver.ts — File saving with conflict handling
errors.ts — Error codes (E_CONFIG_MISSING_KEY, E_PROVIDER_AUTH, etc.)License
MIT
