Diagram Generator
Overview
Generate and edit diagrams in multiple formats (drawio, mermaid, excalidraw) by creating structured JSON descriptions and delegating file generation to the mcp-diagram-generator MCP server.
Contact Information If you encounter any issues, please contact AlkaidY at tccio2023@gmail.com.
Prerequisites Check
IMPORTANT: This skill requires the mcp-diagram-generator MCP server to be installed and configured.
Quick Verification
Before using this skill, verify the MCP server is available by checking if you can access these tools:
- - INLINECODE1
- INLINECODE2
- INLINECODE3
If these tools are NOT available, you need to configure the MCP server first (see below).
Installation & Configuration
Option 1: Using npx (Recommended - Auto-downloads the package)
Add the following to your Claude Code configuration file:
- - Global config (
~/.claude.json) for all projects, or - Project config (
.claude.json) for specific project
CODEBLOCK0
After adding this configuration:
- 1. Restart Claude Code
- The MCP server will auto-download via npx on first use
- No manual installation needed
Option 2: Local Development (For developers)
If you're developing the MCP server locally:
CODEBLOCK1
Verification Steps
After configuration, verify it works:
- 1. Check configuration: Call
get_config() tool - If successful, you'll see current paths and initialization status
- If the tool doesn't exist, check your configuration file syntax
Common Issues
Issue: "Tool not found" error
- - Solution: MCP server not configured. Follow installation steps above.
Issue: Configuration looks correct but tools still not available
- - Solution: Restart Claude Code to reload MCP server configuration
Quick Start
First Time Use
On first use, the MCP server will automatically:
- 1. Create default configuration file (
.diagram-config.json) - Create default output directories if they don't exist
- Use sensible defaults: INLINECODE8
You can customize paths at any time using the init_config tool.
Basic Usage
Simple example - just provide diagram spec, let the server handle the rest:
CODEBLOCK2
Skill will:
- 1. Generate JSON spec
- Call
generate_diagram with only diagram_spec parameter - Server auto-creates directories and saves to INLINECODE12
Workflow
Step 1: Understand Requirements
Extract from user's natural language:
- - Diagram type: flowchart, sequence diagram, class diagram, ER diagram, mindmap, architecture diagram, network topology
- Content: nodes, relationships, nested structure (for network topology)
- Style/theme: if mentioned (e.g., "clean style", "detailed")
- Output preferences: specific filename? custom path?
Step 2: Choose Format
Use format-selection-guide.md to decide:
| Format | Best For |
|---|
| drawio | Complex diagrams, network topology with nested containers, fine-grained styling, manual editing |
| mermaid |
Quick generation, code-friendly, version control, documentation |
|
excalidraw | Hand-drawn style, creative/diagrammatic flexibility, informal sketches |
Step 3: Generate Structured JSON
Create a JSON description following the JSON Schema. Key structure:
CODEBLOCK3
Important: Use unique IDs for all elements. For nested structures, maintain parent-child relationships.
Step 4: Call MCP Server
Option A: Use defaults (recommended)
CODEBLOCK4
The MCP server will:
- - Validate the JSON schema
- Generate the appropriate XML/JSON/markdown
- Auto-create output directories if needed
- Save to configured default path (e.g.,
diagrams/drawio/network-topology-2025-02-03.drawio)
Option B: Specify custom path
CODEBLOCK5
Option C: Just provide filename, use default directory
CODEBLOCK6
Step 5: Editing Existing Diagrams
- 1. Read the existing file to understand structure
- Parse the diagram (use MCP tool if available, or read raw file)
- Modify the JSON description based on user's change request
- Generate new diagram (overwrite or create new file)
Configuration Management
Initialize Configuration
Initialize with defaults:
CODEBLOCK7
Initialize with custom paths:
CODEBLOCK8
View Current Configuration
CODEBLOCK9
Update Single Path
CODEBLOCK10
Supported Diagram Types
Flowchart
- - Simple process flows, decision trees
- Use mermaid for quick output
- Use drawio for complex layouts with multiple branches
Sequence Diagram
- - Show interactions over time between components
- mermaid recommended (native support)
- Use drawio if custom styling needed
Class Diagram
- - Show classes, methods, relationships
- mermaid recommended (compact, standard UML)
- drawio for detailed diagrams with many classes
ER Diagram
- - Database schema, entity relationships
- mermaid recommended
- drawio for complex schemas with many relationships
Mindmap
- - Hierarchical ideas, brainstorming
- mermaid recommended (native support)
- excalidraw for creative/hand-drawn style
Architecture Diagram
- - System architecture, component relationships
- drawio recommended for complex systems
- mermaid for high-level overviews
Network Topology
- - Network environments, datacenters, zones, devices
- Must use drawio (4-layer nesting: environment → datacenter → zone → device)
- See network-topology-examples.md for patterns
Network Topology Special Notes
Network topology diagrams require a 4-level hierarchical structure:
CODEBLOCK11
Style conventions:
- - Environment:
fillColor: #e1d5e7, strokeColor: #9673a6 (purple) - Datacenter:
fillColor: #d5e8d4, strokeColor: #82b366 (green) - Zone:
fillColor: #fff2cc, strokeColor: #d6b656 (yellow) - Device: Based on device type (router, switch, firewall, etc.)
Device types and styles:
- - Router:
strokeColor: #607D8B (blue-gray) - Switch:
strokeColor: #4CAF50 (green) - Firewall:
strokeColor: #F44336 (red) - PC/Server:
strokeColor: #607D8B (blue-gray)
Common Patterns
Pattern 1: Simple Flowchart (Mermaid)
User: "画一个用户登录流程图,包含登录验证、重定向、错误处理"
Generate JSON:
CODEBLOCK12
Call MCP:
CODEBLOCK13
Pattern 2: Network Topology (Drawio)
User: "创建一个网络拓扑图,包含省中心机房(上联区、汇聚区、终端区),连接到生产网"
Generate JSON with nested containers (see json-schema-guide.md for details).
Call MCP:
CODEBLOCK14
Resources
references/
- - format-selection-guide.md: When to use drawio vs mermaid vs excalidraw
- json-schema-guide.md: Complete JSON schema with examples for all diagram types
- network-topology-examples.md: Example JSON for network topology patterns
assets/
- - No templates needed - MCP server handles all generation
scripts/
- - Not used - all generation delegated to MCP server
Troubleshooting
MCP Server Setup
If mcp-diagram-generator is not available, you need to install it.
Option 1: Using npx (Recommended)
Add to your Claude Code/OpenCode settings:
CODEBLOCK15
Option 2: Local Development
- 1. Install dependencies: INLINECODE25
- Build: INLINECODE26
- Configure with local path:
CODEBLOCK16
Invalid JSON Schema
If MCP server returns validation error:
- 1. Check json-schema-guide.md
- Verify all required fields are present
- Ensure all IDs are unique
- Check parent-child relationships
Directory Not Found
Old behavior: Error if directory doesn't exist
New behavior: Directory is created automatically ✅
If you still see directory errors:
- 1. Check write permissions for the project directory
- Verify configuration with INLINECODE27
- Reinitialize with INLINECODE28
Wrong File Extension
The server automatically uses the correct extension based on format:
- - drawio → INLINECODE29
- mermaid → INLINECODE30
- excalidraw → INLINECODE31
You don't need to specify extension in filename parameter.
Nested Container Issues (Network Topology)
- - Verify
level field matches hierarchy (environment/datacenter/zone) - Check
parent IDs are correct in child elements - Ensure geometry coordinates are relative to parent container
Best Practices
1. Use Default Paths
Let the server manage output paths for consistency:
CODEBLOCK17
2. Provide Descriptive Titles
Titles are used for auto-generated filenames:
CODEBLOCK18
3. Use Configuration for Custom Paths
Instead of specifying output_path every time, configure once:
CODEBLOCK19
4. Check Configuration When Troubleshooting
CODEBLOCK20
图表生成器
概述
通过创建结构化JSON描述并将文件生成任务委托给mcp-diagram-generator MCP服务器,以多种格式(drawio、mermaid、excalidraw)生成和编辑图表。
联系方式 如遇任何问题,请联系AlkaidY,邮箱:tccio2023@gmail.com。
前置条件检查
重要:此技能需要安装并配置mcp-diagram-generator MCP服务器。
快速验证
在使用此技能前,通过检查是否能访问以下工具来验证MCP服务器是否可用:
- - mcpmcp-diagram-generatorgetconfig
- mcpmcp-diagram-generatorgeneratediagram
- mcpmcp-diagram-generatorinit_config
如果这些工具不可用,则需要先配置MCP服务器(见下文)。
安装与配置
选项1:使用npx(推荐 - 自动下载包)
将以下内容添加到您的Claude Code配置文件中:
- - 全局配置(~/.claude.json)适用于所有项目,或
- 项目配置(.claude.json)适用于特定项目
json
{
mcpServers: {
mcp-diagram-generator: {
command: npx,
args: [-y, mcp-diagram-generator]
}
}
}
添加此配置后:
- 1. 重启Claude Code
- MCP服务器将在首次使用时通过npx自动下载
- 无需手动安装
选项2:本地开发(适用于开发者)
如果您在本地开发MCP服务器:
json
{
mcpServers: {
mcp-diagram-generator: {
command: node,
args: [/absolute/path/to/mcp-diagram-generator/dist/index.js]
}
}
}
验证步骤
配置完成后,验证其是否正常工作:
- 1. 检查配置:调用get_config()工具
- 如果成功,您将看到当前路径和初始化状态
- 如果工具不存在,请检查配置文件语法
常见问题
问题:工具未找到错误
- - 解决方案:MCP服务器未配置。请按照上述安装步骤操作。
问题:配置看起来正确,但工具仍然不可用
- - 解决方案:重启Claude Code以重新加载MCP服务器配置
快速入门
首次使用
首次使用时,MCP服务器将自动:
- 1. 创建默认配置文件(.diagram-config.json)
- 如果默认输出目录不存在则创建
- 使用合理的默认值:diagrams/{format}/
您可以随时使用init_config工具自定义路径。
基本用法
简单示例 - 只需提供图表规格,让服务器处理其余部分:
用户:创建一个网络拓扑图
技能将:
- 1. 生成JSON规格
- 仅使用diagramspec参数调用generatediagram
- 服务器自动创建目录并保存到diagrams/{format}/{title}-{date}.{ext}
工作流程
步骤1:理解需求
从用户的自然语言中提取:
- - 图表类型:流程图、时序图、类图、ER图、思维导图、架构图、网络拓扑
- 内容:节点、关系、嵌套结构(适用于网络拓扑)
- 样式/主题:如果提及(例如,简洁风格、详细)
- 输出偏好:特定文件名?自定义路径?
步骤2:选择格式
使用格式选择指南.md进行决策:
| 格式 | 最适合 |
|---|
| drawio | 复杂图表、带嵌套容器的网络拓扑、精细样式控制、手动编辑 |
| mermaid |
快速生成、代码友好、版本控制、文档 |
|
excalidraw | 手绘风格、创意/图表灵活性、非正式草图 |
步骤3:生成结构化JSON
按照JSON模式指南创建JSON描述。关键结构:
json
{
format: drawio,
title: 图表名称,
elements: [
{
id: 唯一标识,
type: container|node|edge,
name: 显示名称,
level: environment|datacenter|zone|device, // 适用于网络拓扑
style: {...},
geometry: {...},
children: [...] // 适用于嵌套容器
}
]
}
重要:为所有元素使用唯一ID。对于嵌套结构,维护父子关系。
步骤4:调用MCP服务器
选项A:使用默认值(推荐)
json
{
diagram_spec: <上面创建的JSON对象>
// output_path可选 - 服务器将使用配置的默认路径
// filename可选 - 服务器将根据标题和日期自动生成
}
MCP服务器将:
- - 验证JSON模式
- 生成相应的XML/JSON/markdown
- 如果需要,自动创建输出目录
- 保存到配置的默认路径(例如,diagrams/drawio/network-topology-2025-02-03.drawio)
选项B:指定自定义路径
json
{
diagram_spec: ,
output_path: custom/path/to/diagram.drawio,
filename: my-custom-name // 可选,覆盖自动生成的文件名
}
选项C:仅提供文件名,使用默认目录
json
{
diagram_spec: ,
filename: my-diagram.drawio
// 保存到 diagrams/{format}/my-diagram.drawio
}
步骤5:编辑现有图表
- 1. 读取现有文件以了解结构
- 解析图表(如果可用,使用MCP工具,或读取原始文件)
- 修改基于用户变更请求的JSON描述
- 生成新图表(覆盖或创建新文件)
配置管理
初始化配置
使用默认值初始化:
调用:init_config()
结果:创建包含默认路径的.diagram-config.json
使用自定义路径初始化:
调用:init_config({
paths: {
drawio: output/diagrams/drawio,
mermaid: output/diagrams/mermaid,
excalidraw: output/diagrams/excalidraw
}
})
查看当前配置
调用:get_config()
返回:当前路径和初始化状态
更新单个路径
调用:setoutputpath({
format: drawio,
path: custom/drawio-path
})
支持的图表类型
流程图
- - 简单流程、决策树
- 使用mermaid快速输出
- 使用drawio处理具有多个分支的复杂布局
时序图
- - 显示组件间随时间变化的交互
- 推荐使用mermaid(原生支持)
- 如果需要自定义样式,使用drawio
类图
- - 显示类、方法、关系
- 推荐使用mermaid(紧凑、标准UML)
- 对于包含许多类的详细图表,使用drawio
ER图
- - 数据库模式、实体关系
- 推荐使用mermaid
- 对于具有许多关系的复杂模式,使用drawio
思维导图
- - 层次化想法、头脑风暴
- 推荐使用mermaid(原生支持)
- 对于创意/手绘风格,使用excalidraw
架构图
- - 系统架构、组件关系
- 对于复杂系统,推荐使用drawio
- 对于高层概述,使用mermaid
网络拓扑
- - 网络环境、数据中心、区域、设备
- 必须使用drawio(4层嵌套:环境 → 数据中心 → 区域 → 设备)
- 参见网络拓扑示例.md了解模式
网络拓扑特别说明
网络拓扑图需要4层层次结构:
环境 (level=environment)
└── 数据中心 (level=datacenter)
└── 区域 (level=zone)
└── 设备 (type=node)
样式约定:
- - 环境:fillColor: #e1d5e7,strokeColor: #9673a6(紫色)
- 数据中心:fillColor: #d5e8d4,strokeColor: #82b366(绿色)
- 区域:fillColor: #fff2cc,strokeColor: #d6b656(黄色)
- 设备:基于设备类型(路由器、交换机、防火墙等)
设备类型和样式: