Skip to main content
Glama
georgejeffers

Gemini MCP Server

Edit Image (Multi-Reference)

edit_image_multi
Read-only

Edit or compose images using multiple reference images (up to 14) with customizable aspect ratios and resolutions.

Instructions

Edit or compose images using multiple reference images (up to 14). Uses gemini-3-pro-image-preview (Nano Banana Pro).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYesDescription of the desired output
imagesYesArray of reference images (1-14)
aspectRatioNoAspect ratio of the output image1:1
imageSizeNoOutput image resolution1K

Implementation Reference

  • The complete implementation of edit_image_multi tool including registration, schema definition, and handler logic. This function registers the tool with the MCP server and handles multi-reference image editing by processing a prompt and up to 14 base64-encoded images through the gemini-3-pro-image-preview model.
    export function registerMulti(server: McpServer, ai: GoogleGenAI): void {
      server.registerTool(
        'edit_image_multi',
        {
          title: 'Edit Image (Multi-Reference)',
          description: 'Edit or compose images using multiple reference images (up to 14). Uses gemini-3-pro-image-preview (Nano Banana Pro).',
          inputSchema: {
            prompt: z.string().min(1).describe('Description of the desired output'),
            images: z.array(z.object({
              data: z.string().min(1).describe('Base64-encoded image'),
              mimeType: z.enum(['image/png', 'image/jpeg', 'image/webp']).default('image/png'),
            })).min(1).max(14).describe('Array of reference images (1-14)'),
            aspectRatio: AspectRatio.default('1:1').describe('Aspect ratio of the output image'),
            imageSize: ImageSize.default('1K').describe('Output image resolution'),
          },
          annotations: {
            readOnlyHint: true,
            destructiveHint: false,
            openWorldHint: true,
          },
        },
        async ({ prompt, images, aspectRatio, imageSize }) => {
          try {
            const parts = [
              { text: prompt },
              ...images.map((img: { mimeType: string; data: string }) => ({
                inlineData: { mimeType: img.mimeType, data: img.data },
              })),
            ];
    
            const response = await ai.models.generateContent({
              model: 'gemini-3-pro-image-preview',
              contents: parts,
              config: {
                responseModalities: ['TEXT', 'IMAGE'],
                imageConfig: { aspectRatio, imageSize },
              },
            });
    
            const result = extractImageFromResponse(response);
            if (!result) {
              return {
                content: [{ type: 'text' as const, text: 'No image was produced. Try a different prompt.' }],
                isError: true,
              };
            }
    
            if (!validateImageSize(result.data)) {
              return {
                content: [{ type: 'text' as const, text: 'Output image exceeds size limit. Try a smaller imageSize.' }],
                isError: true,
              };
            }
    
            return {
              content: [{ type: 'image' as const, data: result.data, mimeType: result.mimeType }],
            };
          } catch (error) {
            return formatToolError(error);
          }
        },
      );
    }
  • src/index.ts:9-31 (registration)
    Tool registration in the main server file. Imports registerMulti as registerEditImageMulti and registers it with the MCP server instance.
    import { register as registerEditImage, registerMulti as registerEditImageMulti } from './tools/edit-image.js';
    
    const GEMINI_API_KEY = process.env.GEMINI_API_KEY;
    if (!GEMINI_API_KEY) {
      console.error('GEMINI_API_KEY environment variable is required');
      process.exit(1);
    }
    
    const ai = createClient(GEMINI_API_KEY);
    
    const server = new McpServer(
      { name: 'gemini', version: '2.0.0' },
      { capabilities: { logging: {} } },
    );
    
    // Register all 7 tools
    registerGenerateText(server, ai);
    registerChat(server, ai);
    registerGenerateWithSearch(server, ai);
    registerCodeExecution(server, ai);
    registerGenerateImage(server, ai);
    registerEditImage(server, ai);
    registerEditImageMulti(server, ai);
  • Type definitions for schema validation used by edit_image_multi tool, defining allowed aspect ratios and image sizes.
    export const AspectRatio = z.enum([
      '1:1', '2:3', '3:2', '3:4', '4:3', '4:5', '5:4', '9:16', '16:9', '21:9',
    ]);
    export type AspectRatio = z.infer<typeof AspectRatio>;
    
    export const ImageSize = z.enum(['1K', '2K', '4K']);
    export type ImageSize = z.infer<typeof ImageSize>;
  • Helper utilities used by edit_image_multi handler: validateImageSize checks if base64 image size is within 2MB limit, extractImageFromResponse parses the Gemini API response to extract the generated image data.
    const MAX_IMAGE_SIZE = 2 * 1024 * 1024; // 2MB — conservative limit for MCP stdio transport
    
    export function validateImageSize(base64: string): boolean {
      const sizeInBytes = Math.ceil(base64.length * 3 / 4);
      return sizeInBytes <= MAX_IMAGE_SIZE;
    }
    
    export function extractImageFromResponse(response: any): { data: string; mimeType: string } | null {
      const parts = response?.candidates?.[0]?.content?.parts;
      if (!parts) return null;
      for (const part of parts) {
        if (part.inlineData) {
          return {
            data: part.inlineData.data,
            mimeType: part.inlineData.mimeType,
          };
        }
      }
      return null;
    }
  • Error formatting utility used by edit_image_multi handler to format errors into the expected MCP tool response structure.
    export function formatToolError(error: unknown) {
      const text = error instanceof Error ? error.message : String(error);
      return {
        content: [{ type: 'text' as const, text }],
        isError: true,
      };
    }
Behavior3/5

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

Annotations already declare readOnlyHint=true, destructiveHint=false, and openWorldHint=true, covering safety and scope. The description adds minimal behavioral context: it mentions the AI model ('gemini-3-pro-image-preview') and the 14-image limit, which are useful but not comprehensive. It doesn't describe output format, latency, rate limits, or quality expectations. With annotations providing core safety info, the description adds some value but lacks rich behavioral disclosure.

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 brief (two sentences) and front-loaded with the core purpose. Every sentence adds information: the first states the function and constraint, the second names the AI model. There's no fluff or repetition. However, it could be more structured (e.g., separating function from technical details) and slightly more informative without losing conciseness.

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

Completeness3/5

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

Given the tool's moderate complexity (image editing with multiple references), the description is minimally adequate. Annotations cover safety and scope, and the schema fully documents inputs. However, with no output schema, the description doesn't explain return values (e.g., image format, errors). It also lacks context about the AI model's capabilities/limitations. For a creative tool with potential variability, more guidance would be helpful.

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 all 4 parameters. The description adds no parameter-specific semantics beyond what's in the schema—it doesn't explain how 'prompt' interacts with 'images', what 'edit vs. compose' means for parameters, or provide examples. Baseline 3 is appropriate when the schema does all the parameter documentation work.

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 tool's purpose: 'Edit or compose images using multiple reference images (up to 14).' It specifies the verb ('Edit or compose'), resource ('images'), and key constraint ('multiple reference images'). However, it doesn't explicitly distinguish this from its sibling 'edit_image' tool, which likely handles single-reference edits. The mention of 'gemini-3-pro-image-preview (Nano Banana Pro)' adds implementation detail but doesn't clarify functional differentiation.

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 guidance on when to use this tool versus alternatives. It doesn't mention the sibling 'edit_image' tool (for single-reference edits), 'generate_image' (for generation without references), or other image-related tools. There's no context about use cases, prerequisites, or exclusions. The only implicit guidance is the 'multi-reference' aspect, but this isn't framed as a decision criterion.

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

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