Skip to main content
Glama

save_workflow_template

Save a ComfyUI workflow JSON to the server's template registry under a named slot. Use to store and retrieve workflow configurations. Overwrite disabled by default to prevent accidental replacement.

Instructions

Save a ComfyUI workflow JSON to the server's template registry under a named slot. Overwrites are disabled by default.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesTemplate name. Letters, digits, '-', '_'; max 64 chars. Must start alphanumeric.
workflowYesComplete ComfyUI workflow JSON (from ComfyUI's 'Save (API Format)').
descriptionNo
overwriteNoAllow overwriting an existing template with the same name.

Implementation Reference

  • The handler for the save_workflow_template tool. Validates the name, checks if template already exists, optionally overwrites, reads prior createdAt, and writes StoredTemplate JSON to disk.
    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}`,
            },
          ],
        };
      },
    );
  • Input schema (saveSchema) for save_workflow_template: name (string), workflow (record), description (optional string), overwrite (boolean, default false).
    const saveSchema = {
      name: z
        .string()
        .describe(
          "Template name. Letters, digits, '-', '_'; max 64 chars. Must start alphanumeric.",
        ),
      workflow: z
        .record(z.string(), z.any())
        .describe(
          "Complete ComfyUI workflow JSON (from ComfyUI's 'Save (API Format)').",
        ),
      description: z.string().optional(),
      overwrite: z
        .boolean()
        .default(false)
        .describe("Allow overwriting an existing template with the same name."),
    };
  • src/server.ts:48-49 (registration)
    Registration call: registerTemplateTools(s, client, templateStore) wires up the tool on the MCP server.
    registerTemplateTools(s, client, templateStore);
    return s;
  • The registerTemplateTools export that calls server.tool(...) to register save_workflow_template and other template tools.
    export function registerTemplateTools(
      server: McpServer,
      client: ComfyUIClient,
      store: TemplateStore,
    ): void {
  • Helper utilities: TEMPLATE_NAME_PATTERN regex, validateName(), templatePath(), ensureTemplatesDir(), TemplateStore interface, StoredTemplate interface, defaultTemplatesDir().
    const TEMPLATE_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/;
    
    export interface TemplateStore {
      dir: string;
    }
    
    export async function ensureTemplatesDir(dir: string): Promise<void> {
      await fs.mkdir(dir, { recursive: true });
    }
    
    function templatePath(dir: string, name: string): string {
      return path.join(dir, `${name}.json`);
    }
    
    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.`,
        );
      }
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided, so description carries burden. It discloses that overwrites are disabled by default, but does not detail side effects of overwriting, error handling, or authentication needs.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two sentences, no filler, front-loaded with key action. Every word adds value.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a save operation with 4 params and no output schema, the description covers core action but lacks details on success response or error cases. Acceptable but could be more informative.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 75%, and the description adds little beyond schema (e.g., 'under a named slot' reinforces but doesn't add new meaning). The 'description' parameter lacks schema description and is not elaborated.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'save', the resource 'ComfyUI workflow JSON', and the destination 'template registry under a named slot'. It distinguishes from sibling tools like 'run_workflow_template' and 'delete_workflow_template' by focusing on saving.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies use when saving a workflow as a template and mentions overwrite behavior, but does not explicitly state when not to use or compare with siblings. No guidance on prerequisites or alternatives.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/miller-joe/comfyui-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server