comfyui-mcp 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/CLAUDE.md +28 -0
  2. package/README.md +336 -93
  3. package/dist/comfyui/client.d.ts +23 -1
  4. package/dist/comfyui/client.d.ts.map +1 -1
  5. package/dist/comfyui/client.js +69 -2
  6. package/dist/comfyui/client.js.map +1 -1
  7. package/dist/comfyui/types.d.ts +2 -0
  8. package/dist/comfyui/types.d.ts.map +1 -1
  9. package/dist/index.js +2 -0
  10. package/dist/index.js.map +1 -1
  11. package/dist/services/civitai-lookup.d.ts +24 -0
  12. package/dist/services/civitai-lookup.d.ts.map +1 -0
  13. package/dist/services/civitai-lookup.js +68 -0
  14. package/dist/services/civitai-lookup.js.map +1 -0
  15. package/dist/services/file-hasher.d.ts +32 -0
  16. package/dist/services/file-hasher.d.ts.map +1 -0
  17. package/dist/services/file-hasher.js +131 -0
  18. package/dist/services/file-hasher.js.map +1 -0
  19. package/dist/services/generation-tracker.d.ts +84 -0
  20. package/dist/services/generation-tracker.d.ts.map +1 -0
  21. package/dist/services/generation-tracker.js +268 -0
  22. package/dist/services/generation-tracker.js.map +1 -0
  23. package/dist/services/hierarchical-mermaid.d.ts +11 -0
  24. package/dist/services/hierarchical-mermaid.d.ts.map +1 -0
  25. package/dist/services/hierarchical-mermaid.js +217 -0
  26. package/dist/services/hierarchical-mermaid.js.map +1 -0
  27. package/dist/services/image-management.d.ts +31 -0
  28. package/dist/services/image-management.d.ts.map +1 -0
  29. package/dist/services/image-management.js +182 -0
  30. package/dist/services/image-management.js.map +1 -0
  31. package/dist/services/job-watcher.d.ts +43 -0
  32. package/dist/services/job-watcher.d.ts.map +1 -0
  33. package/dist/services/job-watcher.js +320 -0
  34. package/dist/services/job-watcher.js.map +1 -0
  35. package/dist/services/mermaid-converter.d.ts +17 -1
  36. package/dist/services/mermaid-converter.d.ts.map +1 -1
  37. package/dist/services/mermaid-converter.js +9 -9
  38. package/dist/services/mermaid-converter.js.map +1 -1
  39. package/dist/services/model-resolver.d.ts +1 -1
  40. package/dist/services/model-resolver.d.ts.map +1 -1
  41. package/dist/services/model-resolver.js +3 -1
  42. package/dist/services/model-resolver.js.map +1 -1
  43. package/dist/services/process-control.d.ts +20 -0
  44. package/dist/services/process-control.d.ts.map +1 -0
  45. package/dist/services/process-control.js +442 -0
  46. package/dist/services/process-control.js.map +1 -0
  47. package/dist/services/queue-manager.d.ts +22 -0
  48. package/dist/services/queue-manager.d.ts.map +1 -0
  49. package/dist/services/queue-manager.js +34 -0
  50. package/dist/services/queue-manager.js.map +1 -0
  51. package/dist/services/workflow-executor.d.ts +9 -10
  52. package/dist/services/workflow-executor.d.ts.map +1 -1
  53. package/dist/services/workflow-executor.js +33 -124
  54. package/dist/services/workflow-executor.js.map +1 -1
  55. package/dist/services/workflow-sections.d.ts +30 -0
  56. package/dist/services/workflow-sections.d.ts.map +1 -0
  57. package/dist/services/workflow-sections.js +274 -0
  58. package/dist/services/workflow-sections.js.map +1 -0
  59. package/dist/services/workflow-settings-extractor.d.ts +14 -0
  60. package/dist/services/workflow-settings-extractor.d.ts.map +1 -0
  61. package/dist/services/workflow-settings-extractor.js +280 -0
  62. package/dist/services/workflow-settings-extractor.js.map +1 -0
  63. package/dist/services/workflow-validator.d.ts +18 -0
  64. package/dist/services/workflow-validator.d.ts.map +1 -0
  65. package/dist/services/workflow-validator.js +167 -0
  66. package/dist/services/workflow-validator.js.map +1 -0
  67. package/dist/tools/diagnostics.js +2 -2
  68. package/dist/tools/diagnostics.js.map +1 -1
  69. package/dist/tools/generation-tracker.d.ts +3 -0
  70. package/dist/tools/generation-tracker.d.ts.map +1 -0
  71. package/dist/tools/generation-tracker.js +118 -0
  72. package/dist/tools/generation-tracker.js.map +1 -0
  73. package/dist/tools/image-management.d.ts +3 -0
  74. package/dist/tools/image-management.d.ts.map +1 -0
  75. package/dist/tools/image-management.js +105 -0
  76. package/dist/tools/image-management.js.map +1 -0
  77. package/dist/tools/index.d.ts.map +1 -1
  78. package/dist/tools/index.js +12 -0
  79. package/dist/tools/index.js.map +1 -1
  80. package/dist/tools/memory-management.d.ts +3 -0
  81. package/dist/tools/memory-management.d.ts.map +1 -0
  82. package/dist/tools/memory-management.js +103 -0
  83. package/dist/tools/memory-management.js.map +1 -0
  84. package/dist/tools/process-control.d.ts +3 -0
  85. package/dist/tools/process-control.d.ts.map +1 -0
  86. package/dist/tools/process-control.js +38 -0
  87. package/dist/tools/process-control.js.map +1 -0
  88. package/dist/tools/queue-management.d.ts +3 -0
  89. package/dist/tools/queue-management.d.ts.map +1 -0
  90. package/dist/tools/queue-management.js +98 -0
  91. package/dist/tools/queue-management.js.map +1 -0
  92. package/dist/tools/workflow-execute.d.ts.map +1 -1
  93. package/dist/tools/workflow-execute.js +21 -67
  94. package/dist/tools/workflow-execute.js.map +1 -1
  95. package/dist/tools/workflow-library.d.ts.map +1 -1
  96. package/dist/tools/workflow-library.js +40 -0
  97. package/dist/tools/workflow-library.js.map +1 -1
  98. package/dist/tools/workflow-validate.d.ts +3 -0
  99. package/dist/tools/workflow-validate.d.ts.map +1 -0
  100. package/dist/tools/workflow-validate.js +76 -0
  101. package/dist/tools/workflow-validate.js.map +1 -0
  102. package/dist/tools/workflow-visualize.d.ts.map +1 -1
  103. package/dist/tools/workflow-visualize.js +82 -0
  104. package/dist/tools/workflow-visualize.js.map +1 -1
  105. package/dist/utils/errors.d.ts +3 -0
  106. package/dist/utils/errors.d.ts.map +1 -1
  107. package/dist/utils/errors.js +6 -0
  108. package/dist/utils/errors.js.map +1 -1
  109. package/docs/design/generation-tracker.md +457 -0
  110. package/model-settings.json +509 -0
  111. package/model-settings.user.jsonc +97 -0
  112. package/model-settings.user.jsonc.example +97 -0
  113. package/package.json +5 -1
  114. package/plugin/scripts/monitor-progress.mjs +421 -0
  115. package/scripts/generation-stats.mjs +136 -0
  116. package/scripts/postinstall.mjs +29 -0
