comfy_upload_image
Upload images to ComfyUI's input folder for AI workflow integration. Specify custom filenames and control file overwriting to prepare visual assets for processing.
Instructions
Upload an image to ComfyUI's input folder for use in workflows. Supports custom filenames and overwrite control.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| image_path | Yes | ||
| filename | No | ||
| overwrite | No |
Implementation Reference
- src/tools/utils.ts:5-39 (handler)MCP handler function for comfy_upload_image tool. Calls uploadImage helper, handles errors, and returns formatted response.export async function handleUploadImage(input: UploadImageInput) { try { const result = uploadImage(input.image_path, input.filename, input.overwrite); return { content: [{ type: "text", text: JSON.stringify({ filename: result.filename, path: result.path, size: result.size, message: `Image uploaded successfully as ${result.filename}` }, null, 2) }] }; } catch (error: any) { if (error.message.includes('not found')) { return { content: [{ type: "text", text: JSON.stringify(ComfyUIErrorBuilder.fileNotFound(input.image_path), null, 2) }], isError: true }; } return { content: [{ type: "text", text: JSON.stringify(ComfyUIErrorBuilder.executionError(error.message), null, 2) }], isError: true }; } }
- src/types/tools.ts:122-126 (schema)Zod input schema for validating parameters of the comfy_upload_image tool.export const UploadImageSchema = z.object({ image_path: z.string(), filename: z.string().optional(), overwrite: z.boolean().optional().default(false) });
- src/server.ts:130-134 (registration)Registration of the comfy_upload_image tool in the MCP server's tool list, providing name, description, and input schema.{ name: 'comfy_upload_image', description: 'Upload an image to ComfyUI\'s input folder for use in workflows. Supports custom filenames and overwrite control.', inputSchema: zodToJsonSchema(UploadImageSchema) as any, },
- src/utils/filesystem.ts:88-133 (helper)Core utility function that uploads the image by copying it to ComfyUI's input directory, handling directory creation, filename sanitization, conflicts, and validation.export function uploadImage(sourcePath: string, filename?: string, overwrite: boolean = false): { filename: string; path: string; size: number } { const config = getConfig(); const inputDir = getFullPath(config.paths.input); // Ensure input directory exists if (!existsSync(inputDir)) { mkdirSync(inputDir, { recursive: true }); } // Validate source file if (!existsSync(sourcePath)) { throw new Error(`Source file not found: ${sourcePath}`); } // Determine target filename let targetFilename = filename || basename(sourcePath); targetFilename = sanitizeFilename(targetFilename); // Validate image format if (!validateImageFormat(targetFilename)) { throw new Error(`Invalid image format: ${targetFilename}`); } // Handle existing file let targetPath = join(inputDir, targetFilename); if (existsSync(targetPath) && !overwrite) { const ext = extname(targetFilename); const nameWithoutExt = basename(targetFilename, ext); let counter = 1; do { targetFilename = `${nameWithoutExt}_${counter}${ext}`; targetPath = join(inputDir, targetFilename); counter++; } while (existsSync(targetPath)); } // Copy file copyFileSync(sourcePath, targetPath); const stat = statSync(targetPath); return { filename: targetFilename, path: targetPath, size: stat.size }; }