ComfyUI MCP Server
Enables AI agents to generate and iteratively refine images, audio, and video by interacting with a local ComfyUI instance through natural conversation. It provides comprehensive tools for workflow management, node introspection, and publishing generated assets.
README
ComfyUI MCP Server
Generate 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.
Quick Start (2–3 minutes)
This proves everything is working.
1) Clone and set up
git clone https://github.com/joenorton/comfyui-mcp-server.git
cd comfyui-mcp-server
uv sync
2) Start ComfyUI
Make sure ComfyUI is installed and running locally.
cd <ComfyUI_dir>
python main.py --port 8188
3) Run the MCP server
From the repository directory:
python server.py
The server listens at:
http://127.0.0.1:9000/mcp
4) Verify it works (no AI client required)
Run the included test client:
# Use default prompt
python tests/clients/test_client.py
# Or provide your own prompt
python tests/clients/test_client.py -p "a beautiful sunset over mountains"
python tests/clients/test_client.py --prompt "a cat on a mat"
test_client.py will:
- connect to the MCP server
- list available tools
- fetch and display server defaults (width, height, steps, model, etc.)
- run
generate_imagewith your prompt (or a default) - automatically use server defaults for all other parameters
- print the resulting asset information
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.
Use with an AI Agent (Cursor / Claude / n8n)
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 for WSL Users: If you are running Cursor on Windows and the server inside WSL, use the streamable-http method above with the server running in your WSL terminal. Alternatively, for stdio mode, use wsl as the command:
"comfyui": {
"type": "stdio",
"command": "wsl",
"args": [
"env",
"PYTHONPATH=/path/to/your/src",
"/home/user/.local/bin/uv",
"--directory",
"/path/to/your/project",
"run",
"server.py",
"--stdio"
]
}
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_assets
This is the primary intended usage mode.
What You Can Do After It Works
Once you’ve confirmed the server runs and a client can connect, the system supports:
- Iterative refinement via
regenerate(no re-prompting) - Explicit asset identity for reliable follow-ups
- Job polling and cancellation for long-running generations
- Optional image injection into the AI’s context (
view_image) - Auto-discovered ComfyUI workflows with parameter exposure
- Configurable defaults to avoid repeating common settings
Everything below builds on the same basic loop you just tested.
Migration Notes (Previous Versions)
If you’ve used earlier versions of this project, a few things have changed.
What’s the Same
- You still run a local MCP server that delegates execution to ComfyUI
- Workflows are still JSON files placed in the
workflows/directory - Image generation behavior is unchanged at its core
What’s New
- Streamable HTTP transport replaces the older WebSocket-based approach
- Explicit job management (
get_job,get_queue_status,cancel_job) - Asset identity instead of ad-hoc URLs (stable across hostname changes)
- Iteration support via
regenerate(replay with parameter overrides) - Optional visual feedback for agents via
view_image - Configurable defaults to avoid repeating common parameters
What Changed Conceptually
Earlier 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:
- refer back to specific outputs
- refine results without re-specifying everything
- poll and cancel long-running jobs
- let AI agents inspect generated images directly
Looking for the Old Behavior?
If you want the minimal, single-shot behavior from earlier versions:
- run
tests/clients/test_client.py(this mirrors the original usage pattern) - call
generate_imagewith just a prompt (server defaults handle the rest) - ignore the additional tools
No migration is required unless you want the new capabilities.
Available Tools
Generation Tools
generate_image: Generate images (requiresprompt)generate_song: Generate audio (requirestagsandlyrics)regenerate: Regenerate an existing asset with optional parameter overrides (requiresasset_id)
Viewing Tools
view_image: View generated images inline (images only, not audio/video)
Job Management Tools
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 job
Configuration Tools
list_models: List available ComfyUI modelsget_defaults: Get current default valuesset_defaults: Set default values (with optional persistence)
Node Introspection Tools
Purpose: Enable AI agents to understand, troubleshoot, and build ComfyUI workflows. When a user provides a workflow JSON, agents can use these tools to validate node configurations, discover compatible nodes, and intelligently extend or fix workflows.
list_available_nodes: List all ComfyUI nodes with categories and metadata - discover what's available in the environmentget_node_definition: Get detailed schema for a specific node (inputs, outputs, types) - validate and understand node requirementssearch_nodes: Search for nodes by name, category, or output type - find compatible nodes for workflow constructionget_node_inputs: Get input parameter specifications for a node - troubleshoot missing or incorrect parameters
Common Use Cases:
- Troubleshooting: User provides broken workflow → agent uses
get_node_definitionto validate node inputs and identify issues - Extension: User wants to add upscaling → agent uses
search_nodes(output_type="IMAGE")to find compatible nodes - Building: User describes desired workflow → agent uses
list_available_nodesandsearch_nodesto construct workflow from scratch
Workflow Tools
list_workflows: List all available workflowsrun_workflow: Run any workflow with custom parameters
Publish Tools
get_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:
- Session-scoped:
asset_ids are valid only for the current server session; restart invalidates them. - Zero-config in common cases: Publish dir auto-detected (
public/gen,static/gen, orassets/gen); if ComfyUI output can't be detected, set it once viaset_comfyui_output_root. - Two modes: Demo (explicit filename) and Library (auto filename + manifest update). In library mode,
manifest_keyis required. - Manifest: Updated only when
manifest_keyis provided. - Compression: Deterministic ladder to meet size limits; fails with a clear error if it can't.
Quick Start:
Example agent conversation flow:
User: "Generate a hero image for my website and publish it as hero.webp"
Agent: Checks publish configuration
- Calls
get_publish_info()→ sees status "ready"
Agent: Generates image
- Calls
generate_image(prompt="a hero image for a website")→ getsasset_id
Agent: Publishes asset
- Calls
publish_asset(asset_id="...", target_filename="hero.webp")→ success
User: "Now generate a logo and add it to the manifest as 'site-logo'"
Agent: Generates and publishes with manifest
- Calls
generate_image(prompt="a modern logo")→ getsasset_id - Calls
publish_asset(asset_id="...", manifest_key="site-logo")→ auto-generates filename, updates manifest
See docs/HOW_TO_TEST_PUBLISH.md for detailed usage and testing instructions.
Custom Workflows
Add custom workflows by placing JSON files in the workflows/ directory. Workflows are automatically discovered and exposed as MCP tools.
Workflow Placeholders
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).
Configuration
The server supports configurable defaults to avoid repeating common parameters. Defaults can be set via:
- Runtime defaults: Use
set_defaultstool (ephemeral, lost on restart) - Config file:
~/.config/comfy-mcp/config.json(persistent) - Environment variables:
COMFY_MCP_DEFAULT_*prefixed variables
Defaults are resolved in priority order: per-call values → runtime defaults → config file → environment variables → hardcoded defaults.
For complete configuration details, see docs/REFERENCE.md.
Detailed Reference
Complete parameter lists, return schemas, configuration options, and advanced workflow metadata are documented in:
- API Reference - Complete tool reference, parameters, return values, and configuration
- Architecture - Design decisions and system overview
Project Structure
comfyui-mcp-server/
├── server.py # Main entry point
├── src/ # Source code
│ ├── auth/ # Authentication abstractions
│ ├── client/ # HTTP client with httpx
│ ├── routes/ # HTTP transport layer
│ ├── orchestrators/ # Business logic layer
│ ├── models/ # Data models
│ ├── tools/ # MCP tool registrations
│ └── utils/ # Cross-cutting utilities
│ └── asset_processor.py # Image processing
├── tests/ # Test files
│ └── clients/
│ └── test_client.py # Test client
├── docs/ # Documentation
└── workflows/ # Workflow JSON files
├── generate_image.json
└── generate_song.json
Notes
- The server binds to localhost by default. Do not expose it publicly without authentication or a reverse proxy.
- Ensure your models exist in
<ComfyUI_dir>/models/checkpoints/ - Server uses streamable-http transport (HTTP-based, not WebSocket)
- Workflows are auto-discovered - no code changes needed
- Assets expire after 24 hours (configurable)
view_imageonly supports images (PNG, JPEG, WebP, GIF)- Asset identity uses
(filename, subfolder, type)instead of URL for robustness - Full workflow history is stored for provenance and reproducibility
regenerateuses stored workflow data to recreate assets with parameter overrides- Session isolation:
list_assetscan filter by session for clean AI agent context
Troubleshooting
Server won't start:
- Check ComfyUI is running on port 8188 (default)
- Verify Python 3.8+ is installed (
python --version) - Check all dependencies are installed:
pip install -r requirements.txt - Check server logs for specific error messages
Client can't connect:
- Verify server shows "Server running at http://127.0.0.1:9000/mcp" in the console
- Test server directly:
curl http://127.0.0.1:9000/mcp(should return MCP response) - Check
.mcp.jsonis in project root (or correct location for your client) - Try both
"type": "streamable-http"and"type": "http"- both are supported - For Cursor-specific issues, see docs/MCP_CONFIG_README.md
Tools not appearing:
- Check
workflows/directory has JSON files withPARAM_*placeholders - Check server logs for workflow parsing errors
- Verify ComfyUI has required custom nodes installed (if using custom workflows)
- Restart the MCP server after adding new workflows
Asset not found errors:
- Assets expire after 24 hours by default (configurable via
COMFY_MCP_ASSET_TTL_HOURS) - Assets are lost on server restart (ephemeral by design)
- Use
get_asset_metadatato verify asset exists before usingregenerate - Check server logs to see if asset was registered successfully
Known Limitations (v1.0)
- Ephemeral asset registry:
asset_idreferences are only valid while the MCP server is running (and until TTL expiry). After restart, previously-issuedasset_ids can’t be resolved, and regenerate will fail for those assets.
Contributing
Issues and pull requests are welcome! See CONTRIBUTING.md for development guidelines.
Acknowledgements
- @venetanji - streamable-http foundation & PARAM_* system
Maintainer
License
Apache License 2.0
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。