Skip to main content
Glama

generate_with_workflow

Submit a ComfyUI workflow JSON to generate images. Returns image URLs for custom node graphs like ControlNet or upscaling.

Instructions

Submit an arbitrary ComfyUI workflow (full node graph) and return the resulting image URLs. Use this when you need a custom workflow like ControlNet, upscaling, or a node graph exported from ComfyUI's 'Save (API Format)'.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
workflowYesComplete ComfyUI workflow JSON (node graph as returned by ComfyUI's 'Save (API Format)' export)

Implementation Reference

  • Zod schema for generate_with_workflow: accepts a 'workflow' field which is a record of strings to any (the complete ComfyUI workflow JSON node graph).
    const generateWithWorkflowSchema = {
      workflow: z
        .record(z.string(), z.any())
        .describe(
          "Complete ComfyUI workflow JSON (node graph as returned by ComfyUI's 'Save (API Format)' export)",
        ),
    };
  • Handler for generate_with_workflow tool. Casts args.workflow to Workflow type, calls client.runWorkflow(workflow), and returns image URLs with prompt_id.
    server.tool(
      "generate_with_workflow",
      "Submit an arbitrary ComfyUI workflow (full node graph) and return the resulting image URLs. Use this when you need a custom workflow like ControlNet, upscaling, or a node graph exported from ComfyUI's 'Save (API Format)'.",
      generateWithWorkflowSchema,
      async (args) => {
        const workflow = args.workflow as Workflow;
        const result = await client.runWorkflow(workflow);
        return textResult(
          `Workflow submitted (prompt_id: ${result.promptId}), ${result.images.length} image(s):`,
          result.images,
        );
      },
    );
  • The registerGenerateTools function (line 76) registers all generate tools including generate_with_workflow (line 132-144) via server.tool(). It is called from server.ts line 42.
    export function registerGenerateTools(
      server: McpServer,
      client: ComfyUIClient,
    ): void {
      server.tool(
        "generate_image",
        "Generate an image from a text prompt using ComfyUI's default txt2img workflow. Returns one or more image URLs served directly by the ComfyUI instance.",
        generateImageSchema,
        async (args) => {
          const result = await client.generate({
            prompt: args.prompt,
            negativePrompt: args.negative_prompt,
            width: args.width,
            height: args.height,
            steps: args.steps,
            cfg: args.cfg,
            seed: args.seed,
            checkpoint: args.checkpoint,
          });
    
          return textResult(
            `Generated ${result.images.length} image(s) (prompt_id: ${result.promptId}):`,
            result.images,
          );
        },
      );
    
      server.tool(
        "generate_variations",
        "Generate multiple variations of the same prompt by varying the seed. Useful for picking the best result or exploring a concept.",
        generateVariationsSchema,
        async (args) => {
          const startSeed = args.base_seed ?? Math.floor(Math.random() * 2 ** 32);
          const results = await Promise.all(
            Array.from({ length: args.count }, (_, i) =>
              client.generate({
                prompt: args.prompt,
                negativePrompt: args.negative_prompt,
                width: args.width,
                height: args.height,
                steps: args.steps,
                cfg: args.cfg,
                seed: startSeed + i,
                checkpoint: args.checkpoint,
              }),
            ),
          );
    
          const urls = results.flatMap((r) => r.images);
          return textResult(
            `Generated ${args.count} variation(s) starting from seed ${startSeed}:`,
            urls,
          );
        },
      );
    
      server.tool(
        "generate_with_workflow",
        "Submit an arbitrary ComfyUI workflow (full node graph) and return the resulting image URLs. Use this when you need a custom workflow like ControlNet, upscaling, or a node graph exported from ComfyUI's 'Save (API Format)'.",
        generateWithWorkflowSchema,
        async (args) => {
          const workflow = args.workflow as Workflow;
          const result = await client.runWorkflow(workflow);
          return textResult(
            `Workflow submitted (prompt_id: ${result.promptId}), ${result.images.length} image(s):`,
            result.images,
          );
        },
      );
  • The runWorkflow method on ComfyUIClient that generate_with_workflow's handler calls. Submits the workflow via HTTP POST to /prompt, then polls /history until completion, extracting image URLs.
    async runWorkflow(workflow: Workflow): Promise<GenerateResult> {
      const { prompt_id } = await this.submit(workflow);
      const entry = await this.waitForCompletion(prompt_id);
      return {
        promptId: prompt_id,
        images: extractImageUrls(entry, this.publicUrl),
      };
    }
Behavior3/5

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

No annotations are provided, so the description carries full burden. It states the tool returns image URLs but omits details on whether the workflow runs synchronously or side effects. The description adds context beyond the schema but lacks comprehensive behavioral disclosure.

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 a single sentence followed by a usage note. It is front-loaded with the core purpose and includes a concrete example. Every word adds value.

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 tool has one complex parameter and no output schema, the description adequately explains the input format and use cases. It does not detail the return structure, but the context signals (no output schema) mitigate this. The sibling differentiation helps contextual completeness.

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

Parameters4/5

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

Schema coverage is 100% with a single parameter described. The description adds meaning by specifying the workflow JSON should be in ComfyUI's 'Save (API Format)' export format, which is not evident from the schema alone. This helps the agent construct correct input.

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 tool submits an arbitrary ComfyUI workflow and returns image URLs. It specifies the resource (ComfyUI workflow) and verb (submit), and distinguishes from siblings like run_workflow_template by focusing on custom workflows.

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

Usage Guidelines4/5

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

The description explicitly says 'Use this when you need a custom workflow like ControlNet, upscaling' providing clear context. It indirectly implies alternatives (e.g., saved templates via sibling run_workflow_template) but does not directly state 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