Skip to main content
Glama

Ungroup Layers

photopea_ungroup_layers

Ungroup a layer group by moving all its child layers to the document root, removing the group folder while preserving contents.

Instructions

Dissolve a layer group, moving all child layers to the document root. The group folder is removed but its contents are preserved. Use get_layers to find group names.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
targetYesName of the layer group to ungroup (use get_layers to find group names)

Implementation Reference

  • The async handler function for photopea_ungroup_layers. It escapes the target layer group name, builds a JavaScript script to move all child layers out of the group to the document root, removes the now-empty group, sends an activity log, executes the script, and returns success/failure.
    }, async (params) => {
      const safe = escapeString(params.target);
      const script = [
        `var _d = app.activeDocument;`,
        `var _g = _d.layerSets.getByName('${safe}');`,
        `while (_g.layers.length > 0) { _g.layers[0].move(_d.layers[_d.layers.length - 1], ElementPlacement.PLACEBEFORE); }`,
        `_g.remove();`,
        `app.echoToOE('ok');`,
      ].join("\n");
      bridge.sendActivity({ type: "activity", id: "", tool: "ungroup_layers", summary: `Ungroup: ${params.target}` });
      const result = await bridge.executeScript(script);
      if (!result.success) return { isError: true, content: [{ type: "text" as const, text: result.error || "Failed to ungroup layers" }] };
      return { content: [{ type: "text" as const, text: `Group ungrouped: ${params.target}` }] };
    });
  • Input schema for photopea_ungroup_layers: requires a single string parameter 'target' (name of the layer group to ungroup).
    inputSchema: {
      target: z.string().describe("Name of the layer group to ungroup (use get_layers to find group names)"),
    },
  • Registration of the tool 'photopea_ungroup_layers' using server.registerTool with title, description, inputSchema, annotations, and the handler function.
    // photopea_ungroup_layers
    server.registerTool("photopea_ungroup_layers", {
      title: "Ungroup Layers",
      description: "Dissolve a layer group, moving all child layers to the document root. The group folder is removed but its contents are preserved. Use get_layers to find group names.",
      inputSchema: {
        target: z.string().describe("Name of the layer group to ungroup (use get_layers to find group names)"),
      },
      annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false },
    }, async (params) => {
      const safe = escapeString(params.target);
      const script = [
        `var _d = app.activeDocument;`,
        `var _g = _d.layerSets.getByName('${safe}');`,
        `while (_g.layers.length > 0) { _g.layers[0].move(_d.layers[_d.layers.length - 1], ElementPlacement.PLACEBEFORE); }`,
        `_g.remove();`,
        `app.echoToOE('ok');`,
      ].join("\n");
      bridge.sendActivity({ type: "activity", id: "", tool: "ungroup_layers", summary: `Ungroup: ${params.target}` });
      const result = await bridge.executeScript(script);
      if (!result.success) return { isError: true, content: [{ type: "text" as const, text: result.error || "Failed to ungroup layers" }] };
      return { content: [{ type: "text" as const, text: `Group ungrouped: ${params.target}` }] };
    });
  • The escapeString helper used by the handler to safely escape the target layer group name before embedding it in the JavaScript script.
    export function escapeString(str: string): string {
      return str.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/\n/g, "\\n").replace(/\r/g, "\\r");
    }
Behavior4/5

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

The description adds detail beyond annotations: it states the group folder is removed but contents are preserved. Annotations show destructiveHint=false, which aligns with 'contents preserved'. No contradictions.

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 no wasted words. The most critical information is front-loaded: the action and its effect.

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 one-parameter operation, the description covers purpose, effect, and prerequisite (use get_layers). No output schema, but results are straightforward. Could mention undo capability, but not essential.

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 fully describes the single required parameter 'target' with a clear description. The tool description adds no new param details beyond referencing 'get_layers', but schema coverage is 100%, so baseline 3 is appropriate.

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 uses a specific verb ('Dissolve') and clearly states the resource ('layer group') and its effect ('moving all child layers to the document root'). It distinguishes from sibling tools like 'group_layers' and 'delete_layer'.

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?

It explicitly states the use case (dissolving a group) and recommends using 'get_layers' to find group names. While it doesn't mention when to avoid this tool or provide alternatives, the context is clear for a simple operation.

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