Skip to main content
Glama

edit_image

Edit existing images using text prompts to modify content, adjust aspect ratios, and change sizes within the Gemini Image MCP server.

Instructions

기존 이미지를 프롬프트에 따라 편집합니다

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
imagePathYes편집할 원본 이미지 파일 경로
promptYes이미지 편집 지시사항
outputPathYes편집된 이미지를 저장할 파일 경로
aspectRatioNo출력 이미지 비율
imageSizeNo출력 이미지 크기 (기본: 1K)
modelNo사용할 모델

Implementation Reference

  • The core editImage function that implements image editing logic. It takes an image path, prompt, and options, reads the image, converts it to base64, sends it to the Gemini API with the edit prompt, and saves the edited result to disk.
    export async function editImage(imagePath, prompt, options = {}) {
      const ai = getAI();
      const model = options.model || DEFAULT_MODEL;
      const outputPath = resolveOutput(
        options.output || options.outputPath || "./edited.png"
      );
    
      const absImagePath = path.resolve(imagePath);
      if (!fs.existsSync(absImagePath)) {
        throw new Error(`이미지 파일을 찾을 수 없습니다: ${absImagePath}`);
      }
    
      const imageData = fs.readFileSync(absImagePath);
      const base64Image = imageData.toString("base64");
      const mimeType = getMimeTypeFromPath(absImagePath);
    
      const config = buildConfig(options);
    
      const contents = [
        {
          inlineData: {
            mimeType,
            data: base64Image,
          },
        },
        { text: prompt },
      ];
    
      try {
        const response = await ai.models.generateContent({
          model,
          contents,
          config,
        });
    
        const image = extractImageFromResponse(response);
        const text = extractTextFromResponse(response);
    
        if (!image) {
          const fallbackMsg = text || "편집된 이미지가 생성되지 않았습니다.";
          return { success: false, text: fallbackMsg, outputPath: null };
        }
    
        ensureDir(outputPath);
        const finalPath = outputPath.match(/\.\w+$/)
          ? outputPath
          : outputPath + getExtFromMimeType(image.mimeType);
    
        fs.writeFileSync(finalPath, Buffer.from(image.data, "base64"));
    
        return { success: true, outputPath: finalPath, text: text || "" };
      } catch (error) {
        if (isOverloadError(error)) {
          return {
            success: false,
            text: `API 과부하 에러 (${model}). model: "${FALLBACK_MODEL}" 옵션으로 다시 시도해보세요.`,
            outputPath: null,
            overloaded: true,
          };
        }
        throw error;
      }
    }
  • server.js:82-138 (registration)
    MCP tool registration for 'edit_image'. Defines the input schema using Zod (imagePath, prompt, outputPath, aspectRatio, imageSize, model) and the async handler that calls editImage and formats the response.
    server.tool(
      "edit_image",
      "기존 이미지를 프롬프트에 따라 편집합니다",
      {
        imagePath: z.string().describe("편집할 원본 이미지 파일 경로"),
        prompt: z.string().describe("이미지 편집 지시사항"),
        outputPath: z.string().describe("편집된 이미지를 저장할 파일 경로"),
        aspectRatio: z
          .enum(["1:1", "2:3", "3:2", "3:4", "4:3", "4:5", "5:4", "9:16", "16:9", "21:9"])
          .optional()
          .describe("출력 이미지 비율"),
        imageSize: z
          .enum(["1K", "2K", "4K"])
          .optional()
          .describe("출력 이미지 크기 (기본: 1K)"),
        model: z
          .string()
          .optional()
          .describe("사용할 모델"),
      },
      async ({ imagePath, prompt, outputPath, aspectRatio, imageSize, model }) => {
        try {
          const result = await editImage(imagePath, prompt, {
            outputPath,
            aspectRatio,
            imageSize,
            model,
          });
    
          if (!result.success) {
            return {
              content: [{ type: "text", text: result.text }],
              isError: !result.overloaded,
            };
          }
    
          return {
            content: [
              {
                type: "text",
                text: `이미지가 편집되었습니다: ${result.outputPath}${result.text ? "\n\n" + result.text : ""}`,
              },
            ],
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `이미지 편집 실패: ${error.message}`,
              },
            ],
            isError: true,
          };
        }
      }
    );
  • server.js:9-9 (registration)
    Import statement that brings the editImage function from gemini-image.js into the server module.
    editImage,
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 only states the basic function. It doesn't disclose behavioral traits such as whether this is a destructive operation (overwrites original?), authentication needs, rate limits, error conditions, or what the output looks like (e.g., file saved confirmation). This is inadequate for a mutation tool with zero annotation coverage.

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

Conciseness5/5

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

The description is a single, efficient sentence in Korean that directly states the tool's function without waste. It's appropriately sized and front-loaded with the core purpose.

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 the complexity (6 parameters, mutation operation) and lack of annotations or output schema, the description is insufficient. It doesn't explain return values, error handling, or important behavioral context like file system interactions, leaving significant gaps for an AI agent to use it correctly.

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 already documents all 6 parameters thoroughly. The description adds no additional meaning beyond implying 'prompt' guides the edit, which is already clear from parameter descriptions. Baseline 3 is appropriate when schema does the heavy lifting.

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 action ('edit') and resource ('existing image') with the mechanism ('according to prompt'), making the purpose understandable. However, it doesn't differentiate from sibling tools like 'generate_image' or 'continue_image_session', which likely involve image creation or modification in different contexts.

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?

No guidance is provided on when to use this tool versus alternatives like 'generate_image' (for new images) or 'continue_image_session' (for ongoing edits). The description implies usage for editing existing images with a prompt, but lacks explicit comparisons or exclusions.

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/jk7g14/gemini-image-mcp'

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