drawio-parser-mcp
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@drawio-parser-mcp Validate this Draw.io XML for syntax errors"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Draw.io Parser MCP Server
一个用于验证和分析 Draw.io XML 语法的 MCP (Model Context Protocol) 服务器,专为检查 AI 生成的 Draw.io 图表内容设计。
功能特性
语法验证 - 检查 Draw.io XML 的语法正确性,发现错误和警告
结构解析 - 解析图表结构,提取单元格、边、图层等信息
图表分析 - 完整分析图表,同时返回验证结果和结构信息
摘要统计 - 快速获取图表统计信息(形状数、连接数等)
单元格查询 - 列出所有单元格或按 ID 查找特定单元格
Related MCP server: Draw.io Diagram Server
安装
使用 uv (推荐)
# 克隆项目
git clone https://github.com/dabian321/pyDrawioParserMCP.git
cd pyDrawioParserMCP
# 安装依赖
uv sync使用 pip
pip install -e .MCP 配置
将以下配置添加到你的 MCP 配置文件 (如 Claude Desktop 的 mcp.json):
{
"mcpServers": {
"drawio-parser-mcp": {
"command": "uv",
"args": [
"--directory",
"/path/to/pyDrawioParserMCP",
"run",
"drawio-parser-mcp"
],
"env": {
"PYTHONIOENCODING": "utf-8"
}
}
}
}将
/path/to/pyDrawioParserMCP替换为项目实际路径
MCP 工具
工具名 | 描述 |
| 验证 Draw.io XML 语法和结构,返回错误、警告和建议 |
| 解析 Draw.io XML,提取单元格、边、图层和统计信息 |
| 完整分析:同时执行验证和解析 |
| 获取图表摘要统计信息 |
| 列出图表中所有单元格(形状和连接) |
| 按 ID 查找特定单元格 |
命令行使用
# 启动 MCP 服务器 (stdio 模式)
drawio-parser-mcp
# 验证单个文件
drawio-parser-mcp --check mydiagram.drawio
# 启用详细日志
drawio-parser-mcp -v使用示例
验证 AI 生成的 Draw.io 内容
from drawio_parser_mcp import DrawioValidator
validator = DrawioValidator()
xml_content = """
<mxfile>
<diagram id="test" name="Page-1">
<mxGraphModel>
<root>
<mxCell id="0"/>
<mxCell id="1" parent="0"/>
<mxCell id="2" value="Hello" style="rounded=1;" vertex="1" parent="1">
<mxGeometry x="100" y="100" width="120" height="60" as="geometry"/>
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>
"""
result = validator.validate(xml_content)
print(f"Valid: {result.valid}")
print(f"Errors: {result.error_count}, Warnings: {result.warning_count}")解析图表结构
from drawio_parser_mcp import DrawioParser
parser = DrawioParser()
structure = parser.parse(xml_content)
print(f"Pages: {len(structure.pages)}")
print(f"Total shapes: {structure.total_vertices}")
print(f"Total connections: {structure.total_edges}")项目结构
pyDrawioParserMCP/
├── src/drawio_parser_mcp/
│ ├── __init__.py # 包入口
│ ├── cli.py # 命令行接口
│ ├── server.py # MCP Server 实现
│ ├── parser.py # XML 解析器
│ ├── validator.py # 语法验证器
│ └── models.py # 数据模型
├── tests/ # 测试文件
├── architecture.drawio # 架构图
└── pyproject.toml # 项目配置验证规则
错误代码 | 描述 |
| XML 语法错误 |
| 无效的根元素 |
| 缺少 diagram 元素 |
| 缺少 id="0" 的根单元格 |
| 缺少 id="1" 的默认父单元格 |
| 引用了不存在的父单元格 |
| 边的源单元格不存在 |
| 边的目标单元格不存在 |
| 负数的宽度或高度 |
依赖
Python >= 3.10
mcp >= 1.0.0
pydantic >= 2.0.0
lxml >= 5.0.0
开发
# 安装开发依赖
uv sync --extra dev
# 运行测试
pytest
# 代码格式检查
ruff check src/License
MIT License
Available Tools
6 toolsanalyze_drawioB
Fully analyze Draw.io XML: validate syntax and parse structure. Returns both validation issues and parsed diagram structure.
Inputs: xml_content (required).
find_cellA
Find a specific cell by ID in a Draw.io diagram.
Inputs: cell_id (required), xml_content (required).
get_diagram_summaryA
Get a concise summary of a Draw.io diagram. Returns statistics and overview without full structure details.
Inputs: xml_content (required).
list_cellsA
List all cells (shapes and connections) in a Draw.io diagram. Returns cell IDs, types, labels, and connections.
Inputs: xml_content (required), include_system_cells.
parse_drawioB
Parse Draw.io XML and extract diagram structure. Returns cells, edges, layers, and statistics.
Inputs: xml_content (required).
validate_drawioA
Validate Draw.io XML syntax and structure. Returns validation result with errors, warnings, and suggestions.
Inputs: xml_content (required).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 6 tools
Most tools target distinct operations (validate, parse, summarize, list, find), but analyze_drawio overlaps with both validate_drawio and parse_drawio, creating two potential points of confusion. The descriptions make the distinctions clear, so the ambiguity is limited.
All tool names follow a consistent verb_noun pattern using snake_case (validate_drawio, parse_drawio, analyze_drawio, get_diagram_summary, list_cells, find_cell). The verbs are distinct and appropriate for each operation.
Six tools is a well-scoped set for a Draw.io parser. Each tool serves a clear purpose, and the combination covers validation, parsing, summarization, listing, and lookup without unnecessary bloat.
The tool surface covers the full read-only lifecycle for a diagram parser: validation, structural parsing, combined analysis, summary statistics, cell listing, and targeted lookup. There are no obvious missing operations for the stated purpose.
Maintenance
Related MCP Connectors
Create draw.io diagrams in chat from Mermaid or XML, shown live and interactive. 10,000+ shapes.
Check XML against your XSD and invoices against XRechnung or EN 16931 rules. Free up to 25 checks per IP per UTC day.
Validate XML and e-invoices (XSD, DTD, RelaxNG, EN 16931, Peppol, XRechnung), explain errors
Render, validate, encode/decode PlantUML diagram-as-code; 22 diagram types. Free, no auth.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceValidates Mermaid diagrams with comprehensive grammar parsing supporting 28+ diagram types. Processes markdown files, ZIP archives, and direct input with detailed error reporting and enterprise-grade performance capabilities.50 npm3Apache 2.0
- AlicenseBqualityDmaintenanceGenerates professional Draw.io compatible diagrams (flowcharts, sequence diagrams, network diagrams, and custom diagrams) from natural language prompts, outputting XML files that can be opened directly in Draw.io.170 npm6MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to create and edit draw.io diagrams programmatically, supporting a wide range of diagram types and styles.72 PyPI6MIT
- FlicenseAqualityDmaintenanceEnables local creation and maintenance of editable draw.io XML diagram files, with tools for inspecting, validating, and updating diagrams.5-