edit_image
Modify existing images using text prompts to apply visual changes, adjustments, or enhancements through the Nano Banana MCP server's image editing capabilities.
Instructions
Edit an existing image based on a text prompt
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| prompt | Yes | The text prompt describing the edits to make | |
| file | Yes | The filename of the input image to edit | |
| preview | No | Automatically open generated images in default viewer |
Implementation Reference
- mcp-server/src/imageGenerator.ts:800-891 (handler)Core handler function that loads the input image, encodes it to base64, sends to OpenRouter API with edit prompt, parses response, saves edited 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), }; } } - mcp-server/src/server.ts:514-529 (handler)MCP server dispatch handler for 'edit_image' tool call: maps arguments, sets mode to 'edit', and delegates to ImageGenerator.editImage.
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:173-196 (registration)Tool registration in ListTools handler, including name, description, and input schema.
{ name: "edit_image", description: "Edit an existing image based on a text prompt", inputSchema: { type: "object", properties: { prompt: { type: "string", description: "The text prompt describing the edits to make", }, file: { type: "string", description: "The filename of the input image to edit", }, preview: { type: "boolean", description: "Automatically open generated images in default viewer", default: false, }, }, required: ["prompt", "file"], }, }, - mcp-server/src/server.ts:176-196 (schema)Input schema definition for the 'edit_image' tool.
inputSchema: { type: "object", properties: { prompt: { type: "string", description: "The text prompt describing the edits to make", }, file: { type: "string", description: "The filename of the input image to edit", }, preview: { type: "boolean", description: "Automatically open generated images in default viewer", default: false, }, }, required: ["prompt", "file"], }, },