Skip to main content
Glama

comfy_wait_for_completion

Monitor ComfyUI image generation progress and retrieve final outputs when complete. Use this tool to wait for prompt execution to finish and receive generated images with file paths.

Instructions

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

Input Schema

NameRequiredDescriptionDefault
prompt_idYes
timeoutNo
poll_intervalNo

Input Schema (JSON Schema)

{ "properties": { "poll_interval": { "default": 2, "type": "number" }, "prompt_id": { "type": "string" }, "timeout": { "default": 300, "type": "number" } }, "required": [ "prompt_id" ], "type": "object" }

Implementation Reference

  • The handler function for 'comfy_wait_for_completion'. Polls ComfyUI history for the given prompt_id until completion or timeout. Constructs output image paths using getOutputPath and returns JSON status with outputs.
    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 for input validation: requires prompt_id, optional timeout (default 300s), poll_interval (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 ListToolsRequestHandler, providing 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 in the CallToolRequestHandler switch statement to invoke the handler function.
    case 'comfy_wait_for_completion': return await handleWaitForCompletion(args as any);
  • TypeScript type inferred from the schema for type safety in handler.
    export type WaitForCompletionInput = z.infer<typeof WaitForCompletionSchema>;

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