@drawio/mcp

中文文档
1.12.0发布于 2026/11/10Apache-2.0ES Module构建来源已验证近 30 天下载 16.6万

Official draw.io MCP server for LLMs - Open diagrams in draw.io editor

原始使用文档
文档目录24 节
  1. Features
  2. Installation
  3. Using npx (recommended)
  4. Global installation
  5. From source
  6. Configuration
  7. Claude Desktop
  8. Claude Code
  9. VS Code (GitHub Copilot)
  10. Cursor
  11. OpenCode
  12. Other MCP Clients
  13. Self-hosted draw.io
  14. Return the link without opening a browser
  15. Tools
  16. open_drawio_xml
  17. open_drawio_csv
  18. open_drawio_mermaid
  19. get_drawio_reference
  20. search_shapes
  21. list_pages / get_page / set_page
  22. Example Prompts
  23. How It Works
  24. Related Resources

Draw.io MCP Tool Server

The official draw.io MCP server that opens diagrams directly in the draw.io editor. Supports XML, CSV, and Mermaid.js formats with lightbox and dark mode options.

This package is part of the drawio-mcp repository, which also includes:

  • MCP App Server — Renders diagrams inline in AI chat interfaces. Hosted at https://mcp.draw.io/mcp — no install required.
  • Claude Code Plugin — Claude Code plugin that generates native .drawio files with optional PNG/SVG/PDF export.
  • Project Instructions — Zero-install approach using Claude Project instructions.

Features

  • Open XML diagrams: Load native draw.io/mxGraph XML format
  • Import CSV data: Convert tabular data to diagrams (org charts, flowcharts, etc.)
  • Render Mermaid.js: Transform Mermaid syntax into editable draw.io diagrams
  • Customizable display: Lightbox mode, dark mode, and more

Installation

npx @drawio/mcp

Global installation

npm install -g @drawio/mcp
drawio-mcp

From source

git clone https://github.com/jgraph/drawio-mcp.git
cd drawio-mcp/mcp-tool-server
npm install
npm start

Configuration

Claude Desktop

Add to your Claude Desktop configuration file:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json Windows: %APPDATA%\Claude\claude_desktop_config.json

{
  "mcpServers": {
    "drawio": {
      "command": "npx",
      "args": ["@drawio/mcp"]
    }
  }
}

Claude Code

claude mcp add drawio -- npx -y @drawio/mcp

Or manually in .claude/settings.json:

{
  "mcpServers": {
    "drawio": {
      "command": "npx",
      "args": ["-y", "@drawio/mcp"]
    }
  }
}

VS Code (GitHub Copilot)

Add to .vscode/mcp.json in your workspace (or run MCP: Open User Configuration for a global config):

{
  "servers": {
    "drawio": {
      "command": "npx",
      "args": ["-y", "@drawio/mcp"]
    }
  }
}

Then click Start above the server entry, trust the server when prompted, switch Copilot Chat to Agent mode, and make sure the drawio tools are enabled under Configure Tools (🔧) in the chat input.

Other clients that use stdio (Windsurf, etc.) use the same config shape as above.

Tip: VS Code 1.109 and later also supports the MCP Apps extension, so the hosted MCP App Server at https://mcp.draw.io/mcp works in Copilot Chat too, rendering diagrams inline in chat instead of opening a browser tab. To use it, replace command and args above with "type": "http" and "url": "https://mcp.draw.io/mcp". Use this stdio server if you prefer diagrams to open in the full draw.io editor.

Cursor

Install MCP Server

Click the button above for one-click install, or add the server manually to ~/.cursor/mcp.json (global) or .cursor/mcp.json in your project:

{
  "mcpServers": {
    "drawio": {
      "command": "npx",
      "args": ["-y", "@drawio/mcp"]
    }
  }
}

Enable the server when prompted (or under Cursor Settings → MCP), then ask the Agent to create a diagram — it opens in the draw.io editor in your browser.

Tip: Cursor also supports the MCP Apps extension, so the hosted MCP App Server at https://mcp.draw.io/mcp works in Cursor too, rendering diagrams inline in chat instead of opening a browser tab. Use this stdio server if you prefer diagrams to open in the full draw.io editor.

OpenCode

Add the server under the mcp key of opencode.json in your project root (or ~/.config/opencode/opencode.json for every project):

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "drawio": {
      "type": "local",
      "command": ["npx", "-y", "@drawio/mcp"],
      "enabled": true
    }
  }
}

