img-gen-mcp
v0.11.0
Published
Local-first MCP server for image generation, editing, async jobs, workflow tracking, image analysis, local bridges, Streamable HTTP, and web-ready finalization.
Downloads
1,781
Readme
img-gen-mcp
img-gen-mcp is a local-first MCP server for image generation, editing, async jobs, batch runs, background removal, optimization, final asset delivery, and optional ACP-style automation.
It now includes workflow-aware image guidance, persisted workflow state, explicit step tracking, and an optional ACP HTTP surface so iterative image jobs can survive restarts and support full automation flows.
It combines:
- OpenRouter-first image generation
- Kilo Gateway support
- OpenAI and Gemini image generation
- provider auto-selection and model-driven routing
- async task submission and polling
- batch image generation for prompt sweeps and variants
- local image generation through OpenAI-compatible endpoints and local bridges for MLX, ComfyUI, Draw Things, and llama.cpp-compatible servers
- Streamable HTTP transport for remote deployments
- optional ACP-style HTTP automation routes layered on top of MCP
- local background cleanup with
rmbg,imgly, and a shared Docker-backedwithoutbgdaemon - web optimization with
sharp - deterministic prompt enhancement before generation
Features
generate_imagefor OpenRouter-first generation with response normalizationkilo_generate_imagefor Kilo Gateway routing- provider auto-selection through
provider=autoor model-driven inference list_image_modelsfor provider/model discovery with warnings and capability hintsget_provider_statusfor backend readiness and local bootstrap guidanceget_model_capabilitiesfor a compact capability summaryedit_imagefor prompt-driven image editing- local provider support for OpenAI-compatible endpoints and local bridges like MLX, ComfyUI, and Draw Things
submit_taskandget_taskfor async generation workflowsbatch_generate_imagefor running multiple prompts in one requestcreate_workflow,update_workflow,get_workflow, andfinalize_workflowfor iterative interactive jobsadd_workflow_stepandclose_workflow_stepfor explicit workflow lifecycle trackingresume_workflowfor continuing a persisted workflow after restartanalyze_image_resultandsuggest_next_stepfor image-backed follow-up guidanceinspect_cutoutandcompare_variantsfor specialized analysis helpersbackground_removefor local cutouts and the shared local withoutBG daemonresize_imageandauto_cropfor deterministic local transformsoptimize_imagefor web-ready re-encoding and compressionfinalize_imagefor a one-call local workflow that can remove background, trim, crop, and resize- alpha stats and multi-background inspection sheets for post-processing QA
- prompt enhancement before generation
- automatic web optimization after background removal/finalize
- debug mode via
IMAGE_MCP_DEBUG=1
Release Notes
- Workflow records are now persisted to
.image-mcp-workflows.jsonand can be resumed after restart. add_workflow_stepandclose_workflow_stepare available for explicit workflow lifecycle tracking.analyze_image_resultandsuggest_next_stepnow inspect the actual image file for structured guidance.
Asset Workflows
For SVG-style icons, logos, favicons, and game sprites, use the built-in asset workflow guidance in docs/public/asset-workflows.md.
That keeps the repository self-contained for npm/GitHub users without asking them to install extra marketplace skills.
Install
npm install -g img-gen-mcpIf you are running from a local checkout instead of npm, point your MCP client at node /absolute/path/to/img-gen-mcp/server.js rather than npx.
Configuration
Use the correct launch command for your setup:
- Local checkout:
node /absolute/path/to/img-gen-mcp/server.js - Published package:
npx -y img-gen-mcp - HTTP transport:
npx -y img-gen-mcp http
Set these environment variables in your MCP client:
IMAGE_MCP_DEFAULT_PROVIDER- default provider when none is suppliedIMAGE_MCP_DEFAULT_MODEL- default model when none is suppliedIMAGE_MCP_PROJECT_OUTPUT_DIR- optional project-specific output rootIMAGE_MCP_DEFAULT_BG_BACKEND- default local cleanup backend (rmbg,imgly, orwithoutbg)WITHOUTBG_DAEMON_URL- local daemon URL, defaults tohttp://127.0.0.1:8765WITHOUTBG_AUTOSTART=1- auto-start the shared withoutBG Docker daemon on demandIMAGE_MCP_DEFAULT_BG_ALPHA_THRESHOLD- tighter default mask for logos/header assetsIMAGE_MCP_PROMPT_ENHANCE=0- disable deterministic prompt enhancementIMAGE_MCP_DEBUG=1- include detailed tool errors and provider payloads
Local model environment variables:
IMAGE_MCP_LOCAL_PROVIDER- selectsopenai-compatible,comfyui,drawthings, ormlxIMAGE_MCP_LOCAL_ENDPOINT- local HTTP base URLIMAGE_MCP_LOCAL_MODEL- local model slugIMAGE_MCP_LOCAL_AUTOSTART=1- opt-in local service startupIMAGE_MCP_LOCAL_BOOTSTRAP=1- opt-in bootstrap helper modeIMAGE_MCP_LOCAL_TIMEOUT_MS- request timeout for local endpointsIMAGE_MCP_LOCAL_API_KEY- optional local auth token
Transport and runtime flags:
IMAGE_MCP_TRANSPORT=http- opt in to Streamable HTTP transportIMAGE_MCP_HTTP_HOST- host for HTTP transport, defaults to127.0.0.1IMAGE_MCP_HTTP_PORT- port for HTTP transport, defaults to3333IMAGE_MCP_ACP=1- enable the optional ACP-style automation surface on HTTP transportIMAGE_MCP_ACP_PATH- ACP route prefix, defaults to/acp
Example MCP config for a local checkout:
{
"mcp": {
"img-gen-mcp": {
"type": "local",
"command": ["npx", "-y", "img-gen-mcp"],
"enabled": true,
"environment": {
"IMAGE_MCP_DEFAULT_PROVIDER": "openrouter",
"IMAGE_MCP_DEFAULT_MODEL": "openai/gpt-image-1",
"IMAGE_MCP_DEFAULT_BG_BACKEND": "imgly",
"WITHOUTBG_DAEMON_URL": "http://127.0.0.1:8765",
"WITHOUTBG_AUTOSTART": "1"
}
}
}
}Example MCP config for the published package:
{
"mcp": {
"img-gen-mcp": {
"type": "local",
"command": ["npx", "-y", "img-gen-mcp"],
"enabled": true,
"environment": {
"IMAGE_MCP_DEFAULT_PROVIDER": "openrouter",
"IMAGE_MCP_DEFAULT_MODEL": "openai/gpt-image-1",
"IMAGE_MCP_DEFAULT_BG_BACKEND": "imgly",
"WITHOUTBG_DAEMON_URL": "http://127.0.0.1:8765",
"WITHOUTBG_AUTOSTART": "1"
}
}
}
}Local examples:
{
"mcp": {
"img-gen-mcp": {
"type": "local",
"command": ["npx", "-y", "img-gen-mcp"],
"enabled": true,
"environment": {
"IMAGE_MCP_LOCAL_PROVIDER": "mlx",
"IMAGE_MCP_LOCAL_ENDPOINT": "http://127.0.0.1:8000/v1",
"IMAGE_MCP_LOCAL_MODEL": "qwen3.5",
"IMAGE_MCP_LOCAL_AUTOSTART": "1"
}
}
}
}See docs/public/clients.md for ready-to-use examples for Kilo, Cursor, and generic MCP clients.
ACP Automation
img-gen-mcp can expose an optional ACP-style HTTP surface for automation clients that want task and workflow primitives in addition to MCP tools.
Enable it with:
IMAGE_MCP_TRANSPORT=http IMAGE_MCP_ACP=1 npm startRoute overview:
GET /acp/healthGET /acp/agentGET /acp/toolsPOST /acp/tools/:tool_namePOST /acp/tasksGET /acp/tasks/:task_idPOST /acp/tasks/:task_id/cancelPOST /acp/workflowsGET /acp/workflows/:workflow_idPOST /acp/workflows/:workflow_id/stepsPATCH /acp/workflows/:workflow_id/steps/:step_idPOST /acp/workflows/:workflow_id/finalize
The ACP layer reuses the same MCP tool implementations and workflow persistence. MCP remains the primary protocol, and ACP is an opt-in automation layer on top.
The package ships bundled skills under skills/ so other users can reuse the same workflow guidance when they install the package or browse the repository.
Use npm run test:acp to smoke-test the ACP routes locally.
Published Package
The package version is 0.11.0.
After this release is published to GitHub, you can publish to npm manually with:
npm publishIf you want to verify the release artifact first, run:
npm pack --dry-runGuidance
- Use
provider=autowhen you want the server to infer the backend from a model slug. - Use
submit_taskfor long-running generations when your client prefers polling. - Use
batch_generate_imagewhen you want multiple prompt variants without reconfiguring the client. - Use
get_provider_statusbefore troubleshooting a local runtime so you can see the expected endpoint and startup hint. - Use
IMAGE_MCP_LOCAL_BOOTSTRAP=1when you want the server to print setup guidance for the configured local adapter. - Use the workflow tools when you want the server to return a workflow ID and suggested next steps instead of stopping after one tool call.
- Run the workflow persistence regression test with
npm run test:workflow.
Workflow tools:
create_workflowupdate_workflowget_workflowresume_workflowfinalize_workflowanalyze_image_resultinspect_cutoutcompare_variantssuggest_next_step
App Model Access
img-gen-mcp cannot automatically use the image models built into Cursor, Claude Code, or Codex.
It can only use a model source that is exposed to it as a separate provider or local HTTP endpoint.
| Client | Use built-in app image models directly? | What works |
|---|---|---|
| Cursor | No | Point IMAGE_MCP_LOCAL_ENDPOINT at a local image server or bridge |
| Claude Code | No | Point IMAGE_MCP_LOCAL_ENDPOINT at a local image server or bridge |
| Codex | No | Point IMAGE_MCP_LOCAL_ENDPOINT at a local image server or bridge |
| MLX / local server | Yes, if exposed as an endpoint | Set IMAGE_MCP_LOCAL_PROVIDER=mlx or openai-compatible |
If you want a zero-cloud setup, use a local backend such as MLX-VLM on macOS or an OpenAI-compatible local server like llama.cpp, LM Studio, ComfyUI, or a Draw Things bridge.
For local adapters, the package supports explicit input_mode, input_image, and reference_image flows so image-to-image and edit workflows can pass files or URLs directly.
Workflow
The typical pipeline is:
- Generate an image
- Remove background if needed
- Inspect the cutout on multiple backgrounds
- Optimize the final asset for the web
- Save and ship the final PNG/WebP/JPEG/AVIF
For complex generation work, prefer a model-first flow: pick a model, let provider=auto resolve the backend, then use async polling or batch generation if your client needs better control.
Common Uses
- logos
- icons
- header artwork
- product photography
- realistic subject cutouts
- transparent PNG delivery
Models
Supported OpenRouter image models include:
microsoft/mai-image-2.5openai/gpt-image-1openai/gpt-5-image-miniopenai/gpt-5.4-image-2x-ai/grok-imagine-image-qualitygoogle/gemini-2.5-flash-imagegoogle/gemini-2.5-flash-image-previewgoogle/gemini-3-pro-image-previewsourceful/riverflow-v2.5-fastsourceful/riverflow-v2.5-prosourceful/riverflow-v2.5-fast:freesourceful/riverflow-v2-fastsourceful/riverflow-v2-prorecraft/recraft-v4.1-utilityrecraft/recraft-v4.1-vectorrecraft/recraft-v4.1-utility-prorecraft/recraft-v4.1-pro-vectorrecraft/recraft-v3black-forest-labs/flux.2-problack-forest-labs/flux.2-flex
Recommended defaults:
- Photorealistic work:
microsoft/mai-image-2.5oropenai/gpt-image-1 - Quick stylized work:
x-ai/grok-imagine-image-quality - Logos / vector-like work:
recraft/recraft-v4.1-vector - Broad prompt-following general use:
sourceful/riverflow-v2.5-pro
Local backends
openai-compatiblefor any/v1-style local servermlxfor macOS local model wrapperscomfyuifor workflow-driven generationdrawthingsfor a running macOS app bridgellama.cppfor a lightweight local OpenAI-compatible endpoint
Background Removal Backends
rmbg- fastest lightweight local cleanupimgly- higher-quality local cleanupwithoutbg- shared Docker-backed local daemon for harder edges, fur, and transparent cutouts
Start the shared daemon once:
docker compose -f withoutbg-daemon/docker-compose.yml up -dIf WITHOUTBG_AUTOSTART=1 is set, the MCP will try to start it automatically when backend=withoutbg is used.
Web Optimization
background_remove and finalize_image automatically run a web optimization pass after cleanup.
Use optimize_image directly when you want explicit control:
- PNG for transparent cutouts
- WebP for opaque assets
- JPEG for flattened web images
- AVIF for aggressive compression
Docs
- Public docs live in
docs/public/ - Wiki-ready pages live in
docs/wiki/ - Migration notes and setup details are documented there for public release
- The
list_image_models,get_provider_status, andget_model_capabilitiestools are documented there as part of the release-facing API surface
Troubleshooting
- If
withoutbgis not running, enableWITHOUTBG_AUTOSTART=1or start the daemon manually. - If the model list looks wrong, set
IMAGE_MCP_DEFAULT_MODELexplicitly. - If image generation fails with provider-specific errors, verify the provider API key in your MCP environment.
- If you need the raw response details, set
IMAGE_MCP_DEBUG=1.
