Skip to main content
Glama
Abdullah007bajwa

Excalidraw MCP Server

update_element

Modify existing elements in Excalidraw diagrams by updating properties like position, size, colors, text, and styling attributes to refine visual content.

Instructions

Update an existing Excalidraw element

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYes
typeNo
xNo
yNo
widthNo
heightNo
backgroundColorNo
strokeColorNo
strokeWidthNo
roughnessNo
opacityNo
textNo
fontSizeNo
fontFamilyNo

Implementation Reference

  • Switch case handler that executes the 'update_element' tool: validates input using Zod schemas, retrieves the existing element, applies updates (handling fontFamily and opacity specially), increments version, stores the updated element, and returns confirmation.
    case 'update_element': {
      const rawParams = ElementSchema.partial().extend({ id: ElementIdSchema.shape.id }).passthrough().parse(args);
      const { id, ...updates } = rawParams;
    
      if (!id) throw new Error('Element ID is required');
    
      const existingElement = elements.get(id);
      if (!existingElement) throw new Error(`Element with ID ${id} not found`);
    
      if (typeof updates.fontFamily === 'string') {
        const fontMap = { "virgil": 1, "helvetica": 2, "cascadia": 3 };
        updates.fontFamily = fontMap[updates.fontFamily.toLowerCase()] ?? existingElement.fontFamily;
      }
    
      if (updates.opacity !== undefined) {
        updates.opacity = Math.max(0, Math.min(100, updates.opacity * 100));
      }
    
      const potentialNewElement = {
        ...existingElement,
        ...updates,
        version: (existingElement.version || 0) + 1,
        versionNonce: Math.floor(Math.random() * 2 ** 31),
        updated: Date.now()
      };
    
      Object.keys(potentialNewElement).forEach(key => {
        if (key === 'createdAt' || key === 'updatedAt') delete potentialNewElement[key];
      });
    
      elements.set(id, potentialNewElement);
      logger.info(`Element ${id} updated.`);
      logger.debug('Stored element data after update:', potentialNewElement);
    
      return {
        content: [{ type: 'text', text: JSON.stringify({ id: potentialNewElement.id, updated: true, version: potentialNewElement.version }, null, 2) }]
      };
    }
  • JSON schema for 'update_element' tool input parameters, registered in the MCP server's capabilities.tools, defining properties like id (required), type, position, styling, etc.
    update_element: {
      description: 'Update an existing Excalidraw element',
      inputSchema: {
        type: 'object',
        properties: {
          id: { type: 'string' },
          type: { 
            type: 'string', 
            enum: Object.values(EXCALIDRAW_ELEMENT_TYPES) 
          },
          x: { type: 'number' },
          y: { type: 'number' },
          width: { type: 'number' },
          height: { type: 'number' },
          backgroundColor: { type: 'string' },
          strokeColor: { type: 'string' },
          strokeWidth: { type: 'number' },
          roughness: { type: 'number' },
          opacity: { type: 'number' },
          text: { type: 'string' },
          fontSize: { type: 'number' },
          fontFamily: { type: 'string' }
        },
        required: ['id']
      }
    },
  • Zod schema for Excalidraw element properties, used in the handler for partial parsing and validation of update parameters.
    const ElementSchema = z.object({
      type: z.enum(Object.values(EXCALIDRAW_ELEMENT_TYPES)),
      x: z.number(),
      y: z.number(),
      width: z.number().optional(),
      height: z.number().optional(),
      points: z.array(z.object({ x: z.number(), y: z.number() })).optional(),
      backgroundColor: z.string().optional(),
      strokeColor: z.string().optional(),
      strokeWidth: z.number().optional(),
      roughness: z.number().optional(),
      opacity: z.number().optional(),
      text: z.string().optional(),
      fontSize: z.number().optional(),
      fontFamily: z.number().optional(),
      locked: z.boolean().optional() // ADDED: Make sure locked status is saved
    });
  • src/index.js:684-708 (registration)
    Tool registration in the ListToolsRequestHandler response, duplicating the schema for tool listing.
    name: 'update_element',
    description: 'Update an existing Excalidraw element',
    inputSchema: {
      type: 'object',
      properties: {
        id: { type: 'string' },
        type: { 
          type: 'string', 
          enum: Object.values(EXCALIDRAW_ELEMENT_TYPES) 
        },
        x: { type: 'number' },
        y: { type: 'number' },
        width: { type: 'number' },
        height: { type: 'number' },
        backgroundColor: { type: 'string' },
        strokeColor: { type: 'string' },
        strokeWidth: { type: 'number' },
        roughness: { type: 'number' },
        opacity: { type: 'number' },
        text: { type: 'string' },
        fontSize: { type: 'number' },
        fontFamily: { type: 'string' }
      },
      required: ['id']
    }

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

C2.7/5.0
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool updates elements but doesn't describe what happens during the update (e.g., partial vs. full updates, error handling, permissions required, or rate limits). For a mutation tool with zero annotation coverage, this leaves significant behavioral gaps.

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 a single, clear sentence with no wasted words. It's front-loaded with the core purpose and efficiently conveys the essential action and target. Every word earns its place, making it highly concise and well-structured.

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 complexity (14 parameters, mutation tool), lack of annotations, and no output schema, the description is incomplete. It doesn't address behavioral aspects like error conditions, return values, or usage context. While concise, it fails to provide sufficient context for effective tool selection and invocation in this environment.

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

Parameters1/5

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

The description provides no information about parameters beyond what's implied by the tool name. With 14 parameters, 0% schema description coverage, and no output schema, the description fails to add any semantic context (e.g., explaining 'id' is required, what 'type' enum values mean, or how 'opacity' scales). This is inadequate given the high parameter count and low schema coverage.

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

Purpose4/5

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

The description clearly states the action ('Update') and resource ('an existing Excalidraw element'), making the purpose immediately understandable. It distinguishes itself from siblings like 'create_element' and 'delete_element' by specifying it's for existing elements, though it doesn't explicitly contrast with similar tools like 'query_elements' or 'lock_elements'.

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., needing an element ID), exclusions (e.g., not for new elements), or comparisons to siblings like 'create_element' for new elements or 'query_elements' for retrieval. Usage is implied but not explicitly stated.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.