comfy_list_models
Browse and filter available models, checkpoints, LoRAs, VAEs, and other resources in your ComfyUI models directory to select assets for AI image generation workflows.
Instructions
List available models, checkpoints, LoRAs, VAEs, and other resources in the ComfyUI models directory. Supports filtering by type and name.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| type | No | ||
| filter | No | ||
| include_size | No |
Implementation Reference
- src/tools/models.ts:5-59 (handler)The main handler function that executes the logic for the 'comfy_list_models' tool. It processes the input, calls scanModelsDirectory to list models, applies filtering and size inclusion options, formats a summary, and returns a JSON-formatted text content response.export async function handleListModels(input: ListModelsInput) { try { const type = input.type || 'all'; const filter = input.filter; const includeSize = input.include_size || false; // Scan models directory let models = scanModelsDirectory(type); // Apply filter if (filter) { const filterLower = filter.toLowerCase(); models = models.filter(model => model.name.toLowerCase().includes(filterLower) ); } // Remove size if not requested if (!includeSize) { models = models.map(({ size, ...rest }) => rest) as any; } // Generate summary const summary = `Found ${models.length} model(s)${type !== 'all' ? ` of type ${type}` : ''}${filter ? ` matching "${filter}"` : ''}`; return { content: [{ type: "text", text: JSON.stringify({ models, total_count: models.length, summary }, 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:62-82 (schema)Zod schema defining the input parameters for the 'comfy_list_models' tool: optional 'type' enum for model category, 'filter' string, and 'include_size' boolean.export const ListModelsSchema = z.object({ type: z.enum([ "checkpoints", "loras", "vae", "clip", "clip_vision", "unet", "embeddings", "upscale_models", "diffusion_models", "controlnet", "ipadapter", "style_models", "photomaker", "insightface", "all" ]).optional(), filter: z.string().optional(), include_size: z.boolean().optional().default(false) });
- src/server.ts:87-91 (registration)Tool registration in the MCP ListToolsRequestHandler, specifying the name, description, and inputSchema (derived from ListModelsSchema).{ name: 'comfy_list_models', description: 'List available models, checkpoints, LoRAs, VAEs, and other resources in the ComfyUI models directory. Supports filtering by type and name.', inputSchema: zodToJsonSchema(ListModelsSchema) as any, },
- src/server.ts:161-162 (registration)Dispatch case in the MCP CallToolRequestHandler that routes calls to 'comfy_list_models' to the handleListModels function.case 'comfy_list_models': return await handleListModels(args as any);
- src/utils/filesystem.ts:23-86 (helper)Core helper function that recursively scans the ComfyUI models directory subfolders for model files (matching extensions like .safetensors, .ckpt), collects ModelInfo objects with type, name, path, and size.export function scanModelsDirectory(type: string): ModelInfo[] { const config = getConfig(); const basePath = getFullPath(config.paths.models); const typeMapping: Record<string, string> = { checkpoints: 'checkpoints', loras: 'loras', vae: 'vae', clip: 'clip', clip_vision: 'clip_vision', unet: 'unet', embeddings: 'embeddings', upscale_models: 'upscale_models', diffusion_models: 'diffusion_models', controlnet: 'controlnet', ipadapter: 'ipadapter', style_models: 'style_models', photomaker: 'photomaker', insightface: 'insightface' }; const results: ModelInfo[] = []; const scanDir = (dir: string, modelType: string): void => { if (!existsSync(dir)) return; try { const files = readdirSync(dir); for (const file of files) { const fullPath = join(dir, file); const stat = statSync(fullPath); if (stat.isDirectory()) { scanDir(fullPath, modelType); } else { const ext = extname(file).toLowerCase(); if (MODEL_EXTENSIONS.includes(ext)) { results.push({ type: modelType, name: file, path: fullPath.replace(basePath + '\\', ''), size: stat.size }); } } } } catch (error) { console.error(`Error scanning directory ${dir}:`, error); } }; if (type === 'all') { for (const [key, subdir] of Object.entries(typeMapping)) { scanDir(join(basePath, subdir), key); } } else { const subdir = typeMapping[type]; if (subdir) { scanDir(join(basePath, subdir), type); } } return results; }