delete_workflow_template
Delete a saved workflow template from ComfyUI by providing its name, enabling you to manage and remove unused templates from your collection.
Instructions
Delete a saved workflow template.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Template name to delete. |
Implementation Reference
- src/tools/templates.ts:198-215 (handler)The handler function for the 'delete_workflow_template' tool. It validates the template name, deletes the file using fs.unlink, and returns a success message.
server.tool( "delete_workflow_template", "Delete a saved workflow template.", deleteSchema, async (args) => { validateName(args.name); try { await fs.unlink(templatePath(store.dir, args.name)); } catch { throw new Error(`Template "${args.name}" not found.`); } return { content: [ { type: "text" as const, text: `Deleted template "${args.name}".` }, ], }; }, ); - src/tools/templates.ts:62-64 (schema)Input schema for delete_workflow_template, requiring a 'name' string describing the template name to delete.
const deleteSchema = { name: z.string().describe("Template name to delete."), }; - src/tools/templates.ts:198-215 (registration)The tool is registered via server.tool('delete_workflow_template', ...) inside the registerTemplateTools function.
server.tool( "delete_workflow_template", "Delete a saved workflow template.", deleteSchema, async (args) => { validateName(args.name); try { await fs.unlink(templatePath(store.dir, args.name)); } catch { throw new Error(`Template "${args.name}" not found.`); } return { content: [ { type: "text" as const, text: `Deleted template "${args.name}".` }, ], }; }, ); - src/tools/templates.ts:70-215 (registration)The registerTemplateTools function (exported) registers all template tools including delete_workflow_template on the McpServer.
export function registerTemplateTools( server: McpServer, client: ComfyUIClient, store: TemplateStore, ): void { server.tool( "save_workflow_template", "Save a ComfyUI workflow JSON to the server's template registry under a named slot. Overwrites are disabled by default.", saveSchema, async (args) => { validateName(args.name); const file = templatePath(store.dir, args.name); let existed = false; try { await fs.access(file); existed = true; } catch { existed = false; } if (existed && !args.overwrite) { throw new Error( `Template "${args.name}" already exists. Pass overwrite=true to replace it.`, ); } const now = new Date().toISOString(); let createdAt = now; if (existed) { try { const prior = JSON.parse( await fs.readFile(file, "utf-8"), ) as StoredTemplate; createdAt = prior.createdAt ?? now; } catch { // ignore parse failure, treat as fresh create } } const record: StoredTemplate = { name: args.name, description: args.description, createdAt, updatedAt: now, workflow: args.workflow as Workflow, }; await fs.writeFile(file, JSON.stringify(record, null, 2)); return { content: [ { type: "text" as const, text: existed ? `Updated template "${args.name}" at ${file}` : `Saved template "${args.name}" at ${file}`, }, ], }; }, ); server.tool( "list_workflow_templates", "List all saved workflow templates in the registry.", listSchema, async () => { let entries: string[]; try { entries = await fs.readdir(store.dir); } catch { return { content: [ { type: "text" as const, text: `No templates directory at ${store.dir} yet.`, }, ], }; } const names = entries .filter((f) => f.endsWith(".json")) .map((f) => f.replace(/\.json$/, "")); if (names.length === 0) { return { content: [ { type: "text" as const, text: "No templates saved yet." }, ], }; } const rows: string[] = []; for (const name of names.sort()) { try { const raw = await fs.readFile( templatePath(store.dir, name), "utf-8", ); const t = JSON.parse(raw) as StoredTemplate; const desc = t.description ? ` — ${t.description}` : ""; rows.push(` ${t.name}${desc} (updated ${t.updatedAt})`); } catch { rows.push(` ${name} (unreadable)`); } } return { content: [ { type: "text" as const, text: `Saved templates (${names.length}) in ${store.dir}:\n${rows.join("\n")}`, }, ], }; }, ); server.tool( "get_workflow_template", "Fetch a saved workflow template's JSON and metadata.", getSchema, async (args) => { validateName(args.name); let raw: string; try { raw = await fs.readFile(templatePath(store.dir, args.name), "utf-8"); } catch { throw new Error(`Template "${args.name}" not found.`); } return { content: [{ type: "text" as const, text: raw }], }; }, ); server.tool( "delete_workflow_template", "Delete a saved workflow template.", deleteSchema, async (args) => { validateName(args.name); try { await fs.unlink(templatePath(store.dir, args.name)); } catch { throw new Error(`Template "${args.name}" not found.`); } return { content: [ { type: "text" as const, text: `Deleted template "${args.name}".` }, ], }; }, ); - src/tools/templates.ts:22-28 (helper)validateName helper used to validate template names before deletion.
function validateName(name: string): void { if (!TEMPLATE_NAME_PATTERN.test(name)) { throw new Error( `Invalid template name "${name}". Must start with alphanumeric; only letters, digits, '-', '_' allowed; max 64 chars.`, ); } }