* feat: enhance Excalidraw MCP with advanced canvas toolkit features - Rename skill to `excalidraw-skill` with expanded playbook and cheatsheet. - Add new MCP tools for iterative refinement: `describe_scene` and `get_canvas_screenshot`. - Implement layout tools (`align_elements`, `distribute_elements`) and `duplicate_elements`. - Add file I/O support for `.excalidraw` JSON and image export (PNG/SVG). - Introduce named snapshots for canvas state management. - Add server-side element CRUD and WebSocket handlers for real-time sync. - Normalize `points` format for arrows and lines. * docs: update README with v2.0 features and official MCP comparison * feat: implement arrow binding and edge-to-edge routing * fix: enhance security with path sanitization and improve export error handling * feat: add viewport control, design guide, and excalidraw.com URL export * feat: enhance excalidraw.com export with proper scene formatting and labels
5.2 KiB
5.2 KiB
name, description
| name | description |
|---|---|
| excalidraw-skill | Programmatic canvas toolkit for creating, editing, and refining Excalidraw diagrams via MCP tools with real-time canvas sync. Use when an agent needs to (1) draw or lay out diagrams on a live canvas, (2) iteratively refine diagrams using describe_scene and get_canvas_screenshot to see its own work, (3) export/import .excalidraw files or PNG/SVG images, (4) save/restore canvas snapshots, (5) convert Mermaid to Excalidraw, or (6) perform element-level CRUD, alignment, distribution, grouping, duplication, and locking. Requires a running canvas server (EXPRESS_SERVER_URL, default http://localhost:3000). |
Excalidraw Skill
Quick Start
- Ensure canvas server is reachable at
EXPRESS_SERVER_URL(defaulthttp://localhost:3000). - Open the canvas URL in a browser (required for image export/screenshot).
- Use MCP tools for all diagram operations; use
scripts/*.cjsfor CLI workflows. - For full tool/endpoint reference, read
references/cheatsheet.md.
Workflow: Draw A Diagram
- Call
read_diagram_guidefirst to load design best practices (colors, sizing, layout, anti-patterns). - Confirm canvas:
node scripts/healthcheck.cjsorGET /health. - Optional:
clear_canvasto start fresh. - Use
batch_create_elementswith all shapes AND arrows in one call. - Assign custom
idto shapes (e.g."id": "auth-svc"). Settextfield to label shapes. - Bind arrows to shapes using
startElementId/endElementId— arrows auto-route to element edges. align_elements/distribute_elementsafter rough placement.set_viewportwithscrollToContent: trueto auto-fit the diagram in view.describe_sceneto verify layout.get_canvas_screenshotto visually check.
Arrow Binding (Recommended)
Use startElementId and endElementId on arrows to bind them to shapes. The server automatically calculates edge-to-edge routing with proper gaps. Example:
{"elements": [
{"id": "svc-a", "type": "rectangle", "x": 0, "y": 0, "width": 120, "height": 60, "text": "Service A"},
{"id": "svc-b", "type": "rectangle", "x": 0, "y": 200, "width": 120, "height": 60, "text": "Service B"},
{"type": "arrow", "x": 0, "y": 0, "startElementId": "svc-a", "endElementId": "svc-b", "text": "calls"}
]}
Arrows without startElementId/endElementId use manual x, y, points coordinates.
Workflow: Iterative Refinement (Key Differentiator)
The feedback loop that makes this skill unique:
describe_scene-- read what's on the canvas (types, positions, labels, connections).- Decide what to change based on the description.
- Apply changes (
update_element,align_elements,create_element, etc.). get_canvas_screenshot-- visually verify the result (returns PNG to multimodal AI).- Repeat until satisfied.
Example flow:
create_element (rectangles, arrows) → describe_scene → "layout is cramped"
→ distribute_elements → get_canvas_screenshot → "arrow misaligned"
→ update_element → get_canvas_screenshot → "looks good"
→ export_scene --filePath architecture.excalidraw
Workflow: Refine An Existing Diagram
describe_sceneto understand current state.- Identify targets by id, type, or label text (not x/y coordinates).
update_elementto move/resize/recolor,delete_elementto remove.get_canvas_screenshotto verify changes visually.- If updates fail: check element id exists (
get_element), element isn't locked (unlock_elements).
Workflow: File I/O (Diagrams-as-Code)
- Export to .excalidraw format:
export_scenewith optionalfilePath. - Import from .excalidraw:
import_scenewithmode: "replace"or"merge". - Export to image:
export_to_imagewithformat: "png"or"svg"(requires browser open). - CLI export:
node scripts/export-elements.cjs --out diagram.elements.json - CLI import:
node scripts/import-elements.cjs --in diagram.elements.json --mode batch|sync
Workflow: Snapshots (Save/Restore Canvas State)
snapshot_scenewith a name before risky changes.- Make changes,
describe_scene/get_canvas_screenshotto evaluate. restore_snapshotto rollback if needed.
Workflow: Duplication
duplicate_elementswithelementIdsand optionaloffsetX/offsetY(default 20,20).- Useful for creating repeated patterns or copying existing layouts.
Points Format for Arrows/Lines
The points field accepts both formats:
- Tuple:
[[0, 0], [100, 50]] - Object:
[{"x": 0, "y": 0}, {"x": 100, "y": 50}]
Both are normalized to tuples automatically.
Workflow: Share Diagram (excalidraw.com URL)
- Create your diagram using any of the above workflows.
export_to_excalidraw_url— uploads encrypted scene, returns a shareable URL.- Share the URL — anyone can open it in excalidraw.com to view and edit.
Workflow: Viewport Control
set_viewportwithscrollToContent: true— auto-fit all elements (zoom-to-fit).set_viewportwithscrollToElementId: "my-element"— center view on a specific element.set_viewportwithzoom: 1.5, offsetX: 100, offsetY: 200— manual camera control.
References
references/cheatsheet.md: Complete MCP tool list (26 tools) + REST API endpoints + payload shapes.