delete_element
Remove a specific element from an Excalidraw diagram by its unique ID using the structured API of the Excalidraw MCP Server.
Instructions
Delete an Excalidraw element
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes |
Implementation Reference
- src/index.ts:603-623 (handler)Main handler logic for the 'delete_element' tool: validates input using ElementIdSchema, calls deleteElementOnCanvas helper, checks success, logs, and returns formatted response.case 'delete_element': { const params = ElementIdSchema.parse(args); const { id } = params; // Delete element directly on HTTP server (no local storage) const canvasResult = await deleteElementOnCanvas(id); if (!canvasResult || !(canvasResult as ApiResponse).success) { throw new Error('Failed to delete element: HTTP server unavailable or element not found'); } const result = { id, deleted: true, syncedToCanvas: true }; logger.info('Element deleted via MCP and synced to canvas', result); return { content: [{ type: 'text', text: `Element deleted successfully!\n\n${JSON.stringify(result, null, 2)}\n\n✅ Synced to canvas` }] }; }
- src/index.ts:286-296 (schema)Tool definition including name, description, and inputSchema for 'delete_element' used in tool registration and capabilities.{ name: 'delete_element', description: 'Delete an Excalidraw element', inputSchema: { type: 'object', properties: { id: { type: 'string' } }, required: ['id'] } },
- src/index.ts:133-136 (helper)Helper function that performs the actual deletion by syncing to the canvas HTTP API using syncToCanvas.async function deleteElementOnCanvas(elementId: string): Promise<any> { const result = await syncToCanvas('delete', { id: elementId }); return result; }
- src/index.ts:200-202 (schema)Zod schema for validating the 'id' input parameter used in the delete_element handler.const ElementIdSchema = z.object({ id: z.string() });
- src/index.ts:490-504 (registration)Server initialization where all tools, including 'delete_element', are registered via the tools array and capabilities.const server = new Server( { name: "mcp-excalidraw-server", version: "1.0.2", description: "Advanced MCP server for Excalidraw with real-time canvas" }, { capabilities: { tools: Object.fromEntries(tools.map(tool => [tool.name, { description: tool.description, inputSchema: tool.inputSchema }])) } } );