edit_image
Modify existing images using AI by providing text instructions to add, remove, or alter elements. Upload an image and describe desired changes for automated editing.
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 core handler function for the 'edit_image' tool. Validates input arguments, calls Gemini service to generate edited image data, saves it using image service, and returns the output 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/types/index.ts:11-15 (schema)Type definition for the input arguments of the edit_image tool.export interface EditImageArgs { description: string; image: string; outputPath?: string; }
- src/tools/editImage.ts:8-32 (schema)Tool definition including the input schema (JSON Schema) for the 'edit_image' tool.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 'edit_image' tool (via editImageTool) in the MCP server's listTools response.this.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [generateImageTool, editImageTool], }; });
- src/index.ts:71-74 (registration)Dispatches calls to the 'edit_image' tool handler in the MCP server's callTool request handler.if (request.params.name === 'edit_image') { const args = request.params.arguments as unknown as EditImageArgs; return await handleEditImage(args, this.geminiService, this.imageService); }