ComfyUI MCP Server - Bridge between AI Assistants and ComfyUI

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

Quick Start

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

Docker Hub →

Configuration

Environment VariableDescriptionRequired
COMFY_URLYour ComfyUI server URLYes
COMFY_WORKFLOW_JSON_FILEPath to workflow JSON exportYes
PROMPT_NODE_IDText prompt node ID in workflowYes
OUTPUT_NODE_IDOutput/SaveImage node IDYes
SEED_NODE_IDKSampler node ID for seed controlYes
COMFY_TIMEOUTMax generation time (seconds)No (default: 120)
ALLOWED_HOSTPermitted Host header valueNo

Optional Ollama Integration:

Environment VariableDescription
OLLAMA_API_BASEOllama server URL
PROMPT_LLMModel 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:

  1. Submit the prompt to your ComfyUI instance
  2. Monitor generation progress
  3. Return the completed image

Functions Available

generate_image(prompt: str, seed: int | null)

generate_prompt(topic: str) (requires Ollama)

Getting Your Workflow JSON

  1. Build your workflow in ComfyUI
  2. Click the API Export button
  3. Save the JSON file
  4. Mount it into the container or specify its path

Version History

v0.2.2

v0.2.1

v0.2.0

Resources

License

MIT License - see the LICENSE file for details.


Article by Olly ([email protected]) - Generated with local AI