comfy_cancel_generation
Stop ongoing image generation tasks in ComfyUI to manage workflow execution and queue processing. Remove queued generations to optimize resource usage.
Instructions
Cancel a specific generation or interrupt the currently executing generation. Can optionally remove from queue.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| prompt_id | No | ||
| delete_from_queue | No |
Input Schema (JSON Schema)
{
"properties": {
"delete_from_queue": {
"default": true,
"type": "boolean"
},
"prompt_id": {
"type": "string"
}
},
"type": "object"
}
Implementation Reference
- src/tools/queue.ts:49-102 (handler)The handler function that implements the logic for the 'comfy_cancel_generation' tool. It uses the ComfyUI client to interrupt the current generation or cancel a specific prompt_id, optionally deleting it from the queue. Returns success or error messages in MCP format.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 defining the input parameters for the 'comfy_cancel_generation' tool: optional prompt_id to cancel specific generation, and optional delete_from_queue flag.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 MCP server's listTools handler, defining name, description, and input schema for 'comfy_cancel_generation'.{ 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)Dispatch case in the MCP server's CallToolRequestHandler switch statement that routes calls to 'comfy_cancel_generation' to the handleCancelGeneration function.case 'comfy_cancel_generation': return await handleCancelGeneration(args as any);