package/CLAUDE.md ADDED
@@ -0,0 +1,28 @@
1
+ # Development Notes
2
+
3
+ ## Local Testing with npm link
4
+
5
+ The developer uses `npm link` so that `npx comfyui-mcp` resolves to the local build at `C:\Users\klutt\code\comfyui-mcp\dist\`.
6
+
7
+ **DO NOT modify `plugin/.mcp.json`** to point to a local path. It must stay as:
8
+ ```json
9
+ {
10
+ "comfyui": {
11
+ "command": "npx",
12
+ "args": ["-y", "comfyui-mcp"]
13
+ }
14
+ }
15
+ ```
16
+ This works for both:
17
+ - **Public users**: `npx` downloads from npm
18
+ - **Developer**: `npm link` makes `npx` resolve to the local build
19
+
20
+ After code changes: `npm run build` then `/mcp` reconnect in Claude Code.
21
+
22
+ ## Plugin File Sync
23
+
24
+ The plugin runs from cached copies, not the source tree. After changing files in `plugin/`:
25
+ - Cache: `~/.claude/plugins/cache/comfyui-mcp/comfy/0.1.0/`
26
+ - Marketplace: `~/.claude/plugins/marketplaces/comfyui-mcp/plugin/`
27
+
28
+ Copy changed files to both locations, then restart Claude Code for hooks or `/mcp` for MCP tools.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # comfyui-mcp
2
2
 
3
- **MCP server + Claude Code plugin for [ComfyUI](https://github.com/comfyanonymous/ComfyUI)** — execute workflows, generate images, visualize pipelines, manage models, and explore custom nodes, all from your AI coding assistant.
3
+ **MCP server + Claude Code plugin for [ComfyUI](https://github.com/comfyanonymous/ComfyUI)** — execute workflows, generate images, visualize pipelines, manage models, control VRAM, and explore custom nodes, all from your AI coding assistant.
4
4
 
5
5
  [![npm version](https://img.shields.io/npm/v/comfyui-mcp)](https://www.npmjs.com/package/comfyui-mcp)
6
6
  [![Node.js](https://img.shields.io/badge/node-%3E%3D22.0.0-brightgreen)](https://nodejs.org)
@@ -8,6 +8,8 @@
8
8
 
9
9
  Works on **macOS**, **Linux**, and **Windows**. Auto-detects your ComfyUI installation and port.
10
10
 
11
+ **31 MCP tools** | **10 slash commands** | **4 knowledge skills** | **3 autonomous agents** | **3 hooks**
12
+
11
13
  ---
12
14
 
13
15
  ## Quick Start
@@ -44,7 +46,7 @@ Claude will find (or download) a checkpoint, build a workflow, execute it, and r
44
46
 
45
47
  ## Claude Code Plugin
46
48
 
47
- This package also ships as a **Claude Code plugin**, providing slash commands, skills, and an explorer agent on top of the MCP tools.
49
+ This package also ships as a **Claude Code plugin**, providing slash commands, skills, agents, and hooks on top of the MCP tools.
48
50
 
49
51
  ### Install as a plugin
50
52
 
@@ -56,108 +58,156 @@ claude plugin install comfyui-mcp
56
58
 
57
59
  | Command | Description |
58
60
  |---------|-------------|
59
- | `/comfy:gen <prompt>` | Generate an image from a text description |
60
- | `/comfy:viz <workflow>` | Visualize a workflow as a Mermaid diagram |
61
- | `/comfy:node-skill <pack>` | Generate a Claude skill for a custom node pack |
62
-
63
- ### Built-in skill
64
-
65
- The **comfyui-core** skill gives Claude deep knowledge of ComfyUI's workflow format, node types, data flow patterns, and pipeline architecture — so it can build and debug workflows without guessing.
61
+ | `/comfy:gen <prompt>` | Generate an image from a text description — auto-selects checkpoint, builds workflow, returns image |
62
+ | `/comfy:viz <workflow>` | Visualize a workflow as a Mermaid diagram with nodes grouped by category |
63
+ | `/comfy:node-skill <pack>` | Generate a Claude skill for a custom node pack from Registry ID or GitHub URL |
64
+ | `/comfy:debug [prompt_id]` | Diagnose why a workflow failed — reads history, logs, traces root cause, suggests fixes |
65
+ | `/comfy:batch <prompt, params>` | Parameter sweep generation across cfg, sampler, steps, seed, etc. |
66
+ | `/comfy:convert <file>` | Convert between UI format and API format workflows |
67
+ | `/comfy:install <pack>` | Install a custom node pack git clone, pip install, optional restart |
68
+ | `/comfy:gallery [filter]` | Browse generated outputs with metadata — filter by date, count, or filename |
69
+ | `/comfy:compare <a vs b>` | Diff two workflows side by side — shows added/removed nodes and changed parameters |
70
+ | `/comfy:recipe <name> <prompt>` | Multi-step recipes: `portrait`, `hires-fix`, `style-transfer`, `product-shot` |
71
+
72
+ ### Built-in skills
73
+
74
+ | Skill | Description |
75
+ |-------|-------------|
76
+ | **comfyui-core** | Workflow format, node types, data flow patterns, pipeline architecture, MCP tool usage guide |
77
+ | **prompt-engineering** | CLIP weight syntax `(word:1.3)`, BREAK tokens, embeddings, model-specific prompting for SD1.5/SDXL/Flux/SD3 |
78
+ | **troubleshooting** | Common error catalog — OOM, dtype mismatches, missing nodes, NaN tensors, black images, CUDA errors, with VRAM estimates per model |
79
+ | **model-compatibility** | Compatibility matrix — loaders, resolutions, CFG, samplers, ControlNets, LoRAs, and VAEs per model family (SD1.5/SDXL/Turbo/Lightning/Flux/SD3/LTXV) |
80
+
81
+ ### Agents
82
+
83
+ | Agent | Model | Description |
84
+ |-------|-------|-------------|
85
+ | **comfy-explorer** | Sonnet | Researches custom node packs — reads docs, queries `/object_info`, generates comprehensive skill files |
86
+ | **comfy-debugger** | Sonnet | Autonomously diagnoses workflow failures — gathers logs + history, identifies failing node, checks models + custom nodes, proposes and optionally applies fixes |
87
+ | **comfy-optimizer** | Sonnet | Analyzes workflows for performance — detects redundant nodes, VRAM waste, wrong CFG/steps for model family, precision issues, suggests optimizations |
88
+
89
+ ### Hooks
90
+
91
+ | Event | Trigger | Action |
92
+ |-------|---------|--------|
93
+ | PreToolUse | `enqueue_workflow` | **VRAM watchdog** — checks GPU memory via `/system_stats` and warns if < 1GB free before execution |
94
+ | PreToolUse | `stop_comfyui`, `restart_comfyui` | **Save warning** — prompts user to save unsaved workflow changes before stopping ComfyUI |
95
+ | PostToolUse | Any comfyui tool | **Job completion notify** — checks for completed jobs and injects completion summaries into the conversation |
96
+
97
+ ### Background Scripts
66
98
 
67
- ### Explorer agent
68
-
69
- The **comfy-explorer** agent autonomously researches custom node packs: it reads documentation, queries node definitions from your running ComfyUI, finds example workflows, and generates comprehensive skill files.
99
+ | Script | Description |
100
+ |--------|-------------|
101
+ | `monitor-progress.mjs` | **Progress monitor** connects to ComfyUI's WebSocket for real-time step progress (e.g., `step 5/14 (36%)`). Run as a background Bash task after enqueuing workflows. Reports completion with output filenames, errors with node details. Replaces polling `get_job_status` in a loop. |
70
102
 
71
103
  ---
72
104
 
73
105
  ## MCP Tools
74
106
 
107
+ 31 tools organized into 13 categories:
108
+
75
109
  ### Workflow Execution
76
110
 
77
111
  | Tool | Description |
78
112
  |------|-------------|
79
- | `run_workflow` | Execute a workflow (API format JSON), returns images as base64 |
80
- | `get_job_status` | Check execution status of a running job |
81
- | `get_queue` | View the current execution queue |
113
+ | `enqueue_workflow` | Submit a workflow (API format JSON) returns `prompt_id` immediately, non-blocking |
114
+ | `get_job_status` | Check execution status of a job by prompt ID |
115
+ | `get_queue` | View the current execution queue (running + pending) |
82
116
  | `cancel_job` | Interrupt the currently running job |
83
- | `get_system_stats` | Get system info (GPU, VRAM, Python version, OS) |
117
+ | `get_system_stats` | Get system info GPU, VRAM, Python version, OS |
84
118
 
85
119
  ### Workflow Visualization
86
120
 
87
121
  | Tool | Description |
88
122
  |------|-------------|
89
- | `visualize_workflow` | Convert a workflow to a Mermaid flowchart diagram |
123
+ | `visualize_workflow` | Convert a workflow to a Mermaid flowchart with nodes grouped by category |
90
124
  | `mermaid_to_workflow` | Convert a Mermaid diagram back to executable workflow JSON |
91
125
 
92
126
  ### Workflow Composition
93
127
 
94
128
  | Tool | Description |
95
129
  |------|-------------|
96
- | `create_workflow` | Generate a workflow from templates (txt2img, img2img, upscale, inpaint) |
97
- | `modify_workflow` | Apply operations: set_input, add_node, remove_node, connect, insert_between |
98
- | `get_node_info` | Query available node types from ComfyUI's `/object_info` |
130
+ | `create_workflow` | Generate a workflow from templates: `txt2img`, `img2img`, `upscale`, `inpaint` |
131
+ | `modify_workflow` | Apply operations: `set_input`, `add_node`, `remove_node`, `connect`, `insert_between` |
132
+ | `get_node_info` | Query available node types from ComfyUI's `/object_info` endpoint |
99
133
 
100
- ### Model Management
134
+ ### Workflow Validation
101
135
 
102
136
  | Tool | Description |
103
137
  |------|-------------|
104
- | `search_models` | Search HuggingFace for compatible models |
105
- | `download_model` | Download a model to the correct ComfyUI subdirectory |
106
- | `list_local_models` | List installed models by type (checkpoints, loras, vae, etc.) |
138
+ | `validate_workflow` | Dry-run validation checks missing nodes, broken connections, invalid output indices, missing model files |
107
139
 
108
- ### Registry & Discovery
140
+ ### Workflow Library
109
141
 
110
142
  | Tool | Description |
111
143
  |------|-------------|
112
- | `search_custom_nodes` | Search the ComfyUI Registry for custom node packs |
113
- | `get_node_pack_details` | Get full details of a custom node pack |
114
- | `generate_node_skill` | Generate a Claude skill from a registry ID or GitHub URL |
144
+ | `list_workflows` | List saved workflows from ComfyUI's user library |
145
+ | `get_workflow` | Load a specific saved workflow by filename |
146
+ | `save_workflow` | Save a workflow to the ComfyUI user library |
115
147
 
116
- ### Diagnostics
148
+ ### Image Management
117
149
 
118
150
  | Tool | Description |
119
151
  |------|-------------|
120
- | `get_logs` | Get ComfyUI server logs (with optional keyword filter) |
121
- | `get_history` | Get execution history with error details and tracebacks |
152
+ | `upload_image` | Copy a local image into ComfyUI's `input/` directory for img2img, inpaint, or ControlNet |
153
+ | `workflow_from_image` | Extract embedded workflow metadata from a ComfyUI-generated PNG (reads `prompt` and `workflow` tEXt chunks) |
154
+ | `list_output_images` | Browse recently generated images from the output directory, sorted newest-first |
122
155
 
123
- ### Workflow Library
156
+ ### Model Management
124
157
 
125
158
  | Tool | Description |
126
159
  |------|-------------|
127
- | `list_workflows` | List saved workflows from ComfyUI's user library |
128
- | `get_workflow` | Load a specific saved workflow |
160
+ | `search_models` | Search HuggingFace for compatible models (checkpoints, LoRAs, VAEs, etc.) |
161
+ | `download_model` | Download a model from a URL to the correct ComfyUI subdirectory |
162
+ | `list_local_models` | List installed models by type: checkpoints, loras, vae, upscale_models, controlnet, embeddings, clip, unet |
129
163
 
130
- ---
164
+ ### Memory Management
131
165
 
132
- ## Configuration
166
+ | Tool | Description |
167
+ |------|-------------|
168
+ | `clear_vram` | Free GPU VRAM by unloading cached models — calls ComfyUI's `/free` endpoint, reports before/after stats |
169
+ | `get_embeddings` | List installed textual inversion embeddings |
133
170
 
134
- The server auto-detects your ComfyUI installation and port. Override with environment variables if needed:
171
+ ### Registry & Discovery
135
172
 
136
- | Variable | Default | Description |
137
- |----------|---------|-------------|
138
- | `COMFYUI_HOST` | `127.0.0.1` | ComfyUI server address |
139
- | `COMFYUI_PORT` | *(auto-detect)* | ComfyUI server port (tries 8188, then 8000) |
140
- | `COMFYUI_PATH` | *(auto-detect)* | Path to ComfyUI data directory |
141
- | `CIVITAI_API_TOKEN` | | CivitAI API token for model downloads |
142
- | `HUGGINGFACE_TOKEN` | | HuggingFace token for higher API rate limits |
143
- | `GITHUB_TOKEN` | | GitHub token for skill generation (avoids rate limits) |
144
- | `LOG_LEVEL` | `info` | Logging verbosity: `debug`, `info`, `warn`, `error` |
173
+ | Tool | Description |
174
+ |------|-------------|
175
+ | `search_custom_nodes` | Search the ComfyUI Registry for custom node packs by keyword |
176
+ | `get_node_pack_details` | Get full details of a custom node pack (description, author, nodes, install info) |
177
+ | `generate_node_skill` | Generate a Claude skill `.md` file from a Registry ID or GitHub URL |
145
178
 
146
- ### Auto-detection
179
+ ### Diagnostics
147
180
 
148
- **Port**: Probes `8188` (CLI default) then `8000` (Desktop app default) via `/system_stats`.
181
+ | Tool | Description |
182
+ |------|-------------|
183
+ | `get_logs` | Get ComfyUI server logs with optional keyword filter (e.g., `error`, `warning`, a node name) |
184
+ | `get_history` | Get execution history with full error details, Python tracebacks, timing, and cached node info |
149
185
 
150
- **Path**: Checks common locations in order:
186
+ ### Process Control
151
187
 
152
- - `~/Documents/ComfyUI` (macOS/Windows Desktop app data directory)
153
- - `~/Library/Application Support/ComfyUI` (macOS)
154
- - `~/AppData/Local/Programs/ComfyUI/resources/ComfyUI` (Windows Desktop app install)
155
- - `~/AppData/Local/ComfyUI` (Windows)
156
- - `~/ComfyUI`, `~/code/ComfyUI`, `~/projects/ComfyUI`, `~/src/ComfyUI`
157
- - `/opt/ComfyUI`, `~/.local/share/ComfyUI` (Linux)
158
- - Scans `~/Documents` and `~/My Documents` for any directory containing "ComfyUI"
188
+ | Tool | Description |
189
+ |------|-------------|
190
+ | `stop_comfyui` | Stop the running ComfyUI process (saves PID and launch args for restart) |
191
+ | `start_comfyui` | Start ComfyUI using info saved from a previous stop |
192
+ | `restart_comfyui` | Stop and restart ComfyUI, preserving all launch arguments |
159
193
 
160
- Set `COMFYUI_PATH` to skip detection and use an explicit path.
194
+ ### Generation Tracker
195
+
196
+ | Tool | Description |
197
+ |------|-------------|
198
+ | `suggest_settings` | Suggest proven sampler/scheduler/steps/CFG settings from local generation history — query by model family, LoRA hash, or text search |
199
+ | `generation_stats` | Show local generation tracking statistics — total runs, unique combos, breakdown by model family |
200
+
201
+ Every `enqueue_workflow` call automatically logs settings to a local SQLite database (`generations.db`). Same settings combos get a `reuse_count` bump instead of duplicates, creating a natural popularity signal. Models and LoRAs are identified by content hash (AutoV2 / SHA256), not filenames — so renamed files still group together.
202
+
203
+ ```bash
204
+ # View local stats from the CLI
205
+ npm run generations:stats
206
+ ```
207
+
208
+ ### Model Settings
209
+
210
+ Community-maintained preset library (`model-settings.json`) with research-backed sampler, scheduler, steps, and CFG values for 10+ model families. User overrides in `model-settings.user.jsonc` (auto-created from template on install, gitignored).
161
211
 
162
212
  ---
163
213
 
@@ -200,6 +250,88 @@ flowchart LR
200
250
  3 -->|CONDITIONING| 5
201
251
  ```
