Skip to main content
Glama

Select Layer

photopea_select_layer
Idempotent

Select a layer by name or index to set it as the active target for subsequent edits such as filters, adjustments, and fills.

Instructions

Set a layer as the active layer by name or index. Many tools (apply_filter, apply_adjustment, fill_selection) operate on the active layer — use this to target a specific layer first. Use get_layers to find layer names and indices.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
targetYesLayer name (string) or index (number)

Implementation Reference

  • Handler registration for photopea_select_layer tool. Calls buildSelectLayer to generate the Photopea JS script, executes it via the bridge, and returns a success/error result.
    server.registerTool("photopea_select_layer", {
      title: "Select Layer",
      description: "Set a layer as the active layer by name or index. Many tools (apply_filter, apply_adjustment, fill_selection) operate on the active layer — use this to target a specific layer first. Use get_layers to find layer names and indices.",
      inputSchema: {
        target: layerTarget,
      },
      annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false },
    }, async (params) => {
      const script = buildSelectLayer({ target: params.target });
      bridge.sendActivity({ type: "activity", id: "", tool: "select_layer", summary: `Select layer: ${params.target}` });
      const result = await bridge.executeScript(script);
      if (!result.success) return { isError: true, content: [{ type: "text" as const, text: result.error || "Failed to select layer" }] };
      return { content: [{ type: "text" as const, text: `Layer selected: ${params.target}` }] };
    });
  • Builds the JavaScript string to set a layer as active in Photopea. Uses layerRef helper to resolve the target (by name string or numeric index).
    export function buildSelectLayer(params: LayerTarget): string {
      const ref = layerRef(params.target);
      return [
        `app.activeDocument.activeLayer = ${ref};`,
        `app.echoToOE('ok');`,
      ].join("\n");
    }
  • Helper function that emits a JS expression resolving to a layer — by numeric index (app.activeDocument.layers[index]) or by name string (app.activeDocument.layers.getByName(...)).
    function layerRef(target: string | number): string {
      if (typeof target === "number") {
        return `app.activeDocument.layers[${target}]`;
      }
      return `app.activeDocument.layers.getByName('${escapeString(target)}')`;
    }
  • TypeScript interface defining the LayerTarget type used by buildSelectLayer and other layer-related script builders.
    export interface LayerTarget {
      target: string | number;
    }
  • Import of buildSelectLayer from script-builder and definition of layerTarget zod schema used in the tool registration.
    import {
      buildAddLayer,
      buildAddFillLayer,
      buildDeleteLayer,
      buildSelectLayer,
      buildSetLayerProperties,
      buildMoveLayer,
      buildDuplicateLayer,
      buildReorderLayer,
      buildGroupLayers,
      buildGetLayers,
      escapeString,
    } from "../bridge/script-builder.js";
    
    const layerTarget = z.union([z.string(), z.number()]).describe("Layer name (string) or index (number)");
    
    export function registerLayerTools(server: McpServer, bridge: PhotopeaBridge): void {
Behavior3/5

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

Annotations already indicate non-readOnly and idempotent. The description adds that it sets the active layer state, but doesn't elaborate on side effects or state changes beyond what annotations imply. Adequate but not rich.

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?

Two concise sentences with front-loaded purpose. No unnecessary words. Every sentence adds value.

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?

Given the simplicity (one parameter, no output), the description covers the tool's purpose, usage context, and input sourcing. Could mention that it modifies document state, but annotations cover that.

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 coverage is 100% and description echoes 'by name or index'. No new semantics beyond the schema's parameter description. Baseline score for high coverage.

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?

Clearly states the tool sets a layer as active by name or index, with a specific verb and resource. Distinguishes its role from siblings by noting that many other tools operate on the active layer.

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

Usage Guidelines5/5

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

Explicitly tells when to use the tool (before operations that depend on active layer) and mentions get_layers to find valid inputs. Provides clear context for selection.

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