comfy_get_output_images
Retrieve recent generated images from ComfyUI's output folder with customizable sorting and filtering options for easy access to AI-generated content.
Instructions
List recent output images from ComfyUI's output folder. Returns full Windows paths that Claude Desktop can read.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | ||
| sort | No | newest | |
| filter | No |
Implementation Reference
- src/tools/utils.ts:41-63 (handler)MCP tool handler function that processes input, calls the getOutputImages utility, formats the response as MCP content or error.export async function handleGetOutputImages(input: GetOutputImagesInput) { try { const images = getOutputImages(input.limit, input.sort, input.filter); return { content: [{ type: "text", text: JSON.stringify({ images, total_count: images.length }, null, 2) }] }; } catch (error: any) { return { content: [{ type: "text", text: JSON.stringify(ComfyUIErrorBuilder.executionError(error.message), null, 2) }], isError: true }; } }
- src/utils/filesystem.ts:135-174 (helper)Core utility function implementing the logic to scan ComfyUI output directory, filter/sort image files, and return metadata array.export function getOutputImages(limit: number = 20, sort: 'newest' | 'oldest' | 'name' = 'newest', filter?: string): ImageInfo[] { const config = getConfig(); const outputDir = getFullPath(config.paths.output); if (!existsSync(outputDir)) { return []; } const files = readdirSync(outputDir); const images: ImageInfo[] = []; for (const file of files) { if (filter && !file.includes(filter)) continue; if (!validateImageFormat(file)) continue; const fullPath = join(outputDir, file); const stat = statSync(fullPath); if (stat.isFile()) { images.push({ filename: file, path: fullPath, size: stat.size, created_at: stat.birthtime.toISOString(), modified_at: stat.mtime.toISOString() }); } } // Sort if (sort === 'newest') { images.sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime()); } else if (sort === 'oldest') { images.sort((a, b) => new Date(a.created_at).getTime() - new Date(b.created_at).getTime()); } else { images.sort((a, b) => a.filename.localeCompare(b.filename)); } return images.slice(0, limit); }
- src/types/tools.ts:128-148 (schema)Zod schema and TypeScript type for GetOutputImagesInput defining optional parameters: limit, sort, filter.// Get Output Images Tool export const GetOutputImagesSchema = z.object({ limit: z.number().int().optional().default(20), sort: z.enum(["newest", "oldest", "name"]).optional().default("newest"), filter: z.string().optional() }); // Type exports export type SubmitWorkflowInput = z.infer<typeof SubmitWorkflowSchema>; export type GenerateSimpleInput = z.infer<typeof GenerateSimpleSchema>; export type GetStatusInput = z.infer<typeof GetStatusSchema>; export type WaitForCompletionInput = z.infer<typeof WaitForCompletionSchema>; export type ListModelsInput = z.infer<typeof ListModelsSchema>; export type SaveWorkflowInput = z.infer<typeof SaveWorkflowSchema>; export type LoadWorkflowInput = z.infer<typeof LoadWorkflowSchema>; export type ListWorkflowsInput = z.infer<typeof ListWorkflowsSchema>; export type DeleteWorkflowInput = z.infer<typeof DeleteWorkflowSchema>; export type CancelGenerationInput = z.infer<typeof CancelGenerationSchema>; export type ClearQueueInput = z.infer<typeof ClearQueueSchema>; export type UploadImageInput = z.infer<typeof UploadImageSchema>; export type GetOutputImagesInput = z.infer<typeof GetOutputImagesSchema>;
- src/server.ts:136-139 (registration)Tool registration entry in the listTools response, providing name, description, and input schema.name: 'comfy_get_output_images', description: 'List recent output images from ComfyUI\'s output folder. Returns full Windows paths that Claude Desktop can read.', inputSchema: zodToJsonSchema(GetOutputImagesSchema) as any, },
- src/server.ts:188-190 (registration)Dispatch in the CallToolRequest handler switch statement routing to the tool handler.case 'comfy_get_output_images': return await handleGetOutputImages(args as any);