comfyui-mcp 0.48.22 → 0.48.23

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.
package/README.md CHANGED
@@ -16,7 +16,7 @@ Works on **macOS**, **Linux**, and **Windows**. Auto-detects your ComfyUI instal
16
16
 
17
17
  **Stuck or have a question? [Join the Discord](https://discord.gg/cW9arBhzCu)** — help, model tips, and release announcements.
18
18
 
19
- **182 MCP tools** | **35 AI skills** (Flux · WAN · LTX 2.3 video · Qwen · Z-Image · Ideogram 4 · ERNIE · ANIMA · model registry · Civitai · node authoring · launch/perf flags) | **55 installer packs** | **11 slash commands** | **4 autonomous agents** | **3 hooks**
19
+ **182 MCP tools** | **36 AI skills** (Flux · WAN · LTX 2.3 video · Qwen · Z-Image · Ideogram 4 · ERNIE · ANIMA · model registry · Civitai · node authoring · launch/perf flags) | **55 installer packs** | **11 slash commands** | **4 autonomous agents** | **3 hooks**
20
20
 
21
21
  The plugin ships **expert skills that grow with every release** — model-specific generation guides with curated download URLs, workflow recipes, troubleshooting, and custom-node authoring — so Claude knows the right sampler, CFG, resolution, and model files for each architecture without trial and error.
22
22
 
@@ -26,7 +26,7 @@ import { uploadImageHttp, resetClient } from "../comfyui/client.js";
26
26
  import { logger } from "../utils/logger.js";
27
27
  import { PanelAgentManager, fetchSupportedModels, fetchSupportedCommands, isEffort, } from "./panel-agent.js";
28
28
  import { promptText } from "./error-text.js";
29
- import { createPanelMcpServer } from "./panel-tools.js";
29
+ import { createPanelMcpServer, makePanelToolCtx, resolvePinTarget } from "./panel-tools.js";
30
30
  import { optionsAckFrame, optionsErrorAckFrame, optionsRequestMeta, } from "./options-ack.js";
31
31
  import { readUserMcpServers } from "../services/user-mcp-config.js";
32
32
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
@@ -85,7 +85,7 @@ REPORT OUR OWN BUGS (we're in beta — bias HARD toward filing) — distinct fro
85
85
 
86
86
  WEDGED RENDER / OOM / VRAM PINNED — when a generation is stuck or hits CUDA out-of-memory, or a cancel didn't actually free GPU memory (models still resident, VRAM pinned, the next run still OOMs), call panel_free_vram to UNLOAD all models and free VRAM before retrying — it does NOT restart ComfyUI, so it's the cheap first move. Escalation ladder: cancel the run → panel_free_vram (unload + free) → retry; only as a LAST RESORT panel_restart_comfyui (which refuses mid-render and guards the running generation). Reach for panel_free_vram before a restart whenever a cancel left memory pinned.
87
87
 
88
- WORKFLOW TARGETING — by default your panel_* graph edits follow whichever workflow tab the user is currently viewing. If the user wants you to work on a DIFFERENT open workflow while they browse another tab, call panel_set_workflow_target(mode:"pinned", path:<from panel_list_workflows>) to pin edits to that workflow; panel_get_workflow_target shows the current binding. Set mode:"current" to follow the user's active tab again. Pinning does NOT switch what the user sees it only routes your graph tools. When pinned, still use panel_open_workflow only when you intentionally want to switch the user's view.
88
+ WORKFLOW TARGETING — by default your panel_* graph edits follow whichever workflow tab the user is currently viewing. The panel can only read or edit the workflow currently IN VIEW, so to work on a specific open workflow, make it the active canvas first with panel_open_workflow, then call panel_set_workflow_target(mode:"pinned", path:<from panel_list_workflows>) to bind your edits to it; panel_get_workflow_target shows the current binding. Pinning to a background (open but not active) workflow is REJECTED at pin time — it cannot route edits to a tab that isn't in view. A pin does NOT switch what the user sees; it binds your edits to that workflow so that if the user later switches away, your next graph call fails loudly instead of silently editing the wrong graph. Set mode:"current" to follow the user's active tab again.
89
89
 
90
90
  CRITICAL — never destroy the user's work. When they ask for a "new workflow", a "fresh canvas", or to "start over for a new project", call panel_new_workflow (it opens a NEW TAB and leaves their current workflow intact). NEVER use panel_clear for that — panel_clear wipes the CURRENTLY OPEN graph and is ONLY for an explicit "clear/reset this canvas". You can manage tabs with panel_list_workflows / panel_open_workflow / panel_rename_workflow / panel_close_workflow, and group nodes with panel_select_nodes / panel_create_subgraph. To label a node by its purpose, use panel_set_node_title. To read or edit nodes INSIDE a subgraph, call panel_enter_subgraph(node_id) first — then panel_query_graph / panel_graph_outline and the panel_* edit tools operate on the subgraph's inner nodes — and panel_exit_subgraph when you're done.
91
91
 
@@ -1244,7 +1244,20 @@ export async function runPanelOrchestrator() {
1244
1244
  // race) can label itself correctly instead of showing the pre-init default.
1245
1245
  const resolvedModelByTab = new Map();
1246
1246
  const headlessTabs = new Set(); // tabs with no ComfyUI canvas (mobile/remote) — deliver renders in-turn
1247
+ // #570: for an UNSAVED workflow the panel tab id is an ephemeral tmp:<uuid>,
1248
+ // regenerated on every reload, so the tab-keyed session store can't survive an
1249
+ // orchestrator restart that also reloads the panel. Map each such tab to a STABLE
1250
+ // resume key (origin + title + backend) computed at hello, so onSession can also
1251
+ // persist under it and a reloaded tab can resume it. tmp: tabs only.
1252
+ const tabStableKey = new Map();
1247
1253
  const workflowTargets = new WorkflowTargetStore();
1254
+ // Monotonic per-tab sequence for set_workflow_target events. A pinned target is
1255
+ // validated asynchronously (resolvePinTarget queries workflow_list), so a later event
1256
+ // (another pin, or a synchronous mode:"current") can arrive before the async pin
1257
+ // commits. Each event bumps the tab's sequence; a pinned resolution only commits/acks if
1258
+ // its captured sequence is still the latest — otherwise a stale pin would clobber the
1259
+ // user's newer selection (codex race).
1260
+ const workflowTargetSeq = new Map();
1248
1261
  const backendForTab = (panelTabId) => tabBackends.get(panelTabId) ?? defaultBackend;
1249
1262
  const agentKeyFor = (panelTabId) => panelTabId + AGENT_KEY_SEP + backendForTab(panelTabId);
1250
1263
  // A panel tab id never contains "::"; backend names never do — so split on the
@@ -1687,6 +1700,10 @@ export async function runPanelOrchestrator() {
1687
1700
  COMFYUI_URL: comfyuiUrl,
1688
1701
  // Where download_model writes live progress for the panel tray.
1689
1702
  COMFYUI_MCP_PROGRESS_DIR: progressDir,
1703
+ // Self-scope this tab's downloads so the orchestrator can wake EXACTLY
1704
+ // this tab's agent when a download settles (#547) — the child stamps its
1705
+ // own COMFYUI_MCP_TAB into each progress row, mirroring COMFYUI_MCP_BLIND.
1706
+ ...(panelTab ? { COMFYUI_MCP_TAB: panelTab } : {}),
1690
1707
  // Local mode → enables download_model, apply_manifest (installer packs),
1691
1708
  // and model scans so the agent installs the right way instead of curl.
1692
1709
  ...(comfyuiPath ? { COMFYUI_PATH: comfyuiPath } : forceRemoteEnv()),
@@ -1733,6 +1750,12 @@ export async function runPanelOrchestrator() {
1733
1750
  // Report the SDK session id so the panel can persist it and resume on reload.
1734
1751
  onSession: (key, sessionId, model) => {
1735
1752
  const panelTab = panelTabOf(key);
1753
+ // #570: also persist under the tab's STABLE resume key (unsaved workflows),
1754
+ // so a panel reload that regenerates the tmp:<uuid> can still resume this
1755
+ // conversation. The manager already persisted under the exact tab key.
1756
+ const skey = tabStableKey.get(panelTab);
1757
+ if (skey)
1758
+ sessionStore.setStable(skey, sessionId, panelTab);
1736
1759
  bridge.push({ type: "session", session_id: sessionId }, panelTab);
1737
1760
  bridge.broadcastTabList(); // a session started/changed → refresh mirror pickers
1738
1761
  // #376: the ready banner was sent at hello with the PRE-init default model.
@@ -2326,6 +2349,12 @@ export async function runPanelOrchestrator() {
2326
2349
  tabBackends.delete(migratedFrom);
2327
2350
  headlessTabs.delete(migratedFrom);
2328
2351
  workflowTargets.clear(migratedFrom);
2352
+ // Invalidate any in-flight set_workflow_target(pinned) resolution captured under
2353
+ // the retired id: dropping its sequence makes isCurrent() false, so a late async
2354
+ // pin can no longer write a stale target / emit a late ack that the bridge's
2355
+ // migration map would deliver to the new tab (codex race, tab-id migration edge).
2356
+ workflowTargetSeq.delete(migratedFrom);
2357
+ tabStableKey.delete(migratedFrom); // recomputed for the new id below (#570)
2329
2358
  }
2330
2359
  // Blind content mode rides the hello (issue #90) so the FIRST agent spawn
2331
2360
  // already carries the right tool-server env. A CHANGE against a live
@@ -2371,6 +2400,53 @@ export async function runPanelOrchestrator() {
2371
2400
  const resume = typeof event.resume === "string" ? event.resume : undefined;
2372
2401
  if (resume && (!prev || prev === backend))
2373
2402
  manager.setResume(key, resume);
2403
+ // #570: an UNSAVED workflow's tab id is an ephemeral tmp:<uuid>, regenerated
2404
+ // on every panel reload — so on an orchestrator restart that also reloads the
2405
+ // panel, the tab returns under a never-stored id and forgets everything
2406
+ // (neither our tab-keyed store nor the panel's tab-keyed hello.resume can hit).
2407
+ // Anchor a STABLE resume key on what DOES survive that tab's reload — the
2408
+ // ComfyUI origin + workflow title + backend — and seed it as a fallback.
2409
+ // Saved workflows (wf:<path>) already key stably, so this is tmp:-only.
2410
+ if (panelTab.startsWith("tmp:")) {
2411
+ const origin = (typeof helloUrl === "string" && helloUrl.trim() ? helloUrl.trim() : undefined) ??
2412
+ bridge.tabOrigin(panelTab) ??
2413
+ "";
2414
+ const title = typeof event.title === "string" ? event.title : "";
2415
+ const skey = `tmp::${origin}::${title}::${backend}`;
2416
+ tabStableKey.set(panelTab, skey);
2417
+ // Seed the resume fallback ONLY when the panel supplied none and no live
2418
+ // agent owns the key. spawn() prefers the exact-tab store hit over this
2419
+ // pendingResume, so the precise path is never overridden — this only
2420
+ // rescues the churned tmp: id. setResume() no-ops if a live agent exists.
2421
+ //
2422
+ // COLLISION GUARD: origin+title+backend is NOT unique — two unsaved tabs
2423
+ // with the same (default) title collide. Seed only when THIS tab is the sole
2424
+ // connected holder of the key, so a fresh sibling tab can never resume
2425
+ // another CONCURRENTLY-live unsaved tab's conversation (the cross-tab hijack
2426
+ // the migration path also refuses; setStable poisons a key the moment two
2427
+ // live tabs write distinct sessions to it). When ambiguous we surface fresh —
2428
+ // a lost resume is a mild miss; resuming the WRONG conversation is not.
2429
+ //
2430
+ // The SEQUENTIAL same-title case (tab A closed, a later tab B opens with the
2431
+ // same origin+title+backend) intentionally resumes A: by the only identity
2432
+ // that survives a reload — the workflow identity the issue itself names as the
2433
+ // key — B *is* the same workspace. This is bounded by the GC TTL (an abandoned
2434
+ // session ages out) and always yields to the exact-tab store and the panel's
2435
+ // own hello.resume. A truly-unique panel per-instance id (referenced in #568/
2436
+ // #570's thread) would let us tighten even this — a clean future upgrade.
2437
+ if (!resume && !manager.hasLiveAgent(key) && sessionStore.get(key) === undefined) {
2438
+ let sameKeyTabs = 0;
2439
+ for (const t of bridge.tabs()) {
2440
+ if (tabStableKey.get(t.tab_id) === skey)
2441
+ sameKeyTabs += 1;
2442
+ }
2443
+ if (sameKeyTabs <= 1) {
2444
+ const stableSid = sessionStore.getStable(skey);
2445
+ if (stableSid)
2446
+ manager.setResume(key, stableSid);
2447
+ }
2448
+ }
2449
+ }
2374
2450
  // Live model list for the picker; SDK slash commands are Claude-only.
2375
2451
  pushModels(panelTab);
2376
2452
  // Truthful provider readiness (this machine runs the agents), so the
@@ -2607,10 +2683,48 @@ export async function runPanelOrchestrator() {
2607
2683
  bridge.push({ type: "ack", ok: false, kind: "workflow_target", message: "path required when pinning" }, panelTab);
2608
2684
  return;
2609
2685
  }
2610
- const target = workflowTargets.set(panelTab, { mode, path, filename });
2611
- bridge.push({ type: "ack", ok: true, kind: "workflow_target", target }, panelTab);
2612
- bridge.push({ type: "workflow_target", target }, panelTab);
2613
- logger.info(`[panel-orchestrator] tab ${panelTab.slice(0, 8)} workflow target → ${target.mode}${target.path ? ` (${target.path})` : ""}`);
2686
+ // Every target event bumps the tab's sequence so a later selection always wins over
2687
+ // an in-flight (async) pin resolution.
2688
+ const seq = (workflowTargetSeq.get(panelTab) ?? 0) + 1;
2689
+ workflowTargetSeq.set(panelTab, seq);
2690
+ const isCurrent = () => workflowTargetSeq.get(panelTab) === seq;
2691
+ const ackTarget = (t) => {
2692
+ bridge.push({ type: "ack", ok: true, kind: "workflow_target", target: t }, panelTab);
2693
+ bridge.push({ type: "workflow_target", target: t }, panelTab);
2694
+ logger.info(`[panel-orchestrator] tab ${panelTab.slice(0, 8)} workflow target → ${t.mode}${t.path ? ` (${t.path})` : ""}`);
2695
+ };
2696
+ // A PINNED target must clear the SAME validation as the MCP tool
2697
+ // (panel_set_workflow_target) — otherwise this panel-driven event path would be a
2698
+ // bypass that re-admits #556/#571 (background pin) and #259 (not-open pin). Resolve
2699
+ // async through the shared helper, failing at pin time before the store is written.
2700
+ if (mode === "pinned") {
2701
+ void (async () => {
2702
+ const ctx = makePanelToolCtx(bridge, panelTab, workflowTargets);
2703
+ const res = await resolvePinTarget(ctx, String(path), filename);
2704
+ // Superseded by a newer target event while we were validating — drop silently
2705
+ // (no write, no late ack) so the newer selection is never clobbered.
2706
+ if (!isCurrent())
2707
+ return;
2708
+ if (!res.ok) {
2709
+ bridge.push({ type: "ack", ok: false, kind: "workflow_target", message: res.error }, panelTab);
2710
+ return;
2711
+ }
2712
+ ackTarget(workflowTargets.set(panelTab, { mode: "pinned", path: res.pinPath, filename: res.pinFilename }));
2713
+ })().catch((err) => {
2714
+ if (!isCurrent())
2715
+ return;
2716
+ bridge.push({
2717
+ type: "ack",
2718
+ ok: false,
2719
+ kind: "workflow_target",
2720
+ message: `Could not pin workflow: ${err instanceof Error ? err.message : String(err)}`,
2721
+ }, panelTab);
2722
+ });
2723
+ return;
2724
+ }
2725
+ // mode === "current" — no target to validate; follow the active tab. Writes
2726
+ // synchronously and is the latest sequence, so it wins over any in-flight pin.
2727
+ ackTarget(workflowTargets.set(panelTab, { mode, path, filename }));
2614
2728
  return;
2615
2729
  }
2616
2730
  // Live panel config: render-stall threshold, plus the user's agent-model
@@ -3067,6 +3181,12 @@ export async function runPanelOrchestrator() {
3067
3181
  // reset() is synchronous (map cleared now), so no concurrent send() can
3068
3182
  // spawn an agent before we report the cleared session.
3069
3183
  manager.reset(agentKeyFor(tabId));
3184
+ // reset() clears the exact-tab store; the stable resume index (#570) is the
3185
+ // manager's blind spot, so drop it here too — a deliberate NEW chat must not
3186
+ // be resurrected by the unsaved-workflow fallback on the next reload.
3187
+ const sk = tabStableKey.get(tabId);
3188
+ if (sk)
3189
+ sessionStore.clearStable(sk);
3070
3190
  bridge.push({ type: "session", session_id: null }, tabId);
3071
3191
  bridge.push({ type: "ack", ok: true, kind: "new_session" }, tabId);
3072
3192
  bridge.broadcastTabList(); // session cleared → mirror pickers' green dot off
@@ -3309,6 +3429,37 @@ export async function runPanelOrchestrator() {
3309
3429
  // a downloading row that stops updating for 60s is treated as a dead writer.
3310
3430
  const DOWNLOAD_LINGER_MS = 8000;
3311
3431
  const downloadRemoveAt = new Map();
3432
+ // Download-completion agent events (#547). A finished render already wakes the
3433
+ // agent (manager.injectEvent kind:"executed"); a finished DOWNLOAD had no
3434
+ // equivalent, so a "download then use the model" task stalled until the user
3435
+ // poked it. We observe the SAME first-terminal transition the tray-prune timer
3436
+ // uses and inject a completion event to the tab's agent — but COALESCED: an
3437
+ // apply_manifest that pulls many files would otherwise fire one turn per file,
3438
+ // so completions accumulate per agent for a short window and flush as ONE event.
3439
+ const DOWNLOAD_DONE_DEBOUNCE_MS = 1500;
3440
+ // agentKey → { download identity → {name, terminal status} } accumulated since
3441
+ // the last flush, plus the epoch-ms deadline (extended by each new completion)
3442
+ // at which we emit. Keyed by download IDENTITY (row.id), not display name, so
3443
+ // two distinct downloads sharing a filename in one batch don't overwrite each
3444
+ // other and hide a failure (codex).
3445
+ const downloadDonePending = new Map();
3446
+ // Resolve which agent to wake for a settled download row: the stamped tab's
3447
+ // agent when it's still live; else the SINGLE live agent (pre-fix/in-process
3448
+ // rows carry no tab, AND a tab-id migration/backend change can leave the
3449
+ // stamped tab's key no longer resolving to the live agent — codex); else none —
3450
+ // never fan out to unrelated tabs (#547).
3451
+ const resolveDownloadAgentKey = (row) => {
3452
+ const tab = typeof row.tab === "string" ? row.tab.trim() : "";
3453
+ if (tab) {
3454
+ const key = agentKeyFor(tab);
3455
+ if (manager.hasLiveAgent(key))
3456
+ return key;
3457
+ // Stamped tab's agent is gone (migration/backend switch) — fall through to
3458
+ // the single-live-agent fallback rather than silently dropping the event.
3459
+ }
3460
+ const live = manager.liveKeys();
3461
+ return live.length === 1 ? live[0] : null;
3462
+ };
3312
3463
  /** Boolean URL probe with a timeout — readiness checks for pending pod connects. */
3313
3464
  const probeOk = async (url, timeoutMs = 8_000) => {
3314
3465
  const ctl = new AbortController();
@@ -3417,6 +3568,19 @@ export async function runPanelOrchestrator() {
3417
3568
  const due = downloadRemoveAt.get(full);
3418
3569
  if (due == null) {
3419
3570
  downloadRemoveAt.set(full, now + DOWNLOAD_LINGER_MS); // start the linger
3571
+ // FIRST terminal observation of this download (due was unset) — the
3572
+ // exact once-per-download moment. Wake the tab's agent with the result
3573
+ // (#547), coalesced via downloadDonePending so a many-file manifest is
3574
+ // one turn, not N.
3575
+ const key = resolveDownloadAgentKey(row);
3576
+ if (key && manager.hasLiveAgent(key)) {
3577
+ const bucket = downloadDonePending.get(key) ??
3578
+ { downloads: new Map(), flushAt: 0 };
3579
+ const idKey = String(row.id ?? full);
3580
+ bucket.downloads.set(idKey, { name: String(row.name ?? row.id ?? "model"), status: String(status) });
3581
+ bucket.flushAt = now + DOWNLOAD_DONE_DEBOUNCE_MS;
3582
+ downloadDonePending.set(key, bucket);
3583
+ }
3420
3584
  }
3421
3585
  else if (now >= due) {
3422
3586
  try {
@@ -3450,6 +3614,16 @@ export async function runPanelOrchestrator() {
3450
3614
  lastDownloadSnapshot = snapshot;
3451
3615
  bridge.push({ type: "download_progress", downloads }); // broadcast to all tabs
3452
3616
  }
3617
+ // Flush any download-completion buckets whose debounce window has elapsed —
3618
+ // ONE agent event per tab per batch of settled downloads (#547). Runs every
3619
+ // tick (700ms) so a flush always fires shortly after the last file settles.
3620
+ for (const [key, bucket] of [...downloadDonePending]) {
3621
+ if (now < bucket.flushAt)
3622
+ continue;
3623
+ downloadDonePending.delete(key);
3624
+ const settled = [...bucket.downloads.values()];
3625
+ manager.injectEvent(key, { kind: "download_done", downloads: settled });
3626
+ }
3453
3627
  // MCP-child control channel (#269): runpod_* tools that ran in spawned
3454
3628
  // agent children ask the orchestrator to retarget / watch / unwatch /
3455
3629
  // auto-connect here — through the SAME applyComfyuiUrl fan-out as a panel