comfy_get_output_images
Retrieve recently generated AI images from ComfyUI's output directory, providing accessible file paths for Claude Desktop to work with your image generation results.
Instructions
List recent output images from ComfyUI's output folder. Returns full Windows paths that Claude Desktop can read.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | ||
| sort | No | newest | |
| filter | No |
Input Schema (JSON Schema)
{
"properties": {
"filter": {
"type": "string"
},
"limit": {
"default": 20,
"type": "integer"
},
"sort": {
"default": "newest",
"enum": [
"newest",
"oldest",
"name"
],
"type": "string"
}
},
"type": "object"
}
Implementation Reference
- src/tools/utils.ts:41-63 (handler)MCP tool handler function that processes input parameters, retrieves output images using the filesystem utility, and returns the result formatted as MCP content with error handling.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 filesystem utility that scans ComfyUI's output directory for image files, applies filtering and sorting based on parameters, and returns metadata for up to the specified number of images.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:129-133 (schema)Zod schema defining the input validation for the comfy_get_output_images tool, including optional limit, sort order, and filter parameters.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() });
- src/server.ts:135-139 (registration)Registration of the comfy_get_output_images tool in the MCP server's listTools handler, 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-189 (registration)Dispatcher case in the MCP server's CallToolRequest handler that routes calls to comfy_get_output_images to the appropriate handler function.case 'comfy_get_output_images': return await handleGetOutputImages(args as any);