Skip to main content
Glama

Duplicate Layer

photopea_duplicate_layer

Duplicate a layer in an active Photopea document. Specify the layer by name or index, and optionally assign a new display name to the copy. The duplicate becomes the active layer, placed above the original.

Instructions

Create a copy of a layer in the active document. The duplicate becomes the active layer and is placed above the original. Use newName to distinguish the copy from the original.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
targetYesLayer name (string) or index (number)
newNameNoDisplay name for the duplicated layer (defaults to 'original name copy')

Implementation Reference

  • Registration of photopea_duplicate_layer tool with input schema (target, newName) and handler that calls buildDuplicateLayer
    // 12. photopea_duplicate_layer
    server.registerTool("photopea_duplicate_layer", {
      title: "Duplicate Layer",
      description: "Create a copy of a layer in the active document. The duplicate becomes the active layer and is placed above the original. Use newName to distinguish the copy from the original.",
      inputSchema: {
        target: layerTarget,
        newName: z.string().optional().describe("Display name for the duplicated layer (defaults to 'original name copy')"),
      },
      annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },
    }, async (params) => {
      const script = buildDuplicateLayer(params);
      bridge.sendActivity({ type: "activity", id: "", tool: "duplicate_layer", summary: `Duplicate 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 duplicate layer" }] };
      return { content: [{ type: "text" as const, text: `Layer duplicated: ${params.target}` }] };
    });
  • Handler function for photopea_duplicate_layer: calls buildDuplicateLayer(params), sends activity, and executes script via bridge
    }, async (params) => {
      const script = buildDuplicateLayer(params);
      bridge.sendActivity({ type: "activity", id: "", tool: "duplicate_layer", summary: `Duplicate 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 duplicate layer" }] };
      return { content: [{ type: "text" as const, text: `Layer duplicated: ${params.target}` }] };
    });
  • buildDuplicateLayer helper function that generates Photopea JS script to duplicate a layer and optionally rename it
    export function buildDuplicateLayer(params: DuplicateLayerParams): string {
      const { target, newName } = params;
      const ref = layerRef(target);
      const lines: string[] = [];
      lines.push(`var _layer = ${ref};`);
      lines.push(`var _copy = _layer.duplicate();`);
      if (newName !== undefined) {
        lines.push(`_copy.name = '${escapeString(newName)}';`);
      }
      lines.push(`app.echoToOE('ok');`);
      return lines.join("\n");
    }
  • DuplicateLayerParams interface: target (string|number) and optional newName (string)
    export interface DuplicateLayerParams {
      target: string | number;
      newName?: string;
    }
Behavior4/5

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

Annotations (readOnlyHint=false, destructiveHint=false) indicate mutation without destruction, which the description reinforces by stating the duplicate becomes active and is placed above the original. The description adds the default naming behavior (original name copy), going beyond what annotations provide.

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 two sentences long with no wasted words. It front-loads the primary action and immediately provides key behavioral details. Every sentence contributes essential 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 duplication operation without an output schema, the description covers the main effects (active layer, placement, naming). It could mention limitations (e.g., background layers) but is largely sufficient given low complexity and supportive annotations.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Input schema has 100% description coverage for both parameters. The description adds the default value for newName ('original name copy') and clarifies its purpose, which is not explicitly in the schema. This exceeds the baseline expectation for high schema 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?

The description clearly states 'Create a copy of a layer in the active document,' specifying a precise verb and resource. It further distinguishes the tool by noting that the duplicate becomes active and is placed above the original, setting it apart from other layer-manipulation tools like delete_layer or reorder_layer.

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

Usage Guidelines3/5

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

The description offers a minimal usage hint: 'Use newName to distinguish the copy from the original.' However, it does not provide explicit guidance on when to use this tool versus alternatives like add_layer, nor does it mention scenarios where duplication might be inappropriate or fail.

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