Skip to main content
Glama

generate_variations

Generate multiple versions of a text prompt by varying the seed to explore different outcomes and select the best result.

Instructions

Generate multiple variations of the same prompt by varying the seed. Useful for picking the best result or exploring a concept.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYesText prompt for the base image
countNoNumber of variations to generate
negative_promptNo
widthNo
heightNo
stepsNo
cfgNo
base_seedNoStarting seed; subsequent variations use base_seed + i
checkpointNo

Implementation Reference

  • The 'generate_variations' tool handler. Generates multiple image variations by calling client.generate() with different seeds (base_seed + i). Uses Promise.all to run all variations concurrently. Returns image URLs from ComfyUI.
    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,
        );
      },
    );
  • Zod schema for 'generate_variations' input validation. Defines prompt, count (2-16, default 4), negative_prompt, width, height, steps, cfg, base_seed, and checkpoint.
    const generateVariationsSchema = {
      prompt: z.string().min(1).describe("Text prompt for the base image"),
      count: z
        .number()
        .int()
        .min(2)
        .max(16)
        .default(4)
        .describe("Number of variations to generate"),
      negative_prompt: z.string().optional(),
      width: z.number().int().min(64).max(2048).default(1024),
      height: z.number().int().min(64).max(2048).default(1024),
      steps: z.number().int().min(1).max(150).default(25),
      cfg: z.number().min(1).max(30).default(7),
      base_seed: z
        .number()
        .int()
        .optional()
        .describe("Starting seed; subsequent variations use base_seed + i"),
      checkpoint: z.string().optional(),
    };
  • The registerGenerateTools() function registers all generate tools (including 'generate_variations') on the McpServer via server.tool(). 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 ComfyUIClient.generate() helper that each variation call invokes. It creates a txt2img workflow and runs it via runWorkflow().
    async generate(params: GenerateParams): Promise<GenerateResult> {
      const workflow = txt2img({
        prompt: params.prompt,
        negativePrompt: params.negativePrompt ?? "",
        width: params.width ?? 1024,
        height: params.height ?? 1024,
        steps: params.steps ?? 25,
        cfg: params.cfg ?? 7,
        seed: params.seed ?? Math.floor(Math.random() * 2 ** 32),
        checkpoint: params.checkpoint ?? DEFAULT_CHECKPOINT,
      });
      return this.runWorkflow(workflow);
    }
  • The txt2img() workflow builder that constructs the ComfyUI node graph used by generate_variations.
    export function txt2img(params: Txt2ImgParams): Workflow {
      return {
        "3": {
          class_type: "KSampler",
          inputs: {
            seed: params.seed,
            steps: params.steps,
            cfg: params.cfg,
            sampler_name: "euler",
            scheduler: "normal",
            denoise: 1,
            model: ["4", 0],
            positive: ["6", 0],
            negative: ["7", 0],
            latent_image: ["5", 0],
          },
        },
        "4": {
          class_type: "CheckpointLoaderSimple",
          inputs: { ckpt_name: params.checkpoint },
        },
        "5": {
          class_type: "EmptyLatentImage",
          inputs: { width: params.width, height: params.height, batch_size: 1 },
        },
        "6": {
          class_type: "CLIPTextEncode",
          inputs: { text: params.prompt, clip: ["4", 1] },
        },
        "7": {
          class_type: "CLIPTextEncode",
          inputs: { text: params.negativePrompt, clip: ["4", 1] },
        },
        "8": {
          class_type: "VAEDecode",
          inputs: { samples: ["3", 0], vae: ["4", 2] },
        },
        "9": {
          class_type: "SaveImage",
          inputs: { filename_prefix: "comfyui-mcp", images: ["8", 0] },
        },
      };
    }
Behavior2/5

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

No annotations are provided, so the description bears full responsibility for behavioral disclosure. It only mentions seed variation, omitting details like whether it uses the same model, order of returns, or any rate limits. For a generative tool with no output schema, more clarity is needed.

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 at two sentences with no wasted words. It is front-loaded with the core action, making it easy to parse quickly.

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

Completeness2/5

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

Given the tool's complexity (9 parameters, no output schema, no annotations), the description is too minimal. It explains the main purpose but lacks details on parameter usage, expected return values, and when alternatives are preferable. Significant gaps remain for an agent to use it correctly without additional context.

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

Parameters2/5

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

Schema description coverage is only 33% (3 of 9 parameters described). The description adds context for seed-related parameters (base_seed, count) but does not explain others like negative_prompt, width, height, steps, cfg, or checkpoint. Since coverage is low, the description should compensate but fails to do so for most parameters.

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 generates multiple variations of a prompt by varying the seed. It differentiates from siblings like 'generate_image' which produces a single image, and 'generate_with_controlnet' which uses control conditions.

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?

Description notes usefulness for 'picking the best result or exploring a concept', providing some guidance. However, it does not explicitly state when not to use this tool versus alternatives like 'generate_image' or 'generate_with_workflow', leaving ambiguity.

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