The tools are available on the next start; ask the agent to create a diagram and it opens in the draw.io editor in your browser.

Tip: OpenCode also loads the drawio skill (native .drawio files, PNG/SVG/PDF export) without any plugin wrapper — see the plugins README.

Other MCP Clients

Configure your MCP client to run the server via stdio:

npx @drawio/mcp

Self-hosted draw.io

To open diagrams in a self-hosted draw.io instance, set the DRAWIO_BASE_URL environment variable to your instance URL (default: https://app.diagrams.net/):

{
  "mcpServers": {
    "drawio": {
      "command": "npx",
      "args": ["-y", "@drawio/mcp"],
      "env": {
        "DRAWIO_BASE_URL": "https://drawio.example.com/"
      }
    }
  }
}

Every open_drawio_* call opens the diagram in your default browser and returns its URL. Set DRAWIO_BROWSER to off to get only the URL. Use this for headless agents, CI and SSH sessions, where there is no browser or it would open on the wrong machine:

{
  "mcpServers": {
    "drawio": {
      "command": "npx",
      "args": ["-y", "@drawio/mcp"],
      "env": {
        "DRAWIO_BROWSER": "off"
      }
    }
  }
}

Tools

open_drawio_xml

Opens the draw.io editor with XML content.

ParameterTypeRequiredDescription
contentstringYesDraw.io XML content
lightboxbooleanNoRead-only view mode (default: false)
darkstringNo"auto", "true", or "false" (default: "auto")
postLayoutstringNo"elk" re-lays out the diagram (ELK layered flow) before opening: vertices are placed, edges routed
directionstringNoFlow direction for postLayout: "vertical" (default) or "horizontal"
routingstringNo"libavoid" reroutes connectors around shapes (obstacle-avoiding orthogonal routing) before opening, leaving positions untouched

Every diagram is repaired first: text around it is dropped (a leaked tool-call tag, a code fence), < and stray & in attribute values are escaped, and a layer written as its own parent is re-parented — the slips that broke 3% of LLM-written diagrams in tests. A layout or routing option the model wrote into the XML string by mistake is still applied. Then every diagram is normalized on the way through, the way the draw.io editor maintains its own model: edges are filed at the nearest common ancestor of their terminals (so you can keep writing parent="1" on every edge and containers still lay out correctly), an edge written without a geometry gets one (it would not render otherwise), and a container that would clip a child is grown to fit it. The same repairs the draw.io Desktop CLI applies with --normalize.

postLayout and routing are alternatives: ELK places the vertices and routes the edges, libavoid only fixes the connectors of a layout you placed yourself. Both run on the server before the diagram is compressed into the URL; the diagram itself still never leaves your machine (it travels in the URL fragment). The ELK pass loads the drawio-elk bundle from the draw.io CDN on first use and caches it per user, so the first layout after an update pays a one-off download.

open_drawio_csv

Opens the draw.io editor with CSV data converted to a diagram.

ParameterTypeRequiredDescription
contentstringYesCSV content
lightboxbooleanNoRead-only view mode (default: false)
darkstringNo"auto", "true", or "false" (default: "auto")

open_drawio_mermaid

Opens the draw.io editor with a Mermaid.js diagram.

ParameterTypeRequiredDescription
contentstringYesMermaid.js syntax
lightboxbooleanNoRead-only view mode (default: false)
darkstringNo"auto", "true", or "false" (default: "auto")
postLayoutstringNo"elk" switches a Mermaid flowchart to the layered ELK layout (direction still follows the flowchart code). Ignored for other diagram types

postLayout costs nothing here: it selects the layout in the Mermaid source (a config: { layout: elk } frontmatter block) and draw.io applies it while converting the diagram — the same result as writing that frontmatter yourself.

get_drawio_reference

Returns a full diagram generation reference: shared/mermaid-reference.md, which the model reads before its first Mermaid diagram, or shared/xml-reference.md, which open_drawio_xml only needs for layers, tags, metadata, tables, cross-functional grids and dark-mode colors — its description already carries the condensed shared/xml-essentials.md.

ParameterTypeRequiredDescription
formatstringYes"xml" or "mermaid"

search_shapes

Searches the draw.io shape library (~10,000 shapes: AWS, Azure, GCP, Cisco, Kubernetes, P&ID, electrical, BPMN, …) and returns matching shapes with ready-to-use style strings for open_drawio_xml. When the built-in libraries have no good match, results are supplemented from the draw.io icon service (brand logos and general-purpose concept icons, e.g. react, slack, shopping cart). Use only for diagrams needing industry-specific, branded, or pictorial icons — standard flowcharts, UML, ERD, and org charts don't need it.

ParameterTypeRequiredDescription
querystringYesSpace-separated keywords (e.g. aws lambda, cisco router)
limitnumberNoMax results (default: 10, max: 50)

list_pages / get_page / set_page

Page-level access to a local multi-page .drawio file, so one page can be inspected or edited without loading the whole file. Pages are addressed by zero-based index, exact name, or id (as returned by list_pages). Compressed pages are decompressed/re-compressed transparently. Paths must end in .drawio or .xml.

ToolParametersResult
list_pagespath[{index, id, name, approxSizeBytes}] for every page
get_pagepath, pageThe page's mxGraphModel XML
set_pagepath, page, contentReplaces that page's content (a single <mxGraphModel> element); all other pages stay untouched

Diagrams in Google Drive, OneDrive, Dropbox, GitHub or GitLab

These tools work on local files only. The server can't read your cloud storage, and a draw.io link always opens a new, untitled diagram, never a file you saved. A link that changed a saved file would let anyone who sends you a link rewrite your diagrams. To have the agent change a diagram in the cloud, go through the draw.io tab where you have it open:

  1. In draw.io, choose Extras > Edit Diagram (Insert > Advanced > Edit Diagram in the Simple and Minimal themes). Copy the XML of the current page and give it to the agent.
  2. Ask the agent to reply with the changed XML.
  3. Open Edit Diagram again, replace the XML with the agent's, and click Apply. draw.io saves the change to the same file, under the same link, like any other edit.

This works one page at a time. Downloading the file, changing it with set_page and uploading it again also works, but a draw.io tab that has the file open can save over your upload.

Example Prompts

  • "Use open_drawio_mermaid to create a sequence diagram showing OAuth2 authentication flow"
  • "Use open_drawio_csv to create an org chart: CEO → CTO, CFO; CTO → 3 Engineers"
  • "Use open_drawio_xml to create a detailed AWS architecture diagram with VPC, subnets, and security groups"

Tip: Claude Desktop may have multiple ways to create diagrams. To ensure it uses the draw.io MCP, mention the tool name explicitly or add a system instruction: "Always use the draw.io MCP tools to create diagrams."

How It Works

  1. The MCP server receives diagram content (XML, CSV, or Mermaid)
  2. Content is compressed using pako deflateRaw and encoded as base64
  3. A draw.io URL is generated with the diagram in its hash: #R for XML, #create= for Mermaid and CSV, which draw.io converts in the browser
  4. The URL is returned to the LLM, which can present it to the user
  5. Opening the URL loads draw.io with the diagram ready to view/edit

The open_drawio_xml description carries the condensed XML rules from shared/xml-essentials.md (~1.5k characters). The full XML generation reference (edge routing, containers, layers, tags, metadata, dark mode, etc.) in shared/xml-reference.md, the single source of truth for all draw.io MCP prompts, and the Mermaid reference in shared/mermaid-reference.md are fetched with get_drawio_reference. That keeps every tool description short: clients like VS Code Copilot index tool descriptions, and a description carrying a whole reference is too long for them. A prepack script bundles the three files into the npm package so they work after npm install.

版本与发布记录

@drawio/mcp 共发布 43 个版本,首次发布于 2026/02/03;过去 12 个月发布了 43 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.12.0latest2026/11/103 天前
1.11.02026/11/067 天前
1.10.12026/10/3113 天前
1.10.02026/10/1925 天前
1.9.02026/10/1826 天前
1.8.02026/10/1726 天前

关于 @drawio/mcp 的常见问题

@drawio/mcp 是什么?

Official draw.io MCP server for LLMs - Open diagrams in draw.io editor

如何安装 @drawio/mcp?

在项目目录运行 npm install @drawio/mcp,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 drawio-mcp,可以用 npx drawio-mcp 直接运行。

@drawio/mcp 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/drawio__mcp 是否存在。

@drawio/mcp 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@drawio/mcp 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@drawio/mcp 可以商用吗?

@drawio/mcp 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@drawio/mcp 的下载量有多少?

根据 npm 官方下载统计,@drawio/mcp 在 2026/10/13 – 2026/11/11 这 30 天内被下载 166,240 次,日均约 5,541 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@drawio/mcp 还在维护吗?

最新版本 1.12.0 发布于 2026/11/10(3 天前);至今共发布 43 个版本,其中过去 12 个月发布了 43 个;首次发布于 2026/02/03。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。