Skip to main content
Glama

ungroup_elements

Remove elements from a group in Excalidraw diagrams by specifying the group ID to edit individual components separately.

Instructions

Remove elements from a group by group ID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
groupIdYes

Implementation Reference

  • Core handler function ungroupElementsTool that removes elements from a group by filtering all elements, finding those with the specified groupId, and updating each element to remove that groupId from their groupIds array.
    export async function ungroupElementsTool(
      args: unknown,
      client: CanvasClient
    ) {
      const { groupId } = GroupIdSchema.parse(args);
      const allElements = await client.getAllElements();
    
      const grouped = allElements.filter(
        (el) => el.groupIds && el.groupIds.includes(groupId)
      );
    
      if (grouped.length === 0) {
        throw new Error(`No elements found with groupId ${groupId}`);
      }
    
      let ungroupedCount = 0;
      for (const element of grouped) {
        const updatedGroupIds = (element.groupIds ?? []).filter(
          (gid) => gid !== groupId
        );
        await client.updateElement(element.id, { groupIds: updatedGroupIds });
        ungroupedCount++;
      }
    
      return { success: true, groupId, ungroupedCount };
    }
  • MCP tool registration for 'ungroup_elements' with inline schema definition (groupId as string with max length limit) and the handler logic that calls getAllElements, filters by groupId, and updates each element to remove the group.
    // --- Tool: ungroup_elements ---
    server.tool(
      'ungroup_elements',
      'Remove elements from a group by group ID',
      { groupId: z.string().max(LIMITS.MAX_GROUP_ID_LENGTH) },
      async ({ groupId }) => {
        try {
          const all = await client.getAllElements();
          const inGroup = all.filter(e => e.groupIds?.includes(groupId));
          if (inGroup.length === 0) {
            throw new Error(`No elements found with groupId ${groupId}`);
          }
    
          for (const el of inGroup) {
            const newGroups = (el.groupIds ?? []).filter(g => g !== groupId);
            await client.updateElement(el.id, { groupIds: newGroups });
          }
    
          return {
            content: [{
              type: 'text',
              text: JSON.stringify({ groupId, ungroupedCount: inGroup.length }, null, 2),
            }],
          };
        } catch (err) {
          return { content: [{ type: 'text', text: `Error: ${(err as Error).message}` }], isError: true };
        }
      }
    );
  • GroupIdSchema validation schema that defines the input structure with a groupId field as a string with maximum length constraint, used by the ungroup-elements tool handler.
    export const GroupIdSchema = z
      .object({
        groupId: z.string().max(LIMITS.MAX_GROUP_ID_LENGTH),
      })
      .strict();
  • Export statement that makes ungroupElementsTool available from the tools index module.
    export { ungroupElementsTool } from './ungroup-elements.js';

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/debu-sinha/excalidraw-mcp-server'

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