
Overview
The ComfyUI MCP Server exposes ComfyUI image generation capabilities to your AI assistants via the Model Context Protocol (MCP). This allows LLMs like Claude, Cursor, or any MCP-compatible client to generate images through natural language requests.
Forked from the original by Karim Lalani with enhancements for production use.
Features
- Natural language image generation - Ask your AI assistant to create images
- Docker-ready - Pre-built images on Docker Hub
- Prompt enhancement - Optional Ollama integration for better prompts
- Context updates - Periodic status updates prevent timeouts on long generations
- Seed control - Randomize or specify seeds for reproducible results
- CVE-hardened - All critical and high-priority vulnerabilities addressed
Quick Start
Docker (Recommended)
The fastest way to get started:
docker run -d \
-e COMFY_URL=http://your-comfy-server:8188 \
-e COMFY_WORKFLOW_JSON_FILE=/workflow.json \
-e PROMPT_NODE_ID=6 \
-e OUTPUT_NODE_ID=9 \
-e SEED_NODE_ID=9 \
-v /path/to/workflow.json:/workflow.json \
snowgoons/comfyui-mcp-server:latest
Configuration
| Environment Variable | Description | Required |
|---|---|---|
COMFY_URL | Your ComfyUI server URL | Yes |
COMFY_WORKFLOW_JSON_FILE | Path to workflow JSON export | Yes |
PROMPT_NODE_ID | Text prompt node ID in workflow | Yes |
OUTPUT_NODE_ID | Output/SaveImage node ID | Yes |
SEED_NODE_ID | KSampler node ID for seed control | Yes |
COMFY_TIMEOUT | Max generation time (seconds) | No (default: 120) |
ALLOWED_HOST | Permitted Host header value | No |
Optional Ollama Integration:
| Environment Variable | Description |
|---|---|
OLLAMA_API_BASE | Ollama server URL |
PROMPT_LLM | Model name for prompt enhancement |
MCP Client Configuration
Claude Desktop
Add to your claude_desktop_config.json:
{
"mcpServers": {
"ComfyUI MCP": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e", "COMFY_URL=http://your-comfy-server:8188",
"-e", "COMFY_WORKFLOW_JSON_FILE=/workflow.json",
"-e", "PROMPT_NODE_ID=6",
"-e", "OUTPUT_NODE_ID=9",
"-e", "SEED_NODE_ID=9",
"-v", "/path/to/workflow.json:/workflow.json",
"snowgoons/comfyui-mcp-server:latest"
]
}
}
}
Cursor IDE
Add to your .cursor/mcp.json:
{
"mcpServers": {
"ComfyUI MCP": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e", "COMFY_URL=http://your-comfy-server:8188",
"-e", "COMFY_WORKFLOW_JSON_FILE=/workflow.json",
"-e", "PROMPT_NODE_ID=6",
"-e", "OUTPUT_NODE_ID=9",
"-e", "SEED_NODE_ID=9",
"-v", "/path/to/workflow.json:/workflow.json",
"snowgoons/comfyui-mcp-server:latest"
]
}
}
}
Usage
Once configured, your AI assistant can generate images with simple requests:
“Create an image of a futuristic cityscape at sunset”
The server will:
- Submit the prompt to your ComfyUI instance
- Monitor generation progress
- Return the completed image
Functions Available
generate_image(prompt: str, seed: int | null)
prompt: Text description of desired imageseed: Optional seed value for reproducibility (null = random)
generate_prompt(topic: str) (requires Ollama)
- Enhances simple topics into detailed image prompts
Getting Your Workflow JSON
- Build your workflow in ComfyUI
- Click the API Export button
- Save the JSON file
- Mount it into the container or specify its path
Version History
v0.2.2
- Addressed all Critical and High priority CVE dependencies
v0.2.1
- Release process update
v0.2.0
- Added periodic MCP ContextInfo updates to prevent client timeouts
- Added
COMFY_TIMEOUTenvironment variable - Fixed caching issue with repeated prompts/seeds
- Added seed randomization support
Resources
License
MIT License - see the LICENSE file for details.
Article by Olly ([email protected]) - Generated with local AI