Skip to main content
Glama

continue_image_session

Continue editing images in an existing multi-turn session while preserving previous conversation context. Add new instructions to modify images while maintaining the session's history.

Instructions

기존 멀티턴 세션을 이어서 이미지를 편집합니다. 이전 대화 맥락이 유지됩니다.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sessionIdYesstart_image_session에서 받은 세션 ID
promptYes추가 편집 지시사항
outputPathYes결과 이미지를 저장할 파일 경로
imagePathNo추가로 참조할 이미지 경로 (선택사항)

Implementation Reference

  • Main tool registration and handler for continue_image_session. Validates sessionId, retrieves session from sessions Map, calls session.sendWithImage() or session.send() based on whether an imagePath is provided, and returns formatted success/error responses.
    server.tool(
      "continue_image_session",
      "기존 멀티턴 세션을 이어서 이미지를 편집합니다. 이전 대화 맥락이 유지됩니다.",
      {
        sessionId: z.string().describe("start_image_session에서 받은 세션 ID"),
        prompt: z.string().describe("추가 편집 지시사항"),
        outputPath: z.string().describe("결과 이미지를 저장할 파일 경로"),
        imagePath: z
          .string()
          .optional()
          .describe("추가로 참조할 이미지 경로 (선택사항)"),
      },
      async ({ sessionId, prompt, outputPath, imagePath }) => {
        try {
          const session = sessions.get(sessionId);
          if (!session) {
            return {
              content: [
                {
                  type: "text",
                  text: `세션을 찾을 수 없습니다 (ID: ${sessionId}). start_image_session으로 새 세션을 시작하세요.`,
                },
              ],
              isError: true,
            };
          }
    
          let result;
          if (imagePath) {
            result = await session.sendWithImage(imagePath, prompt, { outputPath });
          } else {
            result = await session.send(prompt, { outputPath });
          }
    
          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,
          };
        }
      }
    );
  • Input schema definition using Zod validation. Defines required parameters: sessionId (string), prompt (string), outputPath (string), and optional imagePath (string) for additional image reference.
    {
      sessionId: z.string().describe("start_image_session에서 받은 세션 ID"),
      prompt: z.string().describe("추가 편집 지시사항"),
      outputPath: z.string().describe("결과 이미지를 저장할 파일 경로"),
      imagePath: z
        .string()
        .optional()
        .describe("추가로 참조할 이미지 경로 (선택사항)"),
    },
  • createSession function that creates a multi-turn session object with send() and sendWithImage() methods. These methods are called by the continue_image_session handler to maintain conversation context across multiple edits.
    export function createSession(options = {}) {
      const ai = getAI();
      const model = options.model || DEFAULT_MODEL;
      const config = buildConfig(options);
    
      const chat = ai.chats.create({
        model,
        config,
      });
    
      return {
        async send(prompt, sendOptions = {}) {
          const outputPath = resolveOutput(
            sendOptions.output || sendOptions.outputPath || "./session-output.png"
          );
    
          try {
            const response = await chat.sendMessage({
              message: prompt,
            });
    
            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;
          }
        },
    
        async sendWithImage(imagePath, prompt, sendOptions = {}) {
          const outputPath = resolveOutput(
            sendOptions.output || sendOptions.outputPath || "./session-output.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 message = [
            {
              inlineData: {
                mimeType,
                data: base64Image,
              },
            },
            { text: prompt },
          ];
    
          try {
            const response = await chat.sendMessage({ message });
    
            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;
          }
        },
      };
    }
  • sendWithImage method implementation on the session object. Handles sending a message with both an image and text prompt, saves the result, and returns success/outputPath information.
    async sendWithImage(imagePath, prompt, sendOptions = {}) {
      const outputPath = resolveOutput(
        sendOptions.output || sendOptions.outputPath || "./session-output.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 message = [
        {
          inlineData: {
            mimeType,
            data: base64Image,
          },
        },
        { text: prompt },
      ];
    
      try {
        const response = await chat.sendMessage({ message });
    
        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;
      }
    },
  • send method implementation on the session object. Handles sending a text-only prompt while maintaining conversation context, saves the result image, and returns success/outputPath information.
    async send(prompt, sendOptions = {}) {
      const outputPath = resolveOutput(
        sendOptions.output || sendOptions.outputPath || "./session-output.png"
      );
    
      try {
        const response = await chat.sendMessage({
          message: prompt,
        });
    
        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;
      }
    },

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