202
252
 
253
+ ### Debug a failed workflow
254
+
255
+ ```
256
+ > /comfy:debug
257
+ ```
258
+
259
+ Automatically reads the last execution history and logs, identifies the failing node, checks for missing models or node packs, and suggests a fix.
260
+
261
+ ```
262
+ > /comfy:debug abc123-def456
263
+ ```
264
+
265
+ Diagnose a specific execution by prompt ID.
266
+
267
+ ### Parameter sweep
268
+
269
+ ```
270
+ > /comfy:batch a cat in a field, cfg:5-10:2, sampler:euler,dpmpp_2m
271
+ ```
272
+
273
+ Generates a grid of images across all parameter combinations and presents a summary table with results.
274
+
275
+ Supported sweep parameters: `cfg`, `steps`, `sampler`, `scheduler`, `seed`, `denoise`, `width`, `height`.
276
+
277
+ ### Multi-step recipes
278
+
279
+ ```
280
+ > /comfy:recipe hires-fix a dramatic fantasy landscape with castles
281
+ ```
282
+
283
+ Runs a two-pass pipeline: txt2img at 512x768, then img2img upscale to 1024x1536 with detail enhancement.
284
+
285
+ Available recipes:
286
+
287
+ | Recipe | Description |
288
+ |--------|-------------|
289
+ | `portrait` | Generate at 1024x1024, then 2x upscale to 2048x2048 |
290
+ | `hires-fix` | Low-res generation → img2img upscale with denoise 0.4-0.5 |
291
+ | `style-transfer` | Apply a style prompt to an existing image via img2img |
292
+ | `product-shot` | Product image with clean white background |
293
+
294
+ ### Convert workflow format
295
+
296
+ ```
297
+ > /comfy:convert ~/workflows/my-ui-workflow.json
298
+ ```
299
+
300
+ Converts between ComfyUI's UI format (nodes + links arrays) and API format (node IDs → {class_type, inputs}).
301
+
302
+ ### Install a custom node pack
303
+
304
+ ```
305
+ > /comfy:install comfyui-impact-pack
306
+ ```
307
+
308
+ Searches the registry, shows details, clones the repo to `custom_nodes/`, installs dependencies, and offers to restart ComfyUI.
309
+
310
+ ### Browse output gallery
311
+
312
+ ```
313
+ > /comfy:gallery last 5
314
+ > /comfy:gallery today
315
+ ```
316
+
317
+ Lists recent outputs with embedded metadata — shows checkpoint, prompt, seed, steps, CFG, sampler for each image.
318
+
319
+ ### Compare workflows
320
+
321
+ ```
322
+ > /comfy:compare workflow-a.json vs workflow-b.json
323
+ ```
324
+
325
+ Shows added/removed nodes, changed parameters (old → new values), and optional Mermaid diagrams for visual comparison.
326
+
327
+ ### Validate before running
328
+
329
+ ```
330
+ > Validate this workflow before I run it
331
+ ```
332
+
333
+ Checks for missing node types, broken connections, invalid output indices, and missing model files — without executing.
334
+
203
335
  ### Manage models
