Skip to main content
Glama

comfy_upload_image

Upload images to ComfyUI's input folder for AI workflow processing. Supports custom filenames and overwrite control to manage your image assets.

Instructions

Upload an image to ComfyUI's input folder for use in workflows. Supports custom filenames and overwrite control.

Input Schema

NameRequiredDescriptionDefault
image_pathYes
filenameNo
overwriteNo

Input Schema (JSON Schema)

{ "properties": { "filename": { "type": "string" }, "image_path": { "type": "string" }, "overwrite": { "default": false, "type": "boolean" } }, "required": [ "image_path" ], "type": "object" }

Implementation Reference

  • The main handler function for the comfy_upload_image tool, which calls uploadImage and formats the response or error.
    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 schema defining the input parameters for the tool: image_path (required), filename (optional), overwrite (optional boolean).
    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 tool in the ListTools response, including name, description, and input schema reference.
    { 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 performs the file copy to ComfyUI input directory, handles naming conflicts, validation, and returns file info.
    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