by joenorton
lightweight Python-based MCP (Model Context Protocol) server for local ComfyUI
# Add to your Claude Code skills
git clone https://github.com/joenorton/comfyui-mcp-serverGenerate and refine AI images/audio/video through natural conversation
A lightweight MCP (Model Context Protocol) server that lets AI agents generate and iteratively refine images, audio, and video using a local ComfyUI instance.
You run the server, connect a client, and issue tool calls. Everything else is optional depth.
This proves everything is working.
git clone https://github.com/joenorton/comfyui-mcp-server.git
cd comfyui-mcp-server
pip install -r requirements.txt
Make sure ComfyUI is installed and running locally.
cd <ComfyUI_dir>
python main.py --port 8188
From the repository directory:
python server.py
The server listens at:
http://127.0.0.1:9000/mcp
Run the included test client:
# Use default prompt
python test_client.py
# Or provide your own prompt
python test_client.py -p "a beautiful sunset over mountains"
python test_client.py --prompt "a cat on a mat"
test_client.py will:
generate_image with your prompt (or a default)If this step succeeds, the system is working.
Note: The test client respects server defaults configured via config files, environment variables, or set_defaults calls. Only the prompt parameter is required; all other parameters use server defaults automatically.
That’s it.
Once the server is running, you can connect it to an AI client.
Create a project-scoped .mcp.json file:
{
"mcpServers": {
"comfyui-mcp-server": {
"type": "streamable-http",
"url": "http://127.0.0.1:9000/mcp"
}
}
}
Note: Some clients use "type": "http" instead of "streamable-http". Both work with this server. If auto-discovery doesn't work, try changing the type field.
Restart your AI client. You can now call tools such as:
generate_imageview_imageregenerateget_joblist_assetsThis is the primary intended usage mode.
Once you’ve confirmed the server runs and a client can connect, the system supports:
regenerate (no re-prompting)view_image)Everything below builds on the same basic loop you just tested.
If you’ve used earlier versions of this project, a few things have changed.
workflows/ directoryget_job, get_queue_status, cancel_job)regenerate (replay with parameter overrides)view_imageEarlier versions were a thin request/response bridge. The current version is built around iteration and stateful control loops.
You can still generate an image with a single call, but you now have the option to:
If you want the minimal, single-shot behavior from earlier versions:
test_client.py (this mirrors the original usage pattern)generate_image with just a prompt (server defaults handle the rest)No migration is required unless you want the new capabilities.
generate_image: Generate images (requires prompt)generate_song: Generate audio (requires tags and lyrics)regenerate: Regenerate an existing asset with optional parameter overrides (requires asset_id)view_image: View generated images inline (images only, not audio/video)get_queue_status: Check ComfyUI queue state (running/pending jobs) - provides async awarenessget_job: Poll job completion status by prompt_id - check if a job has finishedlist_assets: Browse recently generated assets - enables AI memory and iterationget_asset_metadata: Get full provenance and parameters for an asset - includes workflow historycancel_job: Cancel a queued or running joblist_models: List available ComfyUI modelsget_defaults: Get current default valuesset_defaults: Set default values (with optional persistence)list_workflows: List all available workflowsrun_workflow: Run any workflow with custom parametersget_publish_info: Show publish status (detected project root, publish dir, ComfyUI output root, and any missing setup)set_comfyui_output_root: Set ComfyUI output directory (recommended for Comfy Desktop / nonstandard installs; persisted across restarts)publish_asset: Publish a generated asset into the project's web directory with deterministic compression (default 600KB)Publish Notes:
asset_ids are valid only for the current server session; restart invalidates them.public/gen, static/gen, or assets/gen); if ComfyUI output can't be detected, set it once via set_comfyui_output_root.manifest_key is required.manifest_key is provided.Quick Start:
Example agent conversation flow:
User: "Generate a hero image for my website and publish it as hero.webp"
Agent: Checks publish configuration
get_publish_info() → sees status "ready"Agent: Generates image
generate_image(prompt="a hero image for a website") → gets asset_idAgent: Publishes asset
publish_asset(asset_id="...", target_filename="hero.webp") → successUser: "Now generate a logo and add it to the manifest as 'site-logo'"
Agent: Generates and publishes with manifest
generate_image(prompt="a modern logo") → gets asset_idpublish_asset(asset_id="...", manifest_key="site-logo") → auto-generates filename, updates manifestSee docs/HOW_TO_TEST_PUBLISH.md for detailed usage and testing instructions.
Add custom workflows by placing JSON files in the workflows/ directory. Workflows are automatically discovered and exposed as MCP tools.
Use PARAM_* placeholders in workflow JSON to expose parameters:
PARAM_PROMPT → prompt: str (required)PARAM_INT_STEPS → steps: int (optional)PARAM_FLOAT_CFG → cfg: float (optional)Example:
{
"3": {
"inputs": {
"text": "PARAM_PROMPT",
"steps": "PARAM_INT_STEPS"
}
}
}
The tool name is derived from the filename (e.g., my_workflow.json → my_workflow tool).
The server supports configurable defaults to avoid repeating common parameters. Defaults can be set via:
set_defaults tool (ephemeral, lost on restart)~/.config/comfy-mcp/config.json (persistent)COMFY_MCP_DEFAULT_* prefixed variablesDefaults are resolved in priority order: per-call values → runtime defaults → config file → environment variables → hardcoded defaults.
For complete configuration details, see docs/REFERENCE.md.
Complete parameter lists, return schemas, configuration options, and advanced workflow metadata are documented in:
comfyui-mcp-server/
├── server.py # Main entry point
├── comfyui_client.py # ComfyUI API client
├── asset_processor.py # Image processing utilities
├── test_client.py # Test client
├── managers/ # Core managers
│ ├── workflow_manager.py
│ ├── defaults_manager.py
│ └── asset_registry.py
├── tools/ # MCP tool implementations
│ ├── generation.py
│ ├── asset.py
│ ├── job.py # Job management tools
│ ├── configuration.py
│ └── workflow.py
├── models/ # Data models
│ ├── workflow.py
│ └── asset.py
└── workflows/ # Workflow JSON files
├── generate_image.json
└── generate_song.json
<ComfyUI_dir>/models/checkpoints/No comments yet. Be the first to share your thoughts!