upscale_image
Provide an image URL and choose an upscaler model (ESRGAN, SwinIR). The tool fetches the image, runs the upscale through ComfyUI, and outputs the URL of the upscaled result.
Instructions
Upscale an image using a loaded upscaler model (ESRGAN, SwinIR, etc.). Fetches the source image, uploads to ComfyUI, runs the upscale node, and returns the output URL. Requires at least one upscaler model in ComfyUI's models/upscale_models/ directory.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| source_image_url | Yes | URL of the image to upscale. Will be fetched and uploaded to ComfyUI. | |
| upscale_model | Yes | Upscaler model filename (e.g. RealESRGAN_x4plus.pth). Use list_models with kind=upscalers to see what's installed. |
Implementation Reference
- src/tools/upscale.ts:18-40 (handler)Registers the 'upscale_image' MCP tool. The handler fetches the source image URL, builds an upscale workflow (LoadImage -> UpscaleModelLoader -> ImageUpscaleWithModel -> SaveImage), executes it via ComfyUIClient, and returns the output image URLs.
export function registerUpscaleTool( server: McpServer, client: ComfyUIClient, ): void { server.tool( "upscale_image", "Upscale an image using a loaded upscaler model (ESRGAN, SwinIR, etc.). Fetches the source image, uploads to ComfyUI, runs the upscale node, and returns the output URL. Requires at least one upscaler model in ComfyUI's models/upscale_models/ directory.", upscaleImageSchema, async (args) => { const uploaded = await client.fetchAndUploadImage(args.source_image_url); const workflow = upscale({ sourceImage: uploaded.name, upscaleModel: args.upscale_model, }); const result = await client.runWorkflow(workflow); const lines = [ `Upscaled image (prompt_id: ${result.promptId}, model: ${args.upscale_model}):`, ...result.images.map((url, i) => ` ${i + 1}. ${url}`), ]; return { content: [{ type: "text" as const, text: lines.join("\n") }] }; }, ); } - src/tools/upscale.ts:6-16 (schema)Defines the input schema for the 'upscale_image' tool: source_image_url (string URL) and upscale_model (string filename of an upscaler model like RealESRGAN_x4plus.pth).
const upscaleImageSchema = { source_image_url: z .string() .url() .describe("URL of the image to upscale. Will be fetched and uploaded to ComfyUI."), upscale_model: z .string() .describe( "Upscaler model filename (e.g. RealESRGAN_x4plus.pth). Use list_models with kind=upscalers to see what's installed.", ), }; - src/server.ts:44-44 (registration)Registration call that wires 'registerUpscaleTool' into the MCP server during initialization.
registerUpscaleTool(s, client); - src/comfyui/workflows.ts:122-141 (helper)The 'upscale' helper function defines the ComfyUI workflow JSON for upscaling: loads the source image, loads the upscaler model, applies ImageUpscaleWithModel, and saves the result.
export function upscale(params: UpscaleParams): Workflow { return { "1": { class_type: "LoadImage", inputs: { image: params.sourceImage }, }, "2": { class_type: "UpscaleModelLoader", inputs: { model_name: params.upscaleModel }, }, "3": { class_type: "ImageUpscaleWithModel", inputs: { upscale_model: ["2", 0], image: ["1", 0] }, }, "4": { class_type: "SaveImage", inputs: { filename_prefix: "comfyui-mcp-upscale", images: ["3", 0] }, }, }; } - src/comfyui/client.ts:128-130 (helper)The 'listUpscaleModels' method on ComfyUIClient queries ComfyUI for available upscaler model names from the UpscaleModelLoader node, supporting the list_models tool.
async listUpscaleModels(): Promise<string[]> { return this.listNodeOptions("UpscaleModelLoader", "model_name"); }