Skip to main content
Glama

update_element

Modify existing diagram elements in Excalidraw by updating properties like position, size, colors, or text content using element IDs.

Instructions

Update an existing Excalidraw element by ID

Input Schema

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

Implementation Reference

  • Main tool registration and handler for update_element. This is the MCP server tool definition that processes incoming requests, validates inputs, filters undefined values, calls the client.updateElement method, and returns the updated element as JSON.
    // --- Tool: update_element --- server.tool( 'update_element', 'Update an existing Excalidraw element by ID', { id: IdZ, ...partialElementFields }, async ({ id, ...data }) => { try { const clean = Object.fromEntries( Object.entries(data).filter(([_, v]) => v !== undefined) ); const element = await client.updateElement(id, clean); return { content: [{ type: 'text', text: JSON.stringify(element, null, 2) }] }; } catch (err) { return { content: [{ type: 'text', text: `Error: ${(err as Error).message}` }], isError: true }; } } );
  • Schema definition for UpdateElementSchema that validates the tool input. It combines a required id field with all element fields from CreateElementSchema made partial (optional).
    export const UpdateElementSchema = z .object({ id: z.string().max(LIMITS.MAX_ID_LENGTH), }) .merge(CreateElementSchema.partial()) .strict();
  • Reusable tool function that encapsulates the update logic. Parses args with UpdateElementSchema, extracts id and data, calls client.updateElement, and returns a success response with the updated element.
    export async function updateElementTool( args: unknown, client: CanvasClient ) { const { id, ...data } = UpdateElementSchema.parse(args); const element = await client.updateElement(id, data as Record<string, unknown>); return { success: true, element }; }
  • CanvasClient.updateElement method that makes a PUT request to the canvas API endpoint (/api/elements/:id) to update an existing element. Handles error responses and returns the updated element.
    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!; }
  • CanvasClientAdapter.updateElement method for standalone mode. Retrieves existing element from in-memory store, merges with new data while preserving id, createdAt, and incrementing version, then stores the updated element.
    async updateElement( id: string, data: Record<string, unknown> ): Promise<ServerElement> { const existing = await this.store.get(id); if (!existing) throw new Error(`Element ${id} not found`); const updated: ServerElement = { ...existing, ...stripUndefined(data), id: existing.id, createdAt: existing.createdAt, updatedAt: new Date().toISOString(), version: existing.version + 1, }; await this.store.set(id, updated); logger.debug({ id }, 'Element updated'); return updated;

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