edit_image
Modify existing images using text instructions with Google Gemini AI. Add, remove, or alter elements by describing the changes you want to apply to your image file.
Instructions
Modify an existing image using Google Gemini AI based on a text instruction. Provide the path to the image you want to edit and describe the changes that should be applied.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| description | Yes | Describe the changes that should be applied to the provided image. Be specific about elements to add, remove, or modify. | |
| image | Yes | Path to the image file that should be edited. Can be absolute or relative to the server. | |
| outputPath | No | Optional path where the edited image should be saved. If omitted, saves in the current working directory using an auto-generated filename. |
Implementation Reference
- src/tools/editImage.ts:34-72 (handler)The handler function that performs the core logic: validates input, edits image using GeminiService, saves with ImageService, and returns the file path.export async function handleEditImage( args: EditImageArgs, geminiService: GeminiService, imageService: ImageService ) { const description = args.description?.trim(); if (!description) { throw invalidParams('Description is required to edit an image'); } if (!args.image || !args.image.trim()) { throw invalidParams('Image path is required to edit an image'); } try { const imageData = await geminiService.editImage({ description, images: [args.image], }); const filePath = await imageService.saveImage(imageData, { description, outputPath: args.outputPath, }); return { content: [ { type: 'text', text: filePath, }, ], }; } catch (error) { throw ensureMcpError(error, ErrorCode.InternalError, 'Failed to edit image', { stage: 'edit_image.tool', }); } }
- src/tools/editImage.ts:8-32 (schema)Tool object definition including JSON input schema for parameters: description (required), image (required), outputPath (optional).export const editImageTool: Tool = { name: 'edit_image', description: 'Modify an existing image using Google Gemini AI based on a text instruction. Provide the path to the image you want to edit and describe the changes that should be applied.', inputSchema: { type: 'object', properties: { description: { type: 'string', description: 'Describe the changes that should be applied to the provided image. Be specific about elements to add, remove, or modify.', }, image: { type: 'string', description: 'Path to the image file that should be edited. Can be absolute or relative to the server.', }, outputPath: { type: 'string', description: 'Optional path where the edited image should be saved. If omitted, saves in the current working directory using an auto-generated filename.', }, }, required: ['description', 'image'], }, };
- src/index.ts:58-62 (registration)Registers the editImageTool in the list of available tools for ListToolsRequest.this.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [generateImageTool, editImageTool], }; });
- src/index.ts:71-74 (registration)Dispatches CallToolRequest to handleEditImage when tool name is 'edit_image'.if (request.params.name === 'edit_image') { const args = request.params.arguments as unknown as EditImageArgs; return await handleEditImage(args, this.geminiService, this.imageService); }
- src/types/index.ts:11-15 (schema)TypeScript interface defining input arguments for edit_image tool.export interface EditImageArgs { description: string; image: string; outputPath?: string; }