Skip to main content
Glama

Modify Selection

photopea_modify_selection

Modify an existing selection by expanding, contracting, feathering edges, or inverting selected and unselected areas. Specify amount in pixels for expand, contract, or feather.

Instructions

Modify the current active selection. Requires an existing selection created by make_selection. For expand, contract, and feather, the amount parameter specifies pixels. Invert swaps selected and unselected areas.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
actionYesHow to modify the selection: 'expand' grows it, 'contract' shrinks it, 'feather' softens edges, 'invert' swaps selected/unselected
amountNoModification amount in pixels (required for expand, contract, feather; ignored for invert)

Implementation Reference

  • Registration of the 'photopea_modify_selection' tool with input schema (action enum + optional amount) and handler that delegates to buildModifySelection.
    server.registerTool("photopea_modify_selection", {
      title: "Modify Selection",
      description: "Modify the current active selection. Requires an existing selection created by make_selection. For expand, contract, and feather, the amount parameter specifies pixels. Invert swaps selected and unselected areas.",
      inputSchema: {
        action: z.enum(["expand", "contract", "feather", "invert"]).describe("How to modify the selection: 'expand' grows it, 'contract' shrinks it, 'feather' softens edges, 'invert' swaps selected/unselected"),
        amount: z.number().min(0).optional().describe("Modification amount in pixels (required for expand, contract, feather; ignored for invert)"),
      },
      annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },
    }, async (params) => {
      const script = buildModifySelection(params);
      bridge.sendActivity({ type: "activity", id: "", tool: "modify_selection", summary: `Modify selection: ${params.action}` });
      const result = await bridge.executeScript(script);
      if (!result.success) return { isError: true, content: [{ type: "text" as const, text: result.error || "Failed to modify selection" }] };
      return { content: [{ type: "text" as const, text: `Selection modified: ${params.action}` }] };
    });
  • Handler function for photopea_modify_selection: builds script, sends activity, executes script, returns result or error.
    }, async (params) => {
      const script = buildModifySelection(params);
      bridge.sendActivity({ type: "activity", id: "", tool: "modify_selection", summary: `Modify selection: ${params.action}` });
      const result = await bridge.executeScript(script);
      if (!result.success) return { isError: true, content: [{ type: "text" as const, text: result.error || "Failed to modify selection" }] };
      return { content: [{ type: "text" as const, text: `Selection modified: ${params.action}` }] };
    });
  • Input schema for photopea_modify_selection: 'action' (enum: expand/contract/feather/invert) and optional 'amount' (number, min 0).
    inputSchema: {
      action: z.enum(["expand", "contract", "feather", "invert"]).describe("How to modify the selection: 'expand' grows it, 'contract' shrinks it, 'feather' softens edges, 'invert' swaps selected/unselected"),
      amount: z.number().min(0).optional().describe("Modification amount in pixels (required for expand, contract, feather; ignored for invert)"),
    },
  • buildModifySelection function: generates Photopea JavaScript string for selection modification (expand, contract, feather, or invert).
    export function buildModifySelection(params: ModifySelectionParams): string {
      const { action, amount = 0 } = params;
      const lines: string[] = [];
      const sel = `app.activeDocument.selection`;
    
      switch (action) {
        case "expand":
          lines.push(`${sel}.expand(${amount});`);
          break;
        case "contract":
          lines.push(`${sel}.contract(${amount});`);
          break;
        case "feather":
          lines.push(`${sel}.feather(${amount});`);
          break;
        case "invert":
          lines.push(`${sel}.invert();`);
          break;
      }
    
      lines.push(`app.echoToOE('ok');`);
      return lines.join("\n");
    }
  • Type definition for ModifySelectionParams: action (expand/contract/feather/invert) and optional amount.
    export interface ModifySelectionParams {
      action: "expand" | "contract" | "feather" | "invert";
      amount?: number;
    }
Behavior4/5

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

Annotations indicate non-destructive behavior, and the description adds behavioral detail by explaining each action's effect (e.g., feather softens edges, invert swaps). It does not contradict annotations. It could mention reversibility or immediate application, but the provided context is sufficient.

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 three short sentences, each serving a distinct purpose: purpose+prerequisite, parameter usage, and invert explanation. No superfluous text; front-loaded with key information.

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

Completeness4/5

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

For a simple mutation tool with no output schema, the description covers core functionality, actions, and parameter constraints. It lacks return value details (though likely void) and edge cases (e.g., empty selection), but the prerequisite mention mitigates some gaps.

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?

The input schema already covers 100% of parameters with descriptions. The description essentially repeats the schema's parameter info (pixels unit, invert ignores amount), adding no new semantic value. It is helpful but redundant.

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

Purpose5/5

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

The description clearly states the tool modifies the current active selection, lists the four specific actions (expand, contract, feather, invert), and explicitly differentiates from sibling tools like make_selection by stating the prerequisite (requires existing selection). The verb-modifier pair is specific and unambiguous.

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

Usage Guidelines4/5

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

The description provides a clear prerequisite (must have an existing selection from make_selection) and explains when each action is applicable (e.g., amount required for expand/contract/feather). It implies usage context but does not explicitly mention when to avoid this tool or suggest alternatives like clear_selection for removal. The prerequisite is a strong guideline.

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/attalla1/photopea-mcp-server'

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