204
336
 
205
337
  ```
@@ -208,6 +340,21 @@ flowchart LR
208
340
  > Download this model to my checkpoints folder
209
341
  ```
210
342
 
343
+ ### Manage VRAM
344
+
345
+ ```
346
+ > Free my VRAM
347
+ > What embeddings do I have?
348
+ ```
349
+
350
+ ### Extract workflow from an image
351
+
352
+ ```
353
+ > Extract the workflow from this image: ~/outputs/ComfyUI_00042_.png
354
+ ```
355
+
356
+ Reads the PNG metadata chunks to recover the exact workflow and prompt used to generate the image.
357
+
211
358
  ### Explore custom nodes
212
359
 
213
360
  ```
@@ -216,6 +363,59 @@ flowchart LR
216
363
 
217
364
  Generates a comprehensive skill file documenting every node, its inputs/outputs, and usage patterns.
218
365
 
366
+ ### Process control
367
+
368
+ ```
369
+ > Restart ComfyUI
370
+ > Stop ComfyUI
371
+ > Start ComfyUI back up
372
+ ```
373
+
374
+ ---
375
+
376
+ ## Configuration
377
+
378
+ The server auto-detects your ComfyUI installation and port. Override with environment variables if needed:
379
+
380
+ | Variable | Default | Description |
381
+ |----------|---------|-------------|
382
+ | `COMFYUI_HOST` | `127.0.0.1` | ComfyUI server address |
383
+ | `COMFYUI_PORT` | *(auto-detect)* | ComfyUI server port (tries 8188, then 8000) |
384
+ | `COMFYUI_PATH` | *(auto-detect)* | Path to ComfyUI data directory |
385
+ | `CIVITAI_API_TOKEN` | | CivitAI API token for model downloads |
386
+ | `HUGGINGFACE_TOKEN` | | HuggingFace token for higher API rate limits |
387
+ | `GITHUB_TOKEN` | | GitHub token for skill generation (avoids rate limits) |
388
+ | `LOG_LEVEL` | `info` | Logging verbosity: `debug`, `info`, `warn`, `error` |
389
+
390
+ ### Auto-detection
391
+
392
+ **Port**: Probes `8188` (CLI default) then `8000` (Desktop app default) via `/system_stats`.
393
+
394
+ **Path**: Checks common locations in order:
395
+
396
+ - `~/Documents/ComfyUI` (macOS/Windows Desktop app data directory)
397
+ - `~/Library/Application Support/ComfyUI` (macOS)
398
+ - `~/AppData/Local/Programs/ComfyUI/resources/ComfyUI` (Windows Desktop app install)
399
+ - `~/AppData/Local/ComfyUI` (Windows)
400
+ - `~/ComfyUI`, `~/code/ComfyUI`, `~/projects/ComfyUI`, `~/src/ComfyUI`
401
+ - `/opt/ComfyUI`, `~/.local/share/ComfyUI` (Linux)
402
+ - Scans `~/Documents` and `~/My Documents` for any directory containing "ComfyUI"
403
+
404
+ Set `COMFYUI_PATH` to skip detection and use an explicit path.
405
+
406
+ ---
407
+
408
+ ## How It Works
409
+
410
+ The server communicates with ComfyUI through its REST API and WebSocket interface:
411
+
412
+ - **WebSocket** — enqueue workflows, receive real-time progress updates (step-by-step via background monitor script), get execution results
413
+ - **REST API** — system stats, node definitions (`/object_info`), logs, history, queue management, workflow library, VRAM control (`/free`), embeddings
414
+ - **File system** — read/write models directory, detect installation paths, upload images, extract PNG metadata, browse outputs
415
+ - **External APIs** — HuggingFace (model search), ComfyUI Registry (custom node discovery), GitHub (skill generation), CivitAI (model downloads)
416
+
417
+ All communication with the MCP client (Claude Code) happens over **stdio** using the [Model Context Protocol](https://modelcontextprotocol.io). Logs go to stderr to avoid polluting the protocol stream.
418
+
219
419
  ---
220
420
 
221
421
  ## Development
@@ -243,6 +443,7 @@ npm install
243
443
  | `npm test` | Run unit tests (vitest) |
244
444
  | `npm run test:integration` | Run integration tests (requires running ComfyUI) |
245
445
  | `npm run lint` | Type-check without emitting |
446
+ | `npm run generations:stats` | Show local generation tracking statistics |
246
447
 
247
448
  ### Local testing with Claude Code
248
449
 
@@ -269,49 +470,85 @@ claude --plugin-dir ./plugin
269
470
  ### Project structure
270
471
 
271
472
  ```
