Skip to main content
Glama

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
NameRequiredDescriptionDefault
promptYesThe text prompt describing the edits to make
fileYesThe filename of the input image to edit
previewNoAutomatically open generated images in default viewer

Implementation Reference

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

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/Aeven-AI/mcp-nanobanana'

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