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).
git clone https://github.com/yctimlin/mcp_excalidraw
T=$(mktemp -d) && git clone --depth=1 https://github.com/yctimlin/mcp_excalidraw "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/excalidraw-skill" ~/.claude/skills/yctimlin-mcp-excalidraw-excalidraw-skill && rm -rf "$T"
skills/excalidraw-skill/SKILL.mdExcalidraw Skill
Step 0: Determine Connection Mode
Two modes are available. Try MCP first — it has more capabilities.
MCP mode (preferred): If
excalidraw/batch_create_elements and other excalidraw/* tools appear in your tool list, use them directly. MCP tools handle label and arrow binding format automatically.
REST API mode (fallback): If MCP tools aren't available, use HTTP endpoints at
http://localhost:3000. See the cheatsheet for REST payloads. Note the format differences in the table below — REST and MCP accept slightly different field names.
Neither works? Tell the user:
The Excalidraw canvas server is not running. To set up:
git clone https://github.com/yctimlin/mcp_excalidraw && cd mcp_excalidrawnpm ci && npm run buildPORT=3000 npm run canvas- Open
in a browserhttp://localhost:3000- (Recommended) Install the MCP server:
claude mcp add excalidraw -s user -e EXPRESS_SERVER_URL=http://localhost:3000 -- node /path/to/mcp_excalidraw/dist/index.js
MCP vs REST API Quick Reference
| Operation | MCP Tool | REST API Equivalent |
|---|---|---|
| Create elements | | |
| Get all elements | | |
| Get one element | | |
| Update element | | |
| Delete element | | |
| Clear canvas | | |
| Describe scene | | (parse manually) |
| Export scene | | (save to file) |
| Import scene | | |
| Snapshot | | |
| Restore snapshot | | then |
| Screenshot | | (needs browser) |
| Viewport | | (needs browser) |
| Export image | | (needs browser) |
| Export URL | | Only via MCP |
Format Differences Between Modes (Critical)
- Labels: MCP accepts
on shapes (auto-converts). REST requires"text": "My Label"
."label": {"text": "My Label"} - Arrow binding: MCP accepts
/startElementId
. REST requiresendElementId
/"start": {"id": "..."}
."end": {"id": "..."} - fontFamily: Must be a string (e.g.
) or omit entirely. Never pass a number."1" - Updating labels via REST: Re-include
in the PUT body to ensure it renders correctly after updates."label"
Coordinate System
The canvas uses a 2D coordinate grid: (0, 0) is the origin, x increases rightward, y increases downward. Plan your layout before writing any JSON.
General spacing guidelines:
- Vertical spacing between tiers: 80–120px (enough that arrows don't crowd labels)
- Horizontal spacing between siblings: 40–60px minimum
- Shape width:
to prevent text truncationmax(160, labelCharCount * 9) - Shape height: 60px single-line, 80px two-line labels
- Background/zone padding: 50px on all sides around contained elements
Layout Anti-Patterns (Critical for Complex Diagrams)
These are the most common mistakes that produce unreadable diagrams. Avoid all of them.
1. Do NOT use label.text
(or text
) on large background zone rectangles
label.texttextWhen you put a label on a background rectangle, Excalidraw creates a bound text element centered in the middle of that shape — right where your service boxes will be placed. The text overlaps everything inside the zone and cannot be repositioned.
Wrong:
{"id": "vpc-zone", "type": "rectangle", "x": 50, "y": 50, "width": 800, "height": 400, "text": "VPC (10.0.0.0/16)"}
Right — use a free-standing text element anchored at the top of the zone:
{"id": "vpc-zone", "type": "rectangle", "x": 50, "y": 50, "width": 800, "height": 400, "backgroundColor": "#e3f2fd"}, {"id": "vpc-label", "type": "text", "x": 70, "y": 60, "width": 300, "height": 30, "text": "VPC (10.0.0.0/16)", "fontSize": 18, "fontWeight": "bold"}
The free-standing text element sits at the top corner of the zone and doesn't interfere with elements placed inside.
2. Avoid cross-zone arrows in complex diagrams
An arrow from an element in one layout zone to an element in a distant zone will draw a long diagonal line crossing through everything in between. In a multi-zone infra diagram this produces an unreadable tangle of spaghetti.
Design rule: Keep arrows within the same zone or tier. To show cross-zone relationships, use annotation text or separate the zones so their edges are adjacent (no elements between them), and route the arrow along the edge.
If you must connect across zones, use an elbowed arrow that travels along the perimeter — never through the middle of another zone.
3. Use arrow labels sparingly
Arrow labels are placed at the midpoint of the arrow. On short arrows, they overlap the shapes at both ends. On crowded diagrams, they collide with nearby elements.
- Only add an arrow label when the relationship name is genuinely essential (e.g., protocol, port number, data direction).
- If you're adding a label to every arrow, reconsider — it usually adds visual noise, not clarity.
- Keep arrow labels to ≤ 12 characters. Prefer omitting them entirely on dense diagrams.
Quality: Why It Matters (and How to Check)
Excalidraw diagrams are visual communication. If text is cut off, elements overlap, or arrows cross through unrelated shapes, the diagram becomes confusing and unprofessional — it defeats the whole purpose of drawing it. So after every batch of elements, verify before adding more.
Quality Checklist
After each
batch_create_elements / POST /api/elements/batch, take a screenshot and check:
- Text truncation — Is all label text fully visible? Truncated text means the shape is too small. Increase
and/orwidth
.height - Overlap — Do any shapes share the same space? Background zones must fully contain children with padding.
- Arrow crossing — Do arrows cut through unrelated elements? If yes, route them around using curved or elbowed arrows (see Arrow Routing below).
- Arrow-label overlap — Arrow labels sit at the midpoint. If they overlap a shape, shorten the label or adjust the arrow path.
- Spacing — At least 40px gap between elements. Cramped layouts are hard to read.
- Readability — Font size ≥ 16 for body text, ≥ 20 for titles.
- Zone label placement — If you used
/text
on a background zone rectangle, the zone label will be centered in the middle of the zone, overlapping everything inside. Fix: delete the bound text element and add a free-standing text element at the top of the zone instead (see Layout Anti-Patterns above).label.text
If you find any issue: stop, fix it, re-screenshot, then continue. Say "I see [issue], fixing it" rather than glossing over problems. Only proceed once all checks pass.
Workflow: Drawing a New Diagram
Mermaid vs. Direct Creation — Which to Use?
Use
when: the user already has a Mermaid diagram, or the structure maps cleanly to a flowchart/sequence/ER diagram with standard Mermaid syntax. It's fast and handles conversion automatically, though you get less control over exact layout.create_from_mermaid
Use
directly when: you need precise layout control, the diagram type doesn't map to Mermaid well (e.g., custom architecture, annotated cloud diagrams), or you want elements positioned in a specific coordinate grid.batch_create_elements
MCP Mode
- Call
for design best practices (colors, fonts, anti-patterns).read_diagram_guide - Plan your coordinate grid on paper/in comments — map out tiers and x-positions before writing JSON.
- Optional:
to start fresh.clear_canvas - Use
— create shapes and arrows in one call. Custombatch_create_elements
fields (e.g.id
) make later updates easy."id": "auth-svc" - Set shape widths using
. Usemax(160, labelLength * 9)
field for labels.text - Bind arrows with
/startElementId
— they auto-route to element edges.endElementId
withset_viewport
to auto-fit.scrollToContent: true
→ run Quality Checklist → fix issues before next iteration.get_canvas_screenshot
MCP element + arrow example:
{"elements": [ {"id": "lb", "type": "rectangle", "x": 300, "y": 50, "width": 180, "height": 60, "text": "Load Balancer"}, {"id": "svc-a", "type": "rectangle", "x": 100, "y": 200, "width": 160, "height": 60, "text": "Web Server 1"}, {"id": "svc-b", "type": "rectangle", "x": 450, "y": 200, "width": 160, "height": 60, "text": "Web Server 2"}, {"id": "db", "type": "rectangle", "x": 275, "y": 350, "width": 210, "height": 60, "text": "PostgreSQL"}, {"type": "arrow", "x": 0, "y": 0, "startElementId": "lb", "endElementId": "svc-a"}, {"type": "arrow", "x": 0, "y": 0, "startElementId": "lb", "endElementId": "svc-b"}, {"type": "arrow", "x": 0, "y": 0, "startElementId": "svc-a", "endElementId": "db"}, {"type": "arrow", "x": 0, "y": 0, "startElementId": "svc-b", "endElementId": "db"} ]}
REST API Mode
- Plan your coordinate grid first.
- Optional:
curl -X DELETE http://localhost:3000/api/elements/clear - Create elements using
. UsePOST /api/elements/batch
for labels."label": {"text": "..."} - Bind arrows with
/"start": {"id": "..."}
."end": {"id": "..."} - Verify with
→ save PNG → run Quality Checklist.POST /api/export/image
REST API element + arrow example:
curl -X POST http://localhost:3000/api/elements/batch \ -H "Content-Type: application/json" \ -d '{ "elements": [ {"id": "svc-a", "type": "rectangle", "x": 100, "y": 100, "width": 160, "height": 60, "label": {"text": "Service A"}}, {"id": "svc-b", "type": "rectangle", "x": 400, "y": 100, "width": 160, "height": 60, "label": {"text": "Service B"}}, {"type": "arrow", "x": 0, "y": 0, "start": {"id": "svc-a"}, "end": {"id": "svc-b"}, "label": {"text": "calls"}} ] }'
Arrow Routing — Avoid Overlaps
Straight arrows can cross through elements in complex diagrams. Use curved or elbowed arrows when needed:
Curved arrows (smooth arc over obstacles):
{ "type": "arrow", "x": 100, "y": 100, "points": [[0, 0], [50, -40], [200, 0]], "roundness": {"type": 2} }
The intermediate waypoint
[50, -40] lifts the arrow upward. roundness: {type: 2} makes it smooth.
Elbowed arrows (right-angle / L-shaped routing):
{ "type": "arrow", "x": 100, "y": 100, "points": [[0, 0], [0, -50], [200, -50], [200, 0]], "elbowed": true }
When to use which:
- Fan-out (one source → many targets): curved arrows with waypoints spread to avoid overlapping
- Cross-lane (connecting to side panels): elbowed arrows that go up, then across, then down
- Long horizontal connections: curved arrows with a slight vertical offset
Rule: If an arrow would pass through an unrelated shape, add a waypoint to route around it.
Points format: Both
[[x, y], ...] tuples and [{"x": ..., "y": ...}] objects are accepted; both are normalized automatically.
Workflow: Iterative Refinement
Using
describe_scene and get_canvas_screenshot together is what makes this skill powerful.
→ returns structured text: element IDs, types, positions, labels, connections. Use this when you need to know what's on the canvas before making programmatic updates (find IDs, understand bounding boxes).describe_scene
→ returns a PNG image of the actual rendered canvas. Use this for visual quality verification — it shows you exactly what the user sees, including truncation, overlap, and arrow routing.get_canvas_screenshot
Feedback loop (MCP):
batch_create_elements → get_canvas_screenshot → "text truncated on auth-svc" → update_element (increase width) → get_canvas_screenshot → "overlap between auth-svc and rate-limiter" → update_element (reposition) → get_canvas_screenshot → "all checks pass" → proceed
Feedback loop (REST):
POST /api/elements/batch → POST /api/export/image → save PNG → evaluate → PUT /api/elements/:id (fix issues) → re-screenshot → evaluate → proceed
Workflow: Refine an Existing Diagram
to understand current state — note element IDs and positions.describe_scene- Identify elements by
or label text (not by x/y coordinates — they change).id
to resize/recolor/move;update_element
to remove.delete_element
to confirm the change looks right.get_canvas_screenshot- If updates fail: check the ID exists with
; check it's not locked withget_element
.unlock_elements
Workflow: Mermaid Conversion
For converting existing Mermaid diagrams to Excalidraw:
MCP mode:
create_from_mermaid(mermaidDiagram: "graph TD\n A --> B\n B --> C")
After conversion, call
set_viewport with scrollToContent: true and get_canvas_screenshot to verify layout. If the auto-layout is poor (nodes crowded, edges crossing), identify problem elements with describe_scene and reposition with update_element.
REST mode:
curl -X POST http://localhost:3000/api/elements/from-mermaid \ -H "Content-Type: application/json" \ -d '{"mermaid": "graph TD\n A --> B\n B --> C"}'
Workflow: File I/O
- Export to
:.excalidraw
with optionalexport_scenefilePath - Import from
:.excalidraw
withimport_scene
ormode: "replace""merge" - Export to image:
withexport_to_image
orformat: "png"
(requires browser open)"svg" - Share link:
— encrypts scene, returns shareable excalidraw.com URLexport_to_excalidraw_url - 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
with a name before risky changes.snapshot_scene- Make changes, evaluate with
/describe_scene
.get_canvas_screenshot
to roll back if needed.restore_snapshot
Workflow: Duplication
duplicate_elements with elementIds and optional offsetX/offsetY (default: 20, 20). Useful for repeated patterns or copying layouts.
Error Recovery
- Elements not appearing? Check
— they may have been created off-screen. Usedescribe_scene
withset_viewport
.scrollToContent: true - Arrow not connecting? Verify element IDs with
. Make sureget_element
/startElementId
(MCP) orendElementId
/start.id
(REST) match existing element IDs.end.id - Canvas in a bad state?
first, thensnapshot_scene
and rebuild. Orclear_canvas
to go back.restore_snapshot - Element won't update? It may be locked — call
first.unlock_elements - Layout looking wrong after import? Use
to inspect actual positions, then batch-update positions.describe_scene - Duplicate text elements / element count doubling? The frontend has an auto-sync timer that periodically sends the full Excalidraw scene back to the server (overwriting). Excalidraw internally generates a bound text element for every shape that has
. If you clear and re-send elements, Excalidraw may re-inject its cached bound texts, causing duplicates. To clean up: (1) uselabel.text
/query_elements
to find elements ofGET /api/elements
with atype: "text"
; (2) delete the unwanted ones withcontainerId
; (3) wait a few seconds for auto-sync to settle before exporting. The safest approach is to never put labels on background zone rectangles — use free-standing text elements instead.delete_element
References
: Complete MCP tool list (26 tools) + REST API endpoints + payload shapes.references/cheatsheet.md