Skip to main content
Glama

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
NameRequiredDescriptionDefault
image_pathYes
filenameNo
overwriteNo

Implementation Reference

  • 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 }; } }
  • 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, },
  • 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 }; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Nikolaibibo/claude-comfyui-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server