473
+ model-settings.json # Community-maintained model presets (shipped)
474
+ model-settings.user.jsonc.example # User override template (copied on install)
475
+ scripts/
476
+ postinstall.mjs # Auto-creates user config from template
477
+ generation-stats.mjs # CLI: npm run generations:stats
272
478
  src/
273
- index.ts # MCP server entry point (stdio transport)
274
- config.ts # Auto-detection & environment config
479
+ index.ts # MCP server entry point (stdio transport)
480
+ config.ts # Auto-detection & environment config
275
481
  comfyui/
276
- client.ts # ComfyUI WebSocket/HTTP client wrapper
277
- types.ts # TypeScript interfaces
482
+ client.ts # ComfyUI WebSocket/HTTP client wrapper
483
+ types.ts # TypeScript interfaces
278
484
  services/
279
- workflow-executor.ts # Execute workflows, handle images & errors
280
- workflow-composer.ts # Templates (txt2img, img2img, upscale, inpaint)
281
- mermaid-converter.ts # Workflow -> Mermaid diagram
282
- mermaid-parser.ts # Mermaid diagram -> Workflow
283
- model-resolver.ts # HuggingFace search, local models, downloads
284
- registry-client.ts # ComfyUI Registry API
285
- skill-generator.ts # Generate node pack skill docs
286
- tools/ # MCP tool registration (one file per group)
485
+ workflow-executor.ts # Execute workflows, handle images & errors
486
+ workflow-composer.ts # Templates (txt2img, img2img, upscale, inpaint)
487
+ workflow-validator.ts # Dry-run validation (missing nodes, models, connections)
488
+ image-management.ts # Upload images, extract PNG metadata, list outputs
489
+ mermaid-converter.ts # Workflow Mermaid diagram
490
+ mermaid-parser.ts # Mermaid diagram → Workflow
491
+ model-resolver.ts # HuggingFace search, local models, downloads
492
+ generation-tracker.ts # SQLite generation log, settings dedup, stats
493
+ file-hasher.ts # SHA256 hashing of .safetensors with cache
494
+ civitai-lookup.ts # CivitAI API lookup by content hash
495
+ workflow-settings-extractor.ts # Extract settings from workflow JSON
496
+ process-control.ts # Stop, start, restart ComfyUI process
497
+ registry-client.ts # ComfyUI Registry API
498
+ skill-generator.ts # Generate node pack skill docs
499
+ tools/ # MCP tool registration (one file per group)
500
+ workflow-execute.ts # enqueue_workflow, get_system_stats
501
+ workflow-visualize.ts # visualize_workflow, mermaid_to_workflow
502
+ workflow-compose.ts # create_workflow, modify_workflow, get_node_info
503
+ workflow-validate.ts # validate_workflow
504
+ workflow-library.ts # list_workflows, get_workflow, save_workflow
505
+ image-management.ts # upload_image, workflow_from_image, list_output_images
506
+ model-management.ts # search_models, download_model, list_local_models
507
+ memory-management.ts # clear_vram, get_embeddings
508
+ registry-search.ts # search_custom_nodes, get_node_pack_details
509
+ skill-generator.ts # generate_node_skill
510
+ generation-tracker.ts # suggest_settings, generation_stats
511
+ diagnostics.ts # get_logs, get_history
512
+ process-control.ts # stop_comfyui, start_comfyui, restart_comfyui
513
+ index.ts # Registers all tool groups
287
514
  utils/
