通过 MCP 协议或 REST API 远程控制 StarUML,让 AI 自动生成各种 UML 图表(用例图、类图、时序图、ER 图等)。
AI Client (Claude/Hermes/Cursor)
│ MCP Protocol (stdio)
▼
Python MCP Server (server.py)
│ HTTP REST API
▼
staruml-controller Extension (runs inside StarUML)
│
▼
StarUML — renders diagrams
| Requirement | Version | Note |
|---|---|---|
| StarUML | v6.0.0+ | https://staruml.io/ |
| Python | 3.10+ | https://www.python.org/downloads/ |
| staruml-controller | latest | StarUML 扩展,提供 REST API |
Clone into StarUML's extensions directory:
# Windows (%APPDATA% = C:\Users\<用户名>\AppData\Roaming)
cd %APPDATA%\StarUML\extensions\user
git clone https://github.com/pontasan/staruml-controller.git
# macOS
cd ~/Library/Application\ Support/StarUML/extensions/user
git clone https://github.com/pontasan/staruml-controller.git
# Linux
cd ~/.config/StarUML/extensions/user
git clone https://github.com/pontasan/staruml-controller.gitcd staruml-mcp
pip install -r requirements.txtOr run the setup script:
scripts\setup.batLaunch StarUML — the extension auto-starts and listens on port 12345.
python server.pyEdit claude_desktop_config.json (or Proma's mcp.json):
{
"mcpServers": {
"staruml": {
"command": "python",
"args": ["D:/path/to/staruml-mcp/server.py"],
"timeout": 60
}
}
}Edit ~/.hermes/config.yaml:
mcp_servers:
staruml:
command: "python"
args: ["D:/path/to/staruml-mcp/server.py"]
timeout: 60Edit .cursor/mcp.json:
{
"mcpServers": {
"staruml": {
"command": "python",
"args": ["D:/path/to/staruml-mcp/server.py"]
}
}
}If the staruml-controller uses a different port:
python server.py --api-port 56789| Tool | Description | Supported Types |
|---|---|---|
generate_diagram |
Import any Mermaid code | classDiagram, sequenceDiagram, flowchart, erDiagram, mindmap, requirementDiagram, stateDiagram |
| Tool | Description |
|---|---|
create_class_diagram |
类图 — classes, attributes, methods, relationships |
create_sequence_diagram |
时序图 — participants, messages |
create_use_case_diagram |
用例图 — actors, use cases, relationships |
create_activity_diagram |
活动图 — nodes, flows |
create_state_diagram |
状态图 — states, transitions |
create_er_diagram |
ER 图 — entities, attributes, relationships |
create_flowchart |
流程图 — nodes, connections |
create_mindmap |
思维导图 — root, branches |
| Tool | Description |
|---|---|
check_staruml_connection |
检查与 StarUML 的连接状态 |
get_all_diagrams |
获取当前项目所有图表信息 |
get_current_diagram |
获取当前图表详情 |
export_diagram_as_image |
导出图表为 PNG 图片(base64) |
In your AI chat, just say:
"用 staruml 画一个电商系统的用例图,有顾客、商家和管理员三个角色"
"画一个图书管理系统的类图,包含 Book、User、BorrowRecord"
"画一个用户登录的时序图"
"画一个订单处理的状态图"
"画一个数据库设计的 ER 图"
The scripts/ directory contains standalone Python scripts that call the REST API directly (no MCP client needed).
python create_usecase.pyIf diagram elements overlap, run the layout script:
python layout_usecase.pyNote: staruml-controller's auto-layout skips use case diagrams, so layout is done by manually positioning views via
PUT /api/views/:id.
staruml-controller provides full CRUD REST API for all diagram families:
| Family | Prefix | Examples |
|---|---|---|
| Use Case | /api/usecase/ |
actors, use-cases, subjects, associations, includes, extends |
| Class | /api/class/ |
classes, interfaces, attributes, methods, associations |
| Sequence | /api/sequence/ |
lifelines, messages, combined-fragments |
| Activity | /api/activity/ |
actions, decisions, forks |
| State Machine | /api/statemachine/ |
states, transitions |
| ERD | /api/erd/ |
entities, columns, relationships |
| Flowchart | /api/flowchart/ |
nodes, connections |
| MindMap | /api/mindmap/ |
nodes |
| BPMN | /api/bpmn/ |
pools, lanes, tasks, gateways |
| C4 | /api/c4/ |
containers, components, relationships |
| AWS / Azure / GCP | /api/aws/, /api/azure/, /api/gcp/ |
architecture diagrams |
Each family supports: GET/POST /api/{family}/{resource}, GET/PUT/DELETE /api/{family}/{resource}/:id
staruml-mcp/
├── server.py # MCP Server (Python / FastMCP)
├── requirements.txt # Python dependencies
├── README.md # This file
├── .gitignore
│
├── create_usecase.py # Standalone: create a use case diagram via REST API
├── layout_usecase.py # Standalone: reposition diagram elements
│
├── scripts/
│ ├── setup.bat # Windows setup script
│ └── test_connection.bat # Connection test script
│
└── examples/
├── class_library.json # Class diagram example data
├── sequence_login.json # Sequence diagram example data
└── use_case_ecommerce.json # Use case diagram example data
- Ensure StarUML is running
- Check staruml-controller is installed at
%APPDATA%\StarUML\extensions\user\staruml-controller - Restart StarUML (extension auto-starts on port 12345)
- Run
scripts\test_connection.batto verify
Only these Mermaid types are supported: classDiagram, sequenceDiagram, flowchart, erDiagram, mindmap, requirementDiagram, stateDiagram. Use case diagrams use the REST API directly instead.
If port 12345 is in use, modify server.py's DEFAULT_API_PORT or pass --api-port flag.
Run python layout_usecase.py to reposition use case diagram elements. For other diagram types, use POST /api/diagrams/{id}/layout with direction (TB/BT/LR/RL).
MIT