Skip to main content
Glama

generate_with_workflow

Execute a custom ComfyUI workflow by submitting its node graph JSON and receive the resulting image URLs. Supports any exported workflow 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

  • Handler function for the 'generate_with_workflow' tool. Takes a 'workflow' parameter (full ComfyUI node graph JSON), casts it to Workflow type, calls client.runWorkflow(), and returns image URLs in a text result.
    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,
        );
      },
    );
  • Input schema for 'generate_with_workflow'. Defines a single required parameter 'workflow' as a record of string to any (the 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)",
        ),
    };
  • Registration of the 'generate_with_workflow' tool via server.tool() inside registerGenerateTools(), which is called from src/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 actual workflow execution engine. runWorkflow() submits the workflow JSON to ComfyUI's /prompt endpoint and waits for completion, returning extracted 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),
      };
    }
  • Type definitions: Workflow (Record<string, WorkflowNode>) and WorkflowNode interface used by the handler to type-check the incoming workflow argument.
    export interface WorkflowNode {
      inputs: Record<string, unknown>;
      class_type: string;
      _meta?: Record<string, unknown>;
    }
    
    export type Workflow = Record<string, WorkflowNode>;
Behavior2/5

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

No annotations provided, so description must fully disclose behavior. It mentions submission and return of URLs but lacks details on mutability, error handling, or side effects, which is insufficient for a submission tool.

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 concise sentences with front-loaded main action; every phrase adds value without redundancy.

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's simplicity (one parameter, no output schema) and clear purpose, the description is mostly complete but lacks behavioral details like handling of invalid workflows or async processing.

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 100% (the one parameter has a description). The description adds no extra meaning beyond the schema's description of 'Complete ComfyUI workflow JSON'.

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?

Description clearly states the tool submits an arbitrary ComfyUI workflow and returns image URLs, with specific use cases like ControlNet and upscaling, distinguishing it from siblings like generate_image or run_workflow_template.

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?

Explicitly says 'Use this when you need a custom workflow', providing clear context for when to use, though it does not mention when not to use 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