excalidraw-mcp
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseExcalidraw MCP
Excalidraw MCP
Overview
概述
Create and refine diagrams on a live Excalidraw canvas via MCP tools, with helper scripts for export/import workflows.
通过MCP工具在实时Excalidraw画布上创建和优化图表,同时提供用于导出/导入工作流的辅助脚本。
Quick Start
快速开始
- Ensure the canvas server is reachable at (default
EXPRESS_SERVER_URL).http://localhost:3000 - Use MCP tools for interactive diagram edits; use for file-ish workflows (export/import/clear/health).
scripts/*.cjs - For detailed endpoint/tool reference, read .
references/cheatsheet.md
- 确保画布服务器可通过访问(默认地址为
EXPRESS_SERVER_URL)。http://localhost:3000 - 使用MCP工具进行交互式图表编辑;使用脚本处理类文件工作流(导出/导入/清空/健康检查)。
scripts/*.cjs - 如需详细的端点/工具参考,请阅读。
references/cheatsheet.md
Workflow: Draw A Diagram (From Empty Canvas)
工作流:从零画布绘制图表
- Confirm canvas is up:
- Run (or GET
node scripts/healthcheck.cjs)./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 field (do not create a separate text element unless you need standalone text).
text - Create arrows/lines after both endpoints exist.
- Use /
align_elementsafter rough placement; group only after layout stabilizes.distribute_elements
- 确认画布正常运行:
- 运行(或发送GET请求至
node scripts/healthcheck.cjs)。/health
- 运行
- 可选操作:清空画布:
- 运行。
node scripts/clear-canvas.cjs
- 运行
- 首先创建形状(矩形/菱形/椭圆),使用工具。
create_element - 通过设置形状的字段为形状添加文本(除非需要独立文本,否则无需创建单独的文本元素)。
text - 在两个端点都创建完成后,再创建箭头/线条。
- 大致布局完成后,使用/
align_elements工具;仅在布局稳定后再进行分组操作。distribute_elements
Workflow: Refine An Existing Diagram
工作流:优化现有图表
- Discover what’s already there:
- Prefer with
get_resourceorresource: "elements".query_elements
- Prefer
- Identify targets by stable signals (id, type, label text), not by exact x/y.
- Update with (move/resize/colors/text) or delete with
update_element.delete_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 first).
unlock_elements
- You’re pointing to the right
- 查看画布现有内容:
- 优先使用并指定
get_resource,或使用resource: "elements"工具。query_elements
- 优先使用
- 通过稳定标识(id、类型、标签文本)定位目标元素,而非依赖精确的x/y坐标。
- 使用工具进行更新(移动/调整大小/修改颜色/文本),或使用
update_element工具删除元素。delete_element - 如果删除/更新操作未生效,请检查:
- 你指向的是否正确。
EXPRESS_SERVER_URL - 元素id是否存在于画布上(使用/ 发送GET请求至
get_resource)。/api/elements/:id - 元素是否被锁定(先使用工具解锁)。
unlock_elements
- 你指向的
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:
- clears the canvas and then writes the provided elements (good for “make canvas match this file”).
--mode sync - If you want stable ids across updates, keep ids in the exported JSON; if you want fresh ids, regenerate before importing.
- 将当前元素导出为JSON文件:
- 运行
node scripts/export-elements.cjs --out diagram.elements.json
- 运行
- 使用批量创建方式导入元素(追加模式):
- 运行
node scripts/import-elements.cjs --in diagram.elements.json --mode batch
- 运行
- 使用同步方式导入元素(覆盖画布):
- 运行
node scripts/import-elements.cjs --in diagram.elements.json --mode sync
- 运行
注意事项:
- 模式会先清空画布,再写入提供的元素(适用于“让画布与文件内容保持一致”的场景)。
--mode sync - 如果希望在更新过程中保持id稳定,请保留导出JSON中的id;如果需要新的id,请在导入前重新生成。
Workflow: CRUD Smoke Test (Create → Update → Delete)
工作流:CRUD冒烟测试(创建→更新→删除)
- Clear:
node scripts/clear-canvas.cjs
- Create a large visible rectangle + label:
- Use twice (rectangle + text).
node scripts/create-element.cjs
- 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
- 清空画布:
- 运行
node scripts/clear-canvas.cjs
- 运行
- 创建一个大的可见矩形和标签:
- 运行两次(分别创建矩形和文本)。
node scripts/create-element.cjs
- 运行两次
- 更新元素:
- 使用移动矩形。
node scripts/update-element.cjs
- 使用
- 删除元素:
- 使用删除这两个元素。
node scripts/delete-element.cjs
- 使用
References
参考资料
- : MCP tool list + REST API endpoints + payload shapes
references/cheatsheet.md
- :MCP工具列表 + REST API端点 + 负载结构
references/cheatsheet.md