Comfyui core

From artokun/comfyui-mcp · View interactive version

Comfyui core is an AI agent skill from the GitHub repository artokun/comfyui-mcp. Core ComfyUI knowledge covering workflow format, node types, pipeline patterns, and MCP tool usage

How to use this skill

Skill file

ComfyUI Core Knowledge

Workflow JSON Format (API Format)

ComfyUI workflows are JSON objects mapping string node IDs to node definitions:

{
  "1": {
    "class_type": "CheckpointLoaderSimple",
    "inputs": { "ckpt_name": "sd_xl_base_1.0.safetensors" },
    "_meta": { "title": "Load Checkpoint" }
  },
  "2": {
    "class_type": "CLIPTextEncode",
    "inputs": { "text": "a cat", "clip": ["1", 1] },
    "_meta": { "title": "Positive Prompt" }
  }
}

Key Rules

Connection Examples

"model": ["1", 0]       // Connect to node 1's first output (MODEL)
"clip": ["1", 1]        // Connect to node 1's second output (CLIP)
"vae": ["1", 2]         // Connect to node 1's third output (VAE)
"positive": ["2", 0]    // Connect to node 2's first output (CONDITIONING)
"samples": ["5", 0]     // Connect to node 5's first output (LATENT)
"images": ["6", 0]      // Connect to node 6's first output (IMAGE)

Important: API Format vs Web UI Format

Workflow Library Tools

Data Types

ComfyUI nodes pass typed data through connections:

| Type | Description | Common Source |

|------|-------------|---------------|

| MODEL | Diffusion model weights | CheckpointLoaderSimple (output 0) |

| CLIP | Text encoder | CheckpointLoaderSimple (output 1) |

| VAE | Variational autoencoder | CheckpointLoaderSimple (output 2) |

| CONDITIONING | Encoded text prompt | CLIPTextEncode (output 0) |

| LATENT | Latent space tensor | EmptyLatentImage, KSampler, VAEEncode |

| IMAGE | Pixel image tensor (BHWC) | VAEDecode, LoadImage, SaveImage |

| MASK | Single-channel mask | LoadImage (output 1) |

| UPSCALE_MODEL | Upscaling model | UpscaleModelLoader |

Standard Pipeline Patterns

Text-to-Image (txt2img)

CheckpointLoaderSimple → MODEL, CLIP, VAE
  ├─ CLIP → CLIPTextEncode (positive) → CONDITIONING
  ├─ CLIP → CLIPTextEncode (negative) → CONDITIONING
  │
EmptyLatentImage → LATENT
  │
KSampler (model, positive, negative, latent_image) → LATENT
  │
VAEDecode (samples, vae) → IMAGE
  │
SaveImage (images)

Node IDs typically: 1=Checkpoint, 2=Positive, 3=Negative, 4=EmptyLatent, 5=KSampler, 6=VAEDecode, 7=SaveImage

Image-to-Image (img2img)

Same as txt2img but replace EmptyLatentImage with:

LoadImage → IMAGE
VAEEncode (pixels, vae) → LATENT → KSampler.latent_image

Set KSampler.denoise to 0.5 to 0.8 (lower = closer to input image).

Upscale

LoadImage → IMAGE
UpscaleModelLoader → UPSCALE_MODEL
ImageUpscaleWithModel (upscale_model, image) → IMAGE
SaveImage (images)

Inpaint

LoadImage (image) → IMAGE → VAEEncode → LATENT
LoadImage (mask) → MASK
SetLatentNoiseMask (samples, mask) → LATENT → KSampler.latent_image

MCP Tool Usage Guide

Quick Generation

  1. create_workflow with template "txt2img" and your params
  2. enqueue_workflow(action="enqueue") with the returned JSON. It returns prompt_id immediately
  3. Poll queue (action:"status") with the prompt_id until done is true
  4. Use get_image (action:"list_outputs") (limit 1) to find the generated image, then Read to display it

Inspect & Modify

Reverse Engineering

Model Management

Never ask the user to manually download models. If a required model is missing, search for it and download it yourself:

  1. Check list_local_models first
  2. If missing, search HuggingFace via download_model action:"search" or CivitAI via their REST API
  3. Use download_model to install it directly to the correct subfolder

