Excalidraw MCP
Overview
Create and refine diagrams on a live Excalidraw canvas via MCP tools, with helper scripts for export/import workflows.
Quick Start
- •Ensure the canvas server is reachable at
EXPRESS_SERVER_URL(defaulthttp://localhost:3000). - •Use MCP tools for interactive diagram edits; use
scripts/*.cjsfor file-ish workflows (export/import/clear/health). - •For detailed endpoint/tool reference, read
references/cheatsheet.md.
Workflow: Draw A Diagram (From Empty Canvas)
- •Confirm canvas is up:
- •Run
node scripts/healthcheck.cjs(or GET/health).
- •Run
- •Optional: clear the canvas:
- •Run
node scripts/clear-canvas.cjs.
- •Run
- •Create shapes first (rectangles/diamonds/ellipses), using
create_element. - •Put text on shapes by setting the shape’s
textfield (do not create a separate text element unless you need standalone text). - •Create arrows/lines after both endpoints exist.
- •Use
align_elements/distribute_elementsafter rough placement; group only after layout stabilizes.
Workflow: Refine An Existing Diagram
- •Discover what’s already there:
- •Prefer
get_resourcewithresource: "elements"orquery_elements.
- •Prefer
- •Identify targets by stable signals (id, type, label text), not by exact x/y.
- •Update with
update_element(move/resize/colors/text) or delete withdelete_element. - •If deletes/updates “don’t work”, check:
- •You’re pointing to the right
EXPRESS_SERVER_URL. - •The element id exists on the canvas (use
get_resource/GET /api/elements/:id). - •The element isn’t locked (use
unlock_elementsfirst).
- •You’re pointing to the right
Workflow: Export / Import (Repository-Friendly)
- •Export current elements to a JSON file:
- •
node scripts/export-elements.cjs --out diagram.elements.json
- •
- •Import elements (append) using batch create:
- •
node scripts/import-elements.cjs --in diagram.elements.json --mode batch
- •
- •Import elements (overwrite canvas) using sync:
- •
node scripts/import-elements.cjs --in diagram.elements.json --mode sync
- •
Notes:
- •
--mode syncclears the canvas and then writes the provided elements (good for “make canvas match this file”). - •If you want stable ids across updates, keep ids in the exported JSON; if you want fresh ids, regenerate before importing.
Workflow: CRUD Smoke Test (Create → Update → Delete)
- •Clear:
- •
node scripts/clear-canvas.cjs
- •
- •Create a large visible rectangle + label:
- •Use
node scripts/create-element.cjstwice (rectangle + text).
- •Use
- •Update:
- •Move the rectangle with
node scripts/update-element.cjs.
- •Move the rectangle with
- •Delete:
- •Remove both with
node scripts/delete-element.cjs.
- •Remove both with
References
- •
references/cheatsheet.md: MCP tool list + REST API endpoints + payload shapes