Group Layers
photopea_group_layersGroup multiple layers into a layer folder by specifying layer names. Use with get_layers to find names, and ungroup_layers to reverse. Organize your layers panel efficiently.
Instructions
Group multiple layers into a layer group (folder). Layers are specified by name — use get_layers to find layer names. Grouped layers can be ungrouped later with ungroup_layers.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| layers | Yes | Array of layer names to include in the group (use get_layers to find names) | |
| groupName | No | Display name for the group folder in the layers panel |
Implementation Reference
- src/tools/layer.ts:165-179 (registration)Registration of photopea_group_layers tool on the MCP server with title, description, input schema (layers, groupName), and annotations.
server.registerTool("photopea_group_layers", { title: "Group Layers", description: "Group multiple layers into a layer group (folder). Layers are specified by name — use get_layers to find layer names. Grouped layers can be ungrouped later with ungroup_layers.", inputSchema: { layers: z.array(z.string()).describe("Array of layer names to include in the group (use get_layers to find names)"), groupName: z.string().optional().describe("Display name for the group folder in the layers panel"), }, annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false }, }, async (params) => { const script = buildGroupLayers(params); bridge.sendActivity({ type: "activity", id: "", tool: "group_layers", summary: `Group ${params.layers.length} layers` }); const result = await bridge.executeScript(script); if (!result.success) return { isError: true, content: [{ type: "text" as const, text: result.error || "Failed to group layers" }] }; return { content: [{ type: "text" as const, text: `Layers grouped${params.groupName ? `: ${params.groupName}` : ""}` }] }; }); - src/tools/layer.ts:173-179 (handler)Handler function for photopea_group_layers: calls buildGroupLayers, sends activity, executes script, returns success/error.
}, async (params) => { const script = buildGroupLayers(params); bridge.sendActivity({ type: "activity", id: "", tool: "group_layers", summary: `Group ${params.layers.length} layers` }); const result = await bridge.executeScript(script); if (!result.success) return { isError: true, content: [{ type: "text" as const, text: result.error || "Failed to group layers" }] }; return { content: [{ type: "text" as const, text: `Layers grouped${params.groupName ? `: ${params.groupName}` : ""}` }] }; }); - src/bridge/script-builder.ts:341-360 (helper)buildGroupLayers function that generates the Photopea JavaScript to create a layer group and move specified layers into it.
export function buildGroupLayers(params: GroupLayersParams): string { const { layers, groupName } = params; const lines: string[] = []; lines.push(`var _group = app.activeDocument.layerSets.add();`); if (groupName !== undefined) { lines.push(`_group.name = '${escapeString(groupName)}';`); } // Move each named layer into the group for (const layerName of layers) { const safe = escapeString(layerName); lines.push( `app.activeDocument.layers.getByName('${safe}').move(_group, ElementPlacement.PLACEATEND);` ); } lines.push(`app.echoToOE('ok');`); return lines.join("\n"); } - src/bridge/types.ts:146-149 (schema)TypeScript interface GroupLayersParams defining the shape parameters: layers (string[]) and optional groupName.
export interface GroupLayersParams { layers: string[]; groupName?: string; }