restore_image
Restore or enhance existing images using natural language prompts to describe the desired improvements.
Instructions
Restore or enhance an existing image
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| prompt | Yes | The text prompt describing the restoration to perform | |
| file | Yes | The filename of the input image to restore | |
| preview | No | Automatically open generated images in default viewer |
Implementation Reference
- mcp-server/src/server.ts:514-529 (handler)Handler logic for the 'restore_image' tool. Determines mode as 'restore' based on tool name, constructs ImageGenerationRequest with prompt, input image file, and other params, then delegates to ImageGenerator.editImage() for execution.case "edit_image": case "restore_image": { const mode = name === "edit_image" ? "edit" : "restore"; const imageRequest: ImageGenerationRequest = { prompt: args?.prompt as string, inputImage: args?.file as string, mode, seed: args?.seed as number, preview: args?.preview as boolean, noPreview: (args?.noPreview as boolean) || (args?.["no-preview"] as boolean), }; response = await this.imageGenerator.editImage(imageRequest); break; }
- mcp-server/src/server.ts:197-221 (schema)Input schema and metadata for the 'restore_image' tool, defining required 'prompt' and 'file' parameters with descriptions.{ name: "restore_image", description: "Restore or enhance an existing image", inputSchema: { type: "object", properties: { prompt: { type: "string", description: "The text prompt describing the restoration to perform", }, file: { type: "string", description: "The filename of the input image to restore", }, preview: { type: "boolean", description: "Automatically open generated images in default viewer", default: false, }, }, required: ["prompt", "file"], }, },
- Core implementation in ImageGenerator.editImage() that handles restoration (when mode='restore'). Loads input image as base64, sends to OpenRouter API via image-to-image endpoint with restoration prompt, saves output image, and handles preview.async editImage( request: ImageGenerationRequest ): Promise<ImageGenerationResponse> { try { if (!request.inputImage) { return { success: false, message: "Input image file is required for editing", error: "Missing inputImage parameter", }; } const fileResult = FileHandler.findInputFile(request.inputImage); if (!fileResult.found) { return { success: false, message: `Input image not found: ${request.inputImage}`, error: `Searched in: ${fileResult.searchedPaths.join(", ")}`, }; } const outputPath = FileHandler.ensureOutputDirectory(); const imageBase64 = await FileHandler.readImageAsBase64( fileResult.filePath! ); const fileName = path.basename(fileResult.filePath!); const mimeType = this.detectMimeType(fileName); const dataUrl = `data:${mimeType};base64,${imageBase64}`; const payload: Record<string, unknown> = { model: this.modelName, input: [ { role: "user", content: [ { type: "input_text", text: request.prompt, }, ], }, ], images: [dataUrl], }; if (request.seed !== undefined) { payload.seed = request.seed; } const response = await this.postJson<OpenRouterImageResponse>( this.generationPath, payload ); const imageBase64Result = this.parseImageFromResponse(response); if (!imageBase64Result) { return { success: false, message: `Failed to ${request.mode} image`, error: "No image data returned in OpenRouter response", }; } const filename = FileHandler.generateFilename( `${request.mode}_${request.prompt}`, "png", 0 ); const fullPath = await FileHandler.saveImageFromBase64( imageBase64Result, outputPath, filename ); await this.handlePreview([fullPath], request); return { success: true, message: `Successfully ${request.mode}d image`, generatedFiles: [fullPath], }; } catch (error: unknown) { logger.error(`Error in ${request.mode}Image:`, error); return { success: false, message: `Failed to ${request.mode} image`, error: this.handleApiError(error), }; } }