Skip to main content
Glama

comfy_wait_for_completion

Monitor ComfyUI image generation progress and retrieve final outputs. This tool blocks execution until workflows complete or fail, returning image paths for synchronous processing.

Instructions

Block until a generation completes or fails. Returns final outputs with image paths. Useful for synchronous workflows.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
prompt_idYes
timeoutNo
poll_intervalNo

Implementation Reference

  • The core handler function for 'comfy_wait_for_completion'. Polls ComfyUI's history for the specified prompt_id until completion or timeout, then extracts and returns image output paths.
    export async function handleWaitForCompletion(input: WaitForCompletionInput) {
      try {
        const client = getComfyUIClient();
        const config = getConfig();
        const pollInterval = input.poll_interval || config.comfyui.poll_interval;
        const timeout = input.timeout || config.comfyui.timeout;
        const startTime = Date.now();
    
        // Poll for completion
        while (true) {
          const elapsed = (Date.now() - startTime) / 1000;
          if (elapsed > timeout) {
            return {
              content: [{
                type: "text",
                text: JSON.stringify({
                  prompt_id: input.prompt_id,
                  status: "timeout",
                  execution_time: elapsed,
                  message: `Timeout after ${timeout} seconds`
                }, null, 2)
              }]
            };
          }
    
          // Check history
          const history = await client.getHistory(input.prompt_id);
    
          if (history[input.prompt_id]) {
            // Completed
            const historyItem = history[input.prompt_id];
            const outputs: any[] = [];
    
            if (historyItem.outputs) {
              for (const [nodeId, output] of Object.entries(historyItem.outputs)) {
                if (output.images) {
                  const imagePaths = output.images.map((img: any) =>
                    client.getOutputPath(img.filename)
                  );
                  outputs.push({
                    images: imagePaths,
                    node_id: nodeId,
                    filename: output.images.map((img: any) => img.filename).join(', ')
                  });
                }
              }
            }
    
            return {
              content: [{
                type: "text",
                text: JSON.stringify({
                  prompt_id: input.prompt_id,
                  status: "completed",
                  outputs,
                  execution_time: elapsed
                }, null, 2)
              }]
            };
          }
    
          // Wait before next poll
          await new Promise(resolve => setTimeout(resolve, pollInterval * 1000));
        }
      } catch (error: any) {
        if (error.error) {
          return {
            content: [{
              type: "text",
              text: JSON.stringify(error, null, 2)
            }],
            isError: true
          };
        }
    
        return {
          content: [{
            type: "text",
            text: JSON.stringify(ComfyUIErrorBuilder.executionError(error.message), null, 2)
          }],
          isError: true
        };
      }
    }
  • Zod schema defining the input parameters for the tool: prompt_id (required string), timeout (optional number, default 300s), poll_interval (optional number, default 2s).
    // Wait for Completion Tool
    export const WaitForCompletionSchema = z.object({
      prompt_id: z.string(),
      timeout: z.number().optional().default(300),
      poll_interval: z.number().optional().default(2)
    });
  • src/server.ts:82-86 (registration)
    Tool registration in the MCP server's listTools handler, specifying name, description, and input schema.
    {
      name: 'comfy_wait_for_completion',
      description: 'Block until a generation completes or fails. Returns final outputs with image paths. Useful for synchronous workflows.',
      inputSchema: zodToJsonSchema(WaitForCompletionSchema) as any,
    },
  • src/server.ts:158-159 (registration)
    Dispatch case in the CallToolRequest handler that routes calls to the implementation.
    case 'comfy_wait_for_completion':
      return await handleWaitForCompletion(args as any);
Behavior3/5

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

No annotations are provided, so the description carries the full burden. It discloses key behavioral traits: blocking behavior, handling of completion/failure outcomes, and return of image paths. However, it lacks details on error handling, rate limits, authentication needs, or what happens on timeout (though timeout is a parameter). For a tool with no annotations, this is a moderate disclosure but misses some operational context.

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 highly concise and well-structured: two sentences that front-load the core functionality ('Block until...') and follow with a usage note ('Useful for...'). Every word earns its place with no redundancy or fluff, making it efficient and clear.

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

Completeness3/5

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

Given the tool's complexity (blocking wait with 3 parameters), no annotations, no output schema, and 0% schema coverage, the description is moderately complete. It covers the main purpose and usage context but lacks details on parameters, return values (beyond 'image paths'), error cases, or sibling tool comparisons. For a tool with these gaps, it provides a basic but incomplete picture.

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 description coverage is 0%, so the schema provides no parameter descriptions. The description adds no explicit parameter semantics—it doesn't explain prompt_id, timeout, or poll_interval. However, it implies the purpose of waiting for a generation, which relates to prompt_id. With 0% coverage and 3 parameters, the description compensates minimally, meeting the baseline for moderate schema coverage gaps.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Block until a generation completes or fails. Returns final outputs with image paths.' This specifies the verb (block/wait), resource (generation), and outcome (completion/failure with outputs). It distinguishes from siblings like comfy_get_status (check status without blocking) and comfy_get_output_images (retrieve images without waiting). However, it doesn't explicitly name these siblings for differentiation, keeping it at 4.

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 provides implied usage guidance: 'Useful for synchronous workflows.' This suggests when to use it (synchronous contexts) but doesn't explicitly state when not to use it or name alternatives like comfy_get_status for non-blocking checks. No prerequisites or exclusions are mentioned, leaving some gaps in guidance.

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/Nikolaibibo/claude-comfyui-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server