CivitAI API (when the CIVITAI_API_TOKEN env var is available):

CivitAI is preferred for fine-tuned models, community-rated checkpoints, and specialized LoRAs.

HuggingFace is preferred for official/base models (SDXL, Flux, SD 1.5).

Custom Nodes

Workflow Execution

enqueue_workflow submits to ComfyUI's queue and returns prompt_id + queue position immediately. It does not block.

Background Progress Monitoring

After enqueuing one or more workflows, use a background Bash task to monitor progress silently:

# Single job
Bash(run_in_background: true):
node "${CLAUDE_PLUGIN_ROOT}/scripts/monitor-progress.mjs" <prompt_id>

# Multiple jobs (batch)
Bash(run_in_background: true):
node "${CLAUDE_PLUGIN_ROOT}/scripts/monitor-progress.mjs" <id1> <id2> <id3>

The script connects to ComfyUI's WebSocket and reports:

The standard generation pattern:

  1. create_workflow or build workflow JSON + enqueue_workflow(action="enqueue") (repeat for batch)
  2. Start background monitor with all prompt_ids
  3. Continue conversation. Results appear when jobs finish
  4. Use get_image (action:"list_outputs") or Read to display the generated images

Do not poll queue (action:"status") in a loop. The background monitor replaces polling entirely.

If the monitor script is unavailable, fall back to queue (action:"status") and poll until done is true.

Queue Management

One tool, queue, driven by its action parameter:

When to use queue tools:

Monitoring & Recovery

When ComfyUI is unresponsive or crashed:

  1. Try get_system_stats. If it fails, ComfyUI is down
  2. Use restart_comfyui with action: "restart" (preserves launch args from a prior action: "stop")
  3. If restart fails (no saved process info), use restart_comfyui with action: "start" or ask the user to start it manually. On Windows action: "start" never launches ComfyUI (it refuses), so ask the user to start it from the Desktop app or its launcher
  4. After ComfyUI is back, re-enqueue any failed/lost workflows

Before stopping ComfyUI for maintenance:

  1. Call restart_comfyui with action: "status" first. It is read-only. Then read stop.recoverable_by_start:
  1. To cycle ComfyUI, use action: "restart", not stop then start. Restart refuses rather than leaving ComfyUI down when it cannot bring it back
  2. Use action: "stop" only when ComfyUI should stay down

When a job appears hung (monitor shows [STALL]):

  1. Check get_system_stats and look at VRAM usage (OOM causes hangs)
  2. Try queue (action:"cancel") to interrupt the stuck job
  3. If cancel fails, use restart_comfyui to force-restart
  4. Use clear_vram after restart to free GPU memory before retrying

KSampler Parameters

| Parameter | Type | Common Values |

|-----------|------|---------------|

| seed | int | Random (0 to 2^48). Omit to auto-randomize. |

| steps | int | 20 (standard), 4-8 (turbo/lightning models) |

| cfg | float | 7-8 (SD 1.5/SDXL), 1.0 (Flux), 3.5 (turbo) |

| sampler_name | string | "euler", "euler_ancestral", "dpmpp_2m", "dpmpp_sde" |

| scheduler | string | "normal", "karras", "sgm_uniform" |

| denoise | float | 1.0 (txt2img), 0.5-0.8 (img2img), 0.75-0.9 (inpaint) |

Mermaid Visualization Conventions

The visualize_workflow tool produces mermaid flowcharts with:

The visualize_workflow (action:"mermaid") tool parses mermaid back into workflow JSON, using connection type labels to resolve the correct input/output slots via /object_info schemas.

Common Mistakes to Avoid

  1. Wrong connection format. Use ["1", 0] not [1, 0]; node IDs are strings
  2. Web UI format. Don't pass { nodes: [], links: [] }; use API format
  3. Missing VAE. CheckpointLoaderSimple has 3 outputs: MODEL(0), CLIP(1), VAE(2)
  4. Wrong output index. Check the node's output list order via create_workflow (action:"node_info")
  5. Seed handling. enqueue_workflow randomizes seeds by default unless disable_random_seed: true

Sources

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.