Skip to main content
Glama

generate_image

Generate images from text prompts using ComfyUI, with full control over size, steps, CFG scale, and seed for reproducible results.

Instructions

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.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYesText prompt describing the image to generate
negative_promptNoWhat to avoid in the image
widthNoImage width in pixels
heightNoImage height in pixels
stepsNoNumber of diffusion steps
cfgNoCFG / prompt adherence (1-30)
seedNoSeed for reproducibility
checkpointNoCheckpoint filename (defaults to COMFYUI_DEFAULT_CKPT)

Implementation Reference

  • Registration of the 'generate_image' MCP tool via server.tool(), with its handler that calls client.generate() and formats the result.
    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,
        );
      },
    );
  • ComfyUIClient.generate() method — the core handler that builds the 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);
    }
  • Zod schema defining the input parameters for generate_image tool: prompt, negative_prompt, width, height, steps, cfg, seed, checkpoint.
    const generateImageSchema = {
      prompt: z
        .string()
        .min(1)
        .describe("Text prompt describing the image to generate"),
      negative_prompt: z.string().optional().describe("What to avoid in the image"),
      width: z
        .number()
        .int()
        .min(64)
        .max(2048)
        .default(1024)
        .describe("Image width in pixels"),
      height: z
        .number()
        .int()
        .min(64)
        .max(2048)
        .default(1024)
        .describe("Image height in pixels"),
      steps: z
        .number()
        .int()
        .min(1)
        .max(150)
        .default(25)
        .describe("Number of diffusion steps"),
      cfg: z
        .number()
        .min(1)
        .max(30)
        .default(7)
        .describe("CFG / prompt adherence (1-30)"),
      seed: z.number().int().optional().describe("Seed for reproducibility"),
      checkpoint: z
        .string()
        .optional()
        .describe("Checkpoint filename (defaults to COMFYUI_DEFAULT_CKPT)"),
    };
  • The txt2img workflow builder — constructs the ComfyUI node graph (KSampler, CheckpointLoader, EmptyLatentImage, CLIPTextEncode, VAEDecode, SaveImage) used by generate_image.
    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] },
        },
      };
    }
  • Type definitions for GenerateParams (input to client.generate()) and GenerateResult (output with image URLs).
    export interface GenerateParams {
      prompt: string;
      negativePrompt?: string;
      width?: number;
      height?: number;
      steps?: number;
      cfg?: number;
      seed?: number;
      checkpoint?: string;
    }
    
    export interface GenerateResult {
      promptId: string;
      images: string[];
    }
Behavior2/5

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

No annotations are provided, so the description should fully explain behavioral traits. However, it only states that the tool returns image URLs and uses ComfyUI. It does not disclose resource usage, persistence, idempotency, or error behavior.

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

Conciseness4/5

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

The description is concise at two sentences, with no wasted words. However, it could be more structured (e.g., separating input, output, and usage).

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 absence of annotations and output schema, the description is insufficiently complete. It lacks details on image URL format, handling of multiple images, and potential failures, which are important for a tool with 8 parameters.

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?

All 8 parameters have descriptions in the input schema (100% coverage), so the description does not need to add much. It does not provide extra context beyond what the schema already gives, earning a baseline score of 3.

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 ('generate'), the input (text prompt), the method (ComfyUI default txt2img workflow), and the output (image URLs). It also distinguishes itself from sibling tools like 'generate_variations' or 'generate_with_controlnet' by specifying the default workflow.

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 does not provide explicit guidance on when to use this tool versus alternatives. It mentions the default workflow, implying it's for basic text-to-image, but does not list alternatives or conditions for other tools.

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