288
- errors.ts # Custom error hierarchy with MCP integration
289
- logger.ts # stderr-only logging (safe for stdio transport)
290
- image.ts # Base64 encoding utilities
515
+ errors.ts # Custom error hierarchy with MCP integration
516
+ logger.ts # stderr-only logging (safe for stdio transport)
517
+ image.ts # Base64 encoding utilities
291
518
  plugin/
292
- .claude-plugin/ # Plugin manifest
293
- .mcp.json # MCP server config for plugin
294
- commands/ # Slash command definitions
295
- skills/ # Built-in knowledge (comfyui-core)
296
- agents/ # Explorer agent
297
- hooks/ # Hook configuration
519
+ .claude-plugin/ # Plugin manifest
520
+ .mcp.json # MCP server config for plugin
521
+ commands/ # Slash commands
522
+ gen.md # /comfy:gen image generation
523
+ viz.md # /comfy:viz — workflow visualization
524
+ node-skill.md # /comfy:node-skill — skill generation
525
+ debug.md # /comfy:debug — failure diagnosis
526
+ batch.md # /comfy:batch — parameter sweeps
527
+ convert.md # /comfy:convert — format conversion
528
+ install.md # /comfy:install — node pack installation
529
+ gallery.md # /comfy:gallery — output browser
530
+ compare.md # /comfy:compare — workflow diff
531
+ recipe.md # /comfy:recipe — multi-step pipelines
532
+ skills/ # Knowledge bases
533
+ comfyui-core/ # Workflow format, node types, pipeline patterns
534
+ prompt-engineering/ # CLIP syntax, model-specific prompting
535
+ troubleshooting/ # Error catalog with patterns and fixes
536
+ model-compatibility/ # Compatibility matrix per model family
537
+ agents/ # Autonomous agents
538
+ explorer.md # Research custom node packs, generate skills
539
+ debugger.md # Diagnose workflow failures
540
+ optimizer.md # Analyze and optimize workflows
541
+ hooks/ # Pre/post tool-use hooks
542
+ hooks.json # Hook configuration
543
+ vram-check.mjs # VRAM watchdog before execution
544
+ save-warning.mjs # Save prompt before stop/restart
545
+ job-complete-notify.mjs # Job completion notification via temp files
546
+ scripts/ # Background scripts
547
+ monitor-progress.mjs # Real-time WebSocket progress monitor
298
548
  ```
299
549
 
300
550
  ---
301
551
 
302
- ## How It Works
303
-
304
- The server communicates with ComfyUI through its REST API and WebSocket interface:
305
-
306
- - **WebSocket** — enqueue workflows, receive real-time progress updates, get execution results
307
- - **REST API** — system stats, node definitions (`/object_info`), logs, history, queue management, workflow library
308
- - **File system** — read/write models directory, detect installation paths
309
- - **External APIs** — HuggingFace (model search), ComfyUI Registry (custom node discovery), GitHub (skill generation), CivitAI (model downloads)
310
-
311
- All communication with the MCP client (Claude Code) happens over **stdio** using the [Model Context Protocol](https://modelcontextprotocol.io). Logs go to stderr to avoid polluting the protocol stream.
312
-
313
- ---
314
-
315
552
  ## Troubleshooting
316
553
 
317
554
  **"ComfyUI not detected on ports 8188, 8000"**
@@ -327,7 +564,13 @@ This is informational — the server uses the first one found. Set `COMFYUI_PATH
327
564
  For HuggingFace gated models, set `HUGGINGFACE_TOKEN`. For CivitAI, set `CIVITAI_API_TOKEN`.
