UNPKG

comfyui-mcp

Version:

Local-first, agent-native control plane for ComfyUI — MCP server + autonomous sidebar agent that drives your live graph in natural language on ANY LLM: Claude/ChatGPT/Gemini on your subscription (no API key), free local models via Ollama (fully offline),

69 lines • 2.95 kB
import { basename } from "node:path"; import { discoverWorkflows, buildToolSchema, applyParams, getWorkflowsDir, } from "../services/workflow-autoload.js"; import { enqueueWorkflow } from "../services/workflow-executor.js"; import { errorToToolResult } from "../utils/errors.js"; import { logger } from "../utils/logger.js"; /** * Discover workflow JSON files in COMFYUI_WORKFLOWS_DIR (default * `~/.comfyui-mcp/workflows`) and register each as its own MCP tool with a * schema derived from its PARAM_* placeholders. Failures are logged and do * not abort startup. */ export async function registerAutoloadedWorkflows(server) { const dir = getWorkflowsDir(); let discovered; try { discovered = await discoverWorkflows(dir); } catch (err) { logger.warn("Workflow autoload discovery failed", { dir, error: err instanceof Error ? err.message : err, }); return; } if (discovered.length === 0) { logger.info("No autoloaded workflows discovered", { dir }); return; } for (const wf of discovered) { const shape = buildToolSchema(wf.placeholders); const paramSummary = wf.placeholders .map((p) => `${p.name}:${p.type}`) .filter((s, i, a) => a.indexOf(s) === i) .join(", "); const description = `Enqueue the autoloaded ComfyUI workflow "${wf.toolName}" ` + `(loaded from ${basename(wf.filePath)}) for execution and return immediately ` + `with its prompt_id and queue position — it does NOT wait for the result; ` + `poll get_job_status or get_history afterwards. Requires a running ComfyUI server. ` + `Each parameter below substitutes a PARAM_* placeholder in the saved workflow, and ` + `all parameters are required. Params: ${paramSummary || "(none)"}`; server.tool(wf.toolName, description, shape, async (args) => { try { const built = applyParams(wf.workflow, wf.placeholders, args); const result = await enqueueWorkflow(built); return { content: [ { type: "text", text: JSON.stringify({ status: "enqueued", tool: wf.toolName, prompt_id: result.prompt_id, queue_remaining: result.queue_remaining, }, null, 2), }, ], }; } catch (err) { return errorToToolResult(err); } }); logger.info("Registered autoloaded workflow tool", { tool: wf.toolName, params: wf.placeholders.length, }); } } //# sourceMappingURL=workflow-autoload.js.map