Skip to main content
Glama
Garblesnarff

Gemini MCP Server for Claude Desktop

gemini-edit-image

Edit images using AI by providing instructions and context for intelligent enhancements through Claude Desktop's Gemini integration.

Instructions

Edit existing images using Gemini's AI image editing capabilities (with learned user preferences)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
image_pathYesPath to the image file to edit (JPEG, PNG, WebP, GIF, BMP)
edit_instructionYesDetailed instruction for how to edit the image
contextNoOptional context for intelligent enhancement (e.g., "subtle", "dramatic", "professional")

Implementation Reference

  • The main handler function that performs image editing: validates inputs, loads and encodes image, enhances edit instruction using intelligence system, calls Gemini API for editing, saves the output image, learns from interaction, and returns formatted response.
    async execute(args) {
      const imagePath = validateNonEmptyString(args.image_path, 'image_path');
      const editInstruction = validateNonEmptyString(args.edit_instruction, 'edit_instruction');
      const context = args.context ? validateString(args.context, 'context') : null;
    
      log(`Editing image: "${imagePath}" with instruction: "${editInstruction}" and context: ${context || 'general'}`, this.name);
    
      try {
        validateFileSize(imagePath, config.MAX_IMAGE_SIZE_MB);
        const imageBuffer = readFileAsBuffer(imagePath);
        const imageBase64 = imageBuffer.toString('base64');
        const mimeType = getMimeType(imagePath, config.SUPPORTED_IMAGE_MIMES);
    
        log(`Image file loaded: ${(imageBuffer.length / 1024).toFixed(2)}KB, MIME type: ${mimeType}`, this.name);
    
        let enhancedEditInstruction = editInstruction;
        if (this.intelligenceSystem.initialized) {
          try {
            enhancedEditInstruction = await this.intelligenceSystem.enhancePrompt(editInstruction, context, this.name);
            log('Applied Tool Intelligence enhancement', this.name);
          } catch (err) {
            log(`Tool Intelligence enhancement failed: ${err.message}`, this.name);
          }
        }
    
        let editPrompt = `Please edit this image according to the following instruction: ${enhancedEditInstruction}`; // eslint-disable-line max-len
        if (context) {
          editPrompt += `\n\nAdditional context: ${context}`;
        }
        editPrompt += '\n\nProvide the edited image as output. Maintain the overall composition and quality while making the requested changes.'; // eslint-disable-line max-len
    
        const editedImageData = await this.geminiService.analyzeImage('IMAGE_EDITING', editPrompt, imageBase64, mimeType);
    
        if (editedImageData) {
          log('Successfully extracted edited image data', this.name);
    
          ensureDirectoryExists(config.OUTPUT_DIR, this.name);
    
          const timestamp = Date.now();
          const hash = crypto.createHash('md5').update(editInstruction).digest('hex');
          const imageName = `gemini-edited-${hash}-${timestamp}.png`;
          const outputImagePath = path.join(config.OUTPUT_DIR, imageName);
    
          fs.writeFileSync(outputImagePath, Buffer.from(editedImageData, 'base64'));
          log(`Edited image saved to: ${outputImagePath}`, this.name);
    
          if (this.intelligenceSystem.initialized) {
            try {
              await this.intelligenceSystem.learnFromInteraction(editInstruction, enhancedEditInstruction, `Image edited successfully: ${outputImagePath}`, context, this.name); // eslint-disable-line max-len
              log('Tool Intelligence learned from interaction', this.name);
            } catch (err) {
              log(`Tool Intelligence learning failed: ${err.message}`, this.name);
            }
          }
    
          let finalResponse = `✓ Image successfully edited with instruction: "${editInstruction}"\n\n**Original:** ${imagePath}\n**Edited:** ${outputImagePath}\n\n**Edit Applied:** ${editInstruction}${context ? `\n**Context:** ${context}` : ''}`; // eslint-disable-line max-len
          if (context && this.intelligenceSystem.initialized) {
            finalResponse += `\n\n---\n_Enhancement applied based on context: ${context}_`;
          }
    
          return {
            content: [
              {
                type: 'text',
                text: finalResponse,
              },
            ],
          };
        }
        log('No edited image data found in response', this.name);
        return {
          content: [
            {
              type: 'text',
              text: `Could not edit image with instruction: "${editInstruction}". No edited image data was returned by Gemini API. Try rephrasing your edit instruction or using a different image.`, // eslint-disable-line max-len
            },
          ],
        };
      } catch (error) {
        log(`Error editing image: ${error.message}`, this.name);
        throw new Error(`Error editing image: ${error.message}`);
      }
    }
  • JSON schema defining the input parameters for the tool: image_path (required), edit_instruction (required), and optional context.
    {
      type: 'object',
      properties: {
        image_path: {
          type: 'string',
          description: 'Path to the image file to edit (JPEG, PNG, WebP, GIF, BMP)',
        },
        edit_instruction: {
          type: 'string',
          description: 'Detailed instruction for how to edit the image',
        },
        context: {
          type: 'string',
          description: 'Optional context for intelligent enhancement (e.g., "subtle", "dramatic", "professional")',
        },
      },
      required: ['image_path', 'edit_instruction'],
    },
  • Registers the ImageEditingTool instance (named 'gemini-edit-image') into the tools registry.
    registerTool(new ImageEditingTool(intelligenceSystem, geminiService));
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but offers minimal behavioral disclosure. It mentions 'AI image editing capabilities' and 'learned user preferences', hinting at intelligent processing and personalization, but lacks details on permissions, rate limits, output format, or mutation effects (e.g., whether edits are destructive or reversible). This is inadequate for a tool with implied mutation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose. It avoids redundancy and wastes no words, though it could be slightly more structured (e.g., separating functionality from context). It earns its place but isn't perfectly optimized.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations and no output schema, the description is incomplete for an AI editing tool. It lacks critical context: output format (e.g., returns edited image or path), error handling, mutation behavior, and how 'learned user preferences' apply. This leaves significant gaps for agent understanding.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents parameters. The description adds no additional meaning beyond what's in the schema (e.g., no examples or deeper context for 'edit_instruction' or 'context'). Baseline 3 is appropriate as the schema handles parameter semantics effectively.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('Edit') and resource ('existing images'), specifying it uses 'Gemini's AI image editing capabilities'. It distinguishes from siblings like 'generate_image' (creation) and 'gemini-analyze-image' (analysis), though not explicitly. However, it doesn't fully differentiate from 'gemini-advanced-image' (purpose unclear), making it a 4 rather than a 5.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no explicit guidance on when to use this tool versus alternatives. It mentions 'learned user preferences' but doesn't clarify if this is for personalization or how it affects tool selection. No exclusions, prerequisites, or named alternatives are provided, leaving usage context implied at best.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/Garblesnarff/gemini-mcp-server'

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