comfy_cancel_generation
Cancel an active AI image generation or remove pending tasks from the ComfyUI queue to manage workflow execution.
Instructions
Cancel a specific generation or interrupt the currently executing generation. Can optionally remove from queue.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| prompt_id | No | ||
| delete_from_queue | No |
Implementation Reference
- src/tools/queue.ts:49-103 (handler)The main handler function that implements the tool logic: interrupts the ComfyUI generation using the client, optionally deletes a specific queue item by prompt_id, and returns success/error responses.export async function handleCancelGeneration(input: CancelGenerationInput) { try { const client = getComfyUIClient(); if (input.prompt_id) { // Cancel specific prompt if (input.delete_from_queue) { await client.deleteQueueItem(input.prompt_id); } await client.interrupt(); return { content: [{ type: "text", text: JSON.stringify({ cancelled: true, prompt_id: input.prompt_id, message: `Generation ${input.prompt_id} cancelled` }, null, 2) }] }; } else { // Interrupt current await client.interrupt(); return { content: [{ type: "text", text: JSON.stringify({ cancelled: true, message: "Current generation interrupted" }, null, 2) }] }; } } 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 }; } }
- src/types/tools.ts:111-114 (schema)Zod schema for input validation: optional prompt_id (to target specific generation) and delete_from_queue (default true).export const CancelGenerationSchema = z.object({ prompt_id: z.string().optional(), delete_from_queue: z.boolean().optional().default(true) });
- src/server.ts:120-124 (registration)Tool registration in the ListTools response: defines name, description, and references the input schema.{ name: 'comfy_cancel_generation', description: 'Cancel a specific generation or interrupt the currently executing generation. Can optionally remove from queue.', inputSchema: zodToJsonSchema(CancelGenerationSchema) as any, },
- src/server.ts:179-180 (registration)Switch case in CallToolRequestHandler that dispatches the tool call to the handler function.case 'comfy_cancel_generation': return await handleCancelGeneration(args as any);