328
565
 
329
566
  **Workflow execution errors**
330
- Use `get_history` or `get_logs` to see detailed error messages including Python tracebacks from ComfyUI.
567
+ Use `/comfy:debug` to automatically diagnose failures. Or use `get_history` / `get_logs` directly to see detailed error messages including Python tracebacks from ComfyUI.
568
+
569
+ **Out of memory (OOM)**
570
+ Use `clear_vram` to free GPU memory before running large workflows. The VRAM watchdog hook will warn you automatically if memory is critically low. See the **troubleshooting** skill for model-specific VRAM estimates.
571
+
572
+ **Missing custom nodes**
573
+ Use `/comfy:install <pack>` to install missing node packs from the registry. The debug command will detect and suggest missing packs automatically.
331
574
 
332
575
  ---
333
576
 
@@ -342,4 +585,4 @@ Use `get_history` or `get_logs` to see detailed error messages including Python
342
585
 
343
586
  ## License
344
587
 
345
- See [LICENSE](./LICENSE) for details.
588
+ MIT — see [LICENSE](./LICENSE) for details.
@@ -2,16 +2,38 @@ import { Client } from "@stable-canvas/comfyui-client";
2
2
  import type { ObjectInfo, SystemStats, QueueStatus } from "./types.js";
3
3
  export declare function getClient(): Client;
