delete_element
Remove an element from an Excalidraw diagram by specifying its unique ID to clean up or edit your visual workspace.
Instructions
Delete an Excalidraw element by ID
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes |
Implementation Reference
- src/mcp/tools/delete-element.ts:1-12 (handler)Main tool handler function deleteElementTool that parses input args using ElementIdSchema, calls client.deleteElement(id), and returns success/error responseimport type { CanvasClient } from '../canvas-client.js'; import { ElementIdSchema } from '../schemas/element.js'; export async function deleteElementTool( args: unknown, client: CanvasClient ) { const { id } = ElementIdSchema.parse(args); const deleted = await client.deleteElement(id); if (!deleted) throw new Error(`Element ${id} not found`); return { success: true, message: `Element ${id} deleted` }; }
- src/mcp/index.ts:139-152 (registration)Tool registration for 'delete_element' with server.tool(), including description, schema validation, and async handler that calls client.deleteElement// --- Tool: delete_element --- server.tool( 'delete_element', 'Delete an Excalidraw element by ID', { id: IdZ }, async ({ id }) => { try { const deleted = await client.deleteElement(id); if (!deleted) throw new Error(`Element ${id} not found`); return { content: [{ type: 'text', text: `Element ${id} deleted` }] }; } catch (err) { return { content: [{ type: 'text', text: `Error: ${(err as Error).message}` }], isError: true }; } }
- src/mcp/schemas/element.ts:102-106 (schema)ElementIdSchema definition using Zod to validate the id parameter (string with max length constraint)export const ElementIdSchema = z .object({ id: z.string().max(LIMITS.MAX_ID_LENGTH), }) .strict();
- src/mcp/canvas-client.ts:89-98 (handler)Canvas client deleteElement method that performs HTTP DELETE request to /api/elements/{id} endpointasync deleteElement(id: string): Promise<boolean> { const res = await fetch( `${this.baseUrl}/api/elements/${this.safePath(id)}`, { method: 'DELETE', headers: this.headers() } ); if (res.status === 404) return false; if (!res.ok) throw new Error(`Canvas error: ${res.status}`); return true; }
- Canvas client adapter deleteElement method that performs store.delete operation with loggingasync deleteElement(id: string): Promise<boolean> { const deleted = await this.store.delete(id); if (deleted) logger.debug({ id }, 'Element deleted'); return deleted; }