AgentSkillsCN

excalidraw-diagrams

使用 Excalidraw 创作图表与可视化作品,并支持实时画布预览。当用户提出创建、绘制或可视化图表、流程图、架构图、系统设计,或任何其他形式的可视化表达时,可调用此技能。支持以编程方式创建元素、转换 Mermaid 图表,并通过截图进行可视化验证。

SKILL.md
--- frontmatter
name: excalidraw-diagrams
description: Create diagrams and visual artifacts using Excalidraw with real-time canvas preview. Use when the user asks to create, draw, or visualize diagrams, flowcharts, architecture diagrams, system designs, or any visual representation. Supports creating elements programmatically, Mermaid diagram conversion, and visual verification via screenshots.
license: Apache-2.0

Excalidraw Diagrams

Create diagrams using the Excalidraw canvas server and verify output with screenshots.

Prerequisites

  1. Canvas server running at http://localhost:3000

    bash
    cd ${MCP_EXCALIDRAW_PATH:-~/code/mcp_excalidraw} && npm run canvas
    

    Set MCP_EXCALIDRAW_PATH in your global mise config (~/.config/mise/config.toml) if the path differs.

  2. MCP server configured in project .mcp.json (for MCP tool access)

Creating Diagrams

Via HTTP API (Recommended)

Create elements directly via the canvas server API:

bash
curl -X POST http://localhost:3000/api/elements/batch \
  -H "Content-Type: application/json" \
  -d @/tmp/elements.json

Element JSON structure:

json
{
  "elements": [
    {"type": "rectangle", "x": 100, "y": 100, "width": 150, "height": 80, "backgroundColor": "#a5d8ff", "strokeColor": "#1971c2"},
    {"type": "text", "x": 120, "y": 130, "text": "Label", "fontSize": 20}
  ]
}

Element Types

TypeRequired PropsOptional Props
rectanglex, y, width, heightbackgroundColor, strokeColor, strokeWidth
ellipsex, y, width, heightbackgroundColor, strokeColor
diamondx, y, width, heightbackgroundColor, strokeColor
textx, y, textfontSize, fontFamily
arrowx, y, width, heightstrokeColor, strokeWidth
linex, y, width, heightstrokeColor, strokeWidth

Color Palette

  • Blue: #a5d8ff (bg), #1971c2 (stroke)
  • Green: #b2f2bb (bg), #2f9e44 (stroke)
  • Red: #ffc9c9 (bg), #e03131 (stroke)
  • Yellow: #ffec99 (bg), #f08c00 (stroke)
  • Purple: #d0bfff (bg), #7950f2 (stroke)
  • Gray: #dee2e6 (bg), #495057 (stroke)

Verifying Output

Take a screenshot to verify the diagram rendered correctly:

python
from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch(headless=True)
    page = browser.new_page()
    page.goto('http://localhost:3000')
    page.wait_for_load_state('networkidle')
    page.wait_for_timeout(2000)
    page.screenshot(path='/tmp/diagram.png', full_page=True)
    browser.close()

Run with: uv run python /tmp/screenshot_script.py

Then read the screenshot to verify: Read /tmp/diagram.png

Common Patterns

Flowchart (Vertical)

json
{
  "elements": [
    {"type": "rectangle", "x": 100, "y": 50, "width": 120, "height": 60, "backgroundColor": "#a5d8ff", "strokeColor": "#1971c2"},
    {"type": "text", "x": 130, "y": 70, "text": "Start", "fontSize": 16},
    {"type": "arrow", "x": 160, "y": 110, "width": 0, "height": 40, "strokeColor": "#495057"},
    {"type": "rectangle", "x": 100, "y": 150, "width": 120, "height": 60, "backgroundColor": "#b2f2bb", "strokeColor": "#2f9e44"},
    {"type": "text", "x": 120, "y": 170, "text": "Process", "fontSize": 16},
    {"type": "arrow", "x": 160, "y": 210, "width": 0, "height": 40, "strokeColor": "#495057"},
    {"type": "rectangle", "x": 100, "y": 250, "width": 120, "height": 60, "backgroundColor": "#ffc9c9", "strokeColor": "#e03131"},
    {"type": "text", "x": 135, "y": 270, "text": "End", "fontSize": 16}
  ]
}

Architecture Boxes (Horizontal)

json
{
  "elements": [
    {"type": "rectangle", "x": 50, "y": 100, "width": 100, "height": 80, "backgroundColor": "#a5d8ff", "strokeColor": "#1971c2"},
    {"type": "text", "x": 70, "y": 130, "text": "Client", "fontSize": 14},
    {"type": "arrow", "x": 150, "y": 140, "width": 50, "height": 0, "strokeColor": "#495057"},
    {"type": "rectangle", "x": 200, "y": 100, "width": 100, "height": 80, "backgroundColor": "#b2f2bb", "strokeColor": "#2f9e44"},
    {"type": "text", "x": 225, "y": 130, "text": "API", "fontSize": 14},
    {"type": "arrow", "x": 300, "y": 140, "width": 50, "height": 0, "strokeColor": "#495057"},
    {"type": "rectangle", "x": 350, "y": 100, "width": 100, "height": 80, "backgroundColor": "#d0bfff", "strokeColor": "#7950f2"},
    {"type": "text", "x": 385, "y": 130, "text": "DB", "fontSize": 14}
  ]
}

API Endpoints

EndpointMethodDescription
/api/elementsGETList all elements
/api/elementsPOSTCreate single element
/api/elements/batchPOSTCreate multiple elements
/api/elements/:idPUTUpdate element
/api/elements/:idDELETEDelete element
/api/elements/from-mermaidPOSTConvert Mermaid to elements
/healthGETServer health check

Workflow

  1. Check canvas server is running: curl http://localhost:3000/health
  2. Clear canvas if needed: Click "Clear Canvas" in browser or restart server
  3. Create elements via API batch endpoint
  4. Take screenshot to verify
  5. Show screenshot to user for confirmation
  6. Iterate if needed

Mermaid Conversion

Convert Mermaid diagrams to Excalidraw:

bash
curl -X POST http://localhost:3000/api/elements/from-mermaid \
  -H "Content-Type: application/json" \
  -d '{"mermaidDiagram": "graph TD; A-->B; B-->C;"}'

Note: Mermaid conversion requires the browser canvas to be open for rendering.