4
4
  export declare function connectClient(): Promise<Client>;
5
+ /**
6
+ * Ensures WebSocket is connected, auto-reconnecting if stale.
7
+ * Only needed before WebSocket-dependent operations (enqueue with progress tracking).
8
+ */
9
+ export declare function ensureConnected(): Promise<Client>;
5
10
  export declare function getSystemStats(): Promise<SystemStats>;
6
11
  export declare function getObjectInfo(): Promise<ObjectInfo>;
7
12
  export declare function getQueue(): Promise<QueueStatus>;
8
- export declare function interrupt(): Promise<void>;
13
+ export declare function interrupt(promptId?: string): Promise<void>;
14
+ /**
15
+ * Fire-and-forget: enqueue a prompt via HTTP POST (no WebSocket needed).
16
+ * Returns prompt_id and queue position immediately.
17
+ */
18
+ export declare function enqueuePrompt(workflow: Record<string, unknown>): Promise<{
19
+ prompt_id: string;
20
+ queue_remaining?: number;
21
+ }>;
22
+ /**
23
+ * Remove a specific pending job from the queue by prompt_id.
24
+ */
25
+ export declare function deleteQueueItem(id: string): Promise<void>;
26
+ /**
27
+ * Clear all pending jobs from the queue (doesn't affect running job).
28
+ */
29
+ export declare function clearQueue(): Promise<void>;
9
30
  export declare function getSamplers(): Promise<string[]>;
10
31
  export declare function getSchedulers(): Promise<string[]>;
11
32
  export declare function getCheckpoints(): Promise<string[]>;
12
33
  export declare function getLoRAs(): Promise<string[]>;
13
34
  export declare function getVAEs(): Promise<string[]>;
14
35
  export declare function getUpscaleModels(): Promise<string[]>;
36
+ export declare function resetClient(): void;
15
37
  export declare function getComfyUIPath(): string | undefined;
16
38
  export declare function getLogs(): Promise<string[]>;
17
39
  export interface HistoryEntry {
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/comfyui/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;AAIvD,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAIvE,wBAAgB,SAAS,IAAI,MAAM,CAWlC;AAED,wBAAsB,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC,CAWrD;AAED,wBAAsB,cAAc,IAAI,OAAO,CAAC,WAAW,CAAC,CAI3D;AAED,wBAAsB,aAAa,IAAI,OAAO,CAAC,UAAU,CAA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