Skip to main content
Glama

continue_editing

Apply iterative improvements to the last image generated or edited in your session. Automatically uses the previous image without requiring file paths, enabling continuous refinement through text-based change descriptions.

Instructions

Continue editing the LAST image generated or edited in this session. Automatically uses the previous image without needing a file path. Use for iterative improvements.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYesText describing changes to make to the last image (max 10,000 chars)
referenceImagesNoOptional array of file paths to reference images

Implementation Reference

  • The handleContinueEditing method is the main handler for the continue_editing tool. It checks if a previous image exists (lastImagePath), verifies the file still exists, parses arguments with ContinueEditingArgsSchema, then delegates to editImageInternal for the actual edit operation.
    private async handleContinueEditing(
      request: CallToolRequest
    ): Promise<CallToolResult> {
      if (!this.lastImagePath) {
        throw new McpError(
          ErrorCode.InvalidRequest,
          "No previous image found. Generate or edit an image first, then use continue_editing."
        );
      }
    
      // Verify the file still exists
      try {
        await fs.access(this.lastImagePath);
      } catch {
        throw new McpError(
          ErrorCode.InvalidRequest,
          "Last image file no longer exists. Generate a new image first."
        );
      }
    
      const parsed = ContinueEditingArgsSchema.safeParse(
        request.params.arguments
      );
      if (!parsed.success) {
        throw new McpError(
          ErrorCode.InvalidParams,
          parsed.error.errors.map((e) => e.message).join("; ")
        );
      }
    
      const { prompt, referenceImages } = parsed.data;
      return await this.editImageInternal(
        this.lastImagePath,
        prompt,
        referenceImages
      );
    }
  • ContinueEditingArgsSchema defines the input validation for continue_editing: a required prompt (string, 1-10,000 chars) and optional referenceImages (array of strings).
    export const ContinueEditingArgsSchema = z.object({
      prompt: z.string().min(1, "Prompt is required").max(10_000, "Prompt too long (max 10,000 chars)"),
      referenceImages: z.array(z.string()).optional(),
    });
  • src/index.ts:73-93 (registration)
    Tool registration for continue_editing in the TOOLS array, defining its name, description (for iterative improvements on the last image), and inputSchema with prompt and optional referenceImages.
      name: "continue_editing",
      description:
        "Continue editing the LAST image generated or edited in this session. Automatically uses the previous image without needing a file path. Use for iterative improvements.",
      inputSchema: {
        type: "object",
        properties: {
          prompt: {
            type: "string",
            description:
              "Text describing changes to make to the last image (max 10,000 chars)",
          },
          referenceImages: {
            type: "array",
            items: { type: "string" },
            description:
              "Optional array of file paths to reference images",
          },
        },
        required: ["prompt"],
      },
    },
  • editImageInternal is a shared helper method used by both edit_image and continue_editing tools. It validates paths, reads image files, handles reference images, calls the Gemini client to perform the edit, and returns the result with the edited image.
    private async editImageInternal(
      imagePath: string,
      prompt: string,
      referenceImages?: string[]
    ): Promise<CallToolResult> {
      const allowedDirs = getAllowedDirs();
    
      // Validate main image path
      const validatedPath = validatePath(imagePath, allowedDirs);
      const imageBuffer = await readImageFile(validatedPath);
      const mimeType = getMimeType(validatedPath);
      const imageBase64 = imageBuffer.toString("base64");
    
      // Validate and read reference images
      const refData: Array<{ base64: string; mimeType: string }> = [];
      if (referenceImages && referenceImages.length > 0) {
        for (const refPath of referenceImages) {
          const validatedRef = validatePath(refPath, allowedDirs);
          const refBuffer = await readImageFile(validatedRef);
          const refMime = getMimeType(validatedRef);
          refData.push({
            base64: refBuffer.toString("base64"),
            mimeType: refMime,
          });
        }
      }
    
      const result = await this.gemini.editImage(
        imageBase64,
        mimeType,
        prompt,
        refData.length > 0 ? refData : undefined
      );
    
      if (!result.filePath) {
        return {
          content: [{ type: "text", text: result.textContent }],
        };
      }
    
      this.lastImagePath = result.filePath;
    
      const statusText = [
        `Image edited with nanobanana (${this.gemini.getModelName()})`,
        `Original: ${imagePath}`,
        `Edit: "${prompt.length > 100 ? prompt.slice(0, 100) + "..." : prompt}"`,
        referenceImages?.length
          ? `Reference images: ${referenceImages.length}`
          : null,
        result.textContent ? `Description: ${result.textContent}` : null,
        `Saved to: ${result.filePath}`,
        `Use continue_editing to make further changes.`,
      ]
        .filter(Boolean)
        .join("\n\n");
    
      return {
        content: [
          { type: "text", text: statusText },
          {
            type: "image",
            data: result.base64Data,
            mimeType: result.mimeType,
          },
        ],
      };
    }
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/DojoCodingLabs/nanobanana-mcp'

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