Skip to main content
Glama

group_elements

Combine multiple diagram elements into a single group for easier management and manipulation in Excalidraw diagrams.

Instructions

Group multiple elements together

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
elementIdsYes

Implementation Reference

  • Main handler implementation of group_elements tool. Parses input using GroupElementsSchema, generates a new group ID, and iterates through elements to update their groupIds array with the new groupId. Returns success status, groupId, elementIds, and successCount.
    export async function groupElementsTool(
      args: unknown,
      client: CanvasClient
    ) {
      const { elementIds } = GroupElementsSchema.parse(args);
      const groupId = generateId();
      let successCount = 0;
    
      for (const id of elementIds) {
        const element = await client.getElement(id);
        if (!element) continue;
    
        const existingGroupIds = element.groupIds ?? [];
        const updatedGroupIds = [...existingGroupIds, groupId];
        await client.updateElement(id, { groupIds: updatedGroupIds });
        successCount++;
      }
    
      return { success: true, groupId, elementIds, successCount };
    }
  • Zod schema definition for group_elements input validation. Requires an array of elementIds (strings) with minimum 2 elements and maximum MAX_ELEMENT_IDS. Also exports TypeScript type GroupElements.
    export const GroupElementsSchema = z
      .object({
        elementIds: z
          .array(z.string().max(LIMITS.MAX_ID_LENGTH))
          .min(2)
          .max(LIMITS.MAX_ELEMENT_IDS),
      })
      .strict();
  • MCP server registration of group_elements tool with full inline handler implementation. Registers tool with name 'group_elements', description, input schema validation, and async handler that wraps the grouping logic.
    // --- Tool: group_elements ---
    server.tool(
      'group_elements',
      'Group multiple elements together',
      { elementIds: z.array(IdZ).min(2).max(LIMITS.MAX_ELEMENT_IDS) },
      async ({ elementIds }) => {
        try {
          const { generateId } = await import('../shared/id.js');
          const groupId = generateId();
          let successCount = 0;
    
          for (const eid of elementIds) {
            const el = await client.getElement(eid);
            if (!el) continue;
            const existingGroups = el.groupIds ?? [];
            await client.updateElement(eid, {
              groupIds: [...existingGroups, groupId],
            });
            successCount++;
          }
    
          return {
            content: [{
              type: 'text',
              text: JSON.stringify({ groupId, elementIds, successCount }, null, 2),
            }],
          };
        } catch (err) {
          return { content: [{ type: 'text', text: `Error: ${(err as Error).message}` }], isError: true };
        }
      }
    );
  • Helper function to generate random IDs using crypto. Used by group_elements to generate unique group IDs when grouping multiple elements together.
    export function generateId(): string {
      return crypto.randomBytes(16).toString('hex');
    }
  • CanvasClient helper method updateElement used by group_elements handler to update each element's groupIds array. Makes PUT request to update element on the canvas server.
    async updateElement(
      id: string,
      data: Record<string, unknown>
    ): Promise<ServerElement> {
      const res = await fetch(
        `${this.baseUrl}/api/elements/${this.safePath(id)}`,
        {
          method: 'PUT',
          headers: this.headers(),
          body: JSON.stringify(data),
        }
      );
    
      if (!res.ok) {
        const body = await res.json().catch(() => ({})) as ApiResponse;
        throw new Error(body.error ?? `Canvas error: ${res.status}`);
      }
    
      const body = await res.json() as { element?: ServerElement };
      return body.element!;
    }
Behavior2/5

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

With no annotations provided, the description carries full burden but offers minimal behavioral insight. It states the action but doesn't disclose critical traits like whether grouping is reversible, requires permissions, affects element properties, or has side effects. The description doesn't contradict annotations (none exist), but it fails to compensate for their absence.

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 extremely concise with a single, front-loaded sentence that directly states the tool's purpose. There is zero wasted verbiage, and it efficiently communicates the core action without unnecessary details.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (a mutation operation with no annotations or output schema), the description is incomplete. It lacks information about what grouping means in this context, the result of the operation, error conditions, or how it interacts with sibling tools. The description alone is insufficient for an agent to use the tool effectively without additional context.

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 description adds no parameter semantics beyond what the input schema provides. Schema description coverage is 0%, but the single parameter 'elementIds' is self-explanatory from its name and schema constraints (array of strings, min 2, max 500). Since there's only one parameter, the baseline is 4, but the description doesn't enhance understanding (e.g., explain what element IDs are or how to obtain them), so it scores slightly lower.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Group multiple elements together' clearly states the action (group) and target (elements), but it's somewhat vague about what grouping entails and doesn't differentiate from sibling tools like 'align_elements' or 'distribute_elements' which also manipulate multiple elements. It avoids tautology by not just restating the name.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., elements must exist), exclusions (e.g., cannot group locked elements), or compare to related tools like 'ungroup_elements' or 'batch_create_elements'. Usage is implied only by the tool name.

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

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