Skip to main content
Glama

save_workflow_template

Save a ComfyUI workflow as a named template for later use. Prevent accidental overwrites with an optional overwrite flag.

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 function for the 'save_workflow_template' tool. It validates the name, checks if template exists, optionally overwrites, creates/updates a StoredTemplate record, and writes to disk as JSON.
    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}`,
            },
          ],
        };
      },
  • Zod schema for the 'save_workflow_template' tool inputs: 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-48 (registration)
    Registration call: registerTemplateTools(s, client, templateStore) wire up the tool in the MCP server.
    registerTemplateTools(s, client, templateStore);
  • The registerTemplateTools function that calls server.tool('save_workflow_template', ...) to register the tool with the MCP server.
    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}`,
              },
            ],
          };
        },
      );
  • StoredTemplate interface defining the shape of saved template data (name, description, createdAt, updatedAt, workflow).
    interface StoredTemplate {
      name: string;
      description?: string;
      createdAt: string;
      updatedAt: string;
      workflow: Workflow;
    }
Behavior3/5

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

With no annotations, the description must convey behavioral traits. It indicates overwrite behavior and that the operation is a save (mutation). But it lacks details on validation, error handling, or permission requirements, which are important for safe invocation.

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?

The description is extremely concise: one clear sentence and a short statement about overwrites. Every word adds value without repetition.

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

Completeness4/5

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

Given the low complexity (4 params, no enums, no output schema), the description covers the essential purpose and a key behavioral trait. Missing return value info, but for a save operation it's acceptable.

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 schema already documents parameters with descriptions. The description adds minimal extra meaning ('workflow JSON', 'named slot'). Baseline score is appropriate as schema does the heavy lifting.

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 action (save), the resource (ComfyUI workflow JSON to template registry), and the slot mechanism. It distinguishes from sibling tools like delete and get by specifying 'save' and 'template registry'.

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 mentions that overwrites are disabled by default, providing some usage guidance. However, it does not explicitly state when to use this tool versus alternatives (e.g., run_workflow_template for execution) or when not to use it.

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