UML-MCP Server

by Swayingleaves
Verified

local-only server

The server can only run on the client’s local machine because it depends on local resources.

Integrations

  • Generates UML diagrams of multiple types including class, sequence, activity, use case, state, component, deployment, and object diagrams from natural language or PlantUML code

UML-MCP-服务器

English |中文

UML-MCP Server是一个基于MCP(模型上下文协议)的UML图生成工具,可以帮助用户通过自然语言描述或者直接编写PlantUML代码来生成各种类型的UML图。

功能特点

  • 支持多种UML图类型:类图、序列图、活动图、用例图、状态图、组件图、部署图、对象图
  • 可以通过自然语言描述生成UML图
  • 您可以直接使用PlantUML代码生成UML图
  • 返回PlantUML代码和可访问的URL链接,以便于共享和查看
  • 同时将生成的UML图保存到本地,并提供本地文件路径
  • 支持自定义保存路径和指定UML图像的输出目录
  • 作为 MCP 服务器,它可以与支持 MCP 的客户端集成,例如 Claude
  • 完善的日志系统,记录服务器运行状态和操作日志

安装

通过 Smithery 安装

要通过Smithery自动为 Claude Desktop 安装 UML 图生成工具:

npx -y @smithery/cli install @Swayingleaves/uml-mcp-server --client claude

手动安装

  1. 克隆存储库:
git clone https://github.com/yourusername/UML-MCP-Server.git cd UML-MCP-Server
  1. 创建并激活虚拟环境:
python -m venv uml-mcp-venv source uml-mcp-venv/bin/activate # Linux/Mac # Or uml-mcp-venv\Scripts\activate # Windows
  1. 安装依赖项:
pip install -r requirements.txt

使用方法

用作 Python 库

from fix_plantuml import generate_uml # Create UML code uml_code = """ @startuml Title: Simple Class Diagram class User { -String name -String email +login() +logout() } class Order { -int id -Date date +process() } User "1" -- "many" Order: places @enduml """ # Generate URLs, code, and local paths for UML diagrams result = generate_uml(uml_code) # Output result print("PlantUML code: ") print(result["code"]) print("\nPlantUML URL:") print(result["url"]) print("\nLocal file path: ") print(result["local_path"])

在 Cursor 中配置 MCP

Cursor 支持 MCP(模型上下文协议)服务器,允许您使用 Cursor 中的 UML-MCP Server 直接生成 UML 图。配置步骤如下:

  1. 确保安装了最新版本的 Cursor IDE(支持 MCP 功能)。
  2. 打开Cursor的配置文件:
  • 在 macOS 上: ~/Library/Application Support/Cursor/config.json
  • 在 Windows 上: %APPDATA%\Cursor\config.json
  • 在 Linux 上: ~/.config/Cursor/config.json
  1. 添加或修改配置文件中的“mcpServer”部分:
{ "mcpServers": { "UML-MCP-Server": { "command": "uv", "args": [ "--directory", "/Users/yourpath/UML-MCP-Server", "run", "uml_mcp_server.py" ], "output_dir": "/Users/yourpath/uml-output" } } }

配置说明:

  • UML-MCP-Server:MCP服务器的名称,可以根据需要修改
  • 命令:使用UV作为运行命令
  • args
    • 目录:指定项目目录的绝对路径
    • run :运行命令
    • uml_mcp_server.py:主程序文件
  • output_dir :指定 UML 图像的输出目录

请根据您的实际情况修改以下路径:

  • 将“/Users/Yourpath/UML-MCP Server”替换为 UML-MCP Server 项目的实际路径
  • 将“/Users/Yourpath/uml-output”替换为您要保存 UML 图像的目录路径
  1. 保存配置文件并重新启动 Cursor。
  2. 在 Cursor 中使用 UML-MCP 服务器:
  • 打开新的聊天窗口
  • 在聊天界面底部的工具栏中,您将看到“UML-MCP 服务器”工具图标
  • 单击此图标将显示 UML 工具的选项菜单
  • 选择您需要的UML图类型(例如“生成类图”,“生成序列图”等)

在 Cursor 中使用 UML 工具

在 Cursor 中,您可以输入:

例如:

1. Understand the certification process of the project 2. Generate UML code for the authentication process and generate a flowchart through UML-MCP Server 3. Attention: "output_dir": "/Users/edy/vs-code/bjwa-task-project/uml-output"

UML 工具返回的结果

无论如何使用 UML 工具,Cursor 都会调用 UML-MCP-Server 并返回以下内容:

  1. PlantUML 代码- 您可以复制此代码以在其他 PlantUML 工具中使用
  2. PlantUML URL - 您可以在浏览器中打开此 URL 来查看生成的 UML 图
  3. 本地文件路径-生成的UML图像保存在此本地路径中

例如:

Class diagram generated: PlantUML code: @startuml Title: User and Order System class User { -String name -String email +login() +logout() } class Order { -int id -Date date +process() } User "1" -- "many" Order: places @enduml PlantUML URL: http://www.plantuml.com/plantuml/png/~1UDgCqB5Bn0G1k1zYWM_EfPYQYY0Qd9oQc9oQaPcKYYcKc9gMYaiKc9gK... Local file path: /Users/username/projects/UML-MCP-Server/output/class_diagram_12345.png

您可以通过以下方式查看生成的UML图:

  • 点击返回的URL链接在浏览器中查看
  • 在文件浏览器打开本地文件路径查看保存的图片
  • 在 Cursor 中,可以使用 Markdown 语法直接在聊天窗口中显示图片

故障排除

如果您在使用UML-MCP服务器时遇到问题,可以尝试以下步骤:

  1. 检查日志文件:查看“logs”目录中的日志文件以了解错误详细信息
  2. 验证依赖项安装:确保所有依赖项都已正确安装
  3. 检查网络连接:确保可以访问 PlantUML 服务器( www.plantuml.com
  4. 检查输出目录权限:确保程序有权写入“输出”目录

常见问题及解决方法:

  • 无法生成 UML 图:检查日志中的错误消息,这可能是由于网络问题或 PlantUML 服务器暂时不可用造成的
  • 图像未在本地保存:检查“输出”目录是否存在并具有写入权限
  • MCP 服务器无法启动:检查日志文件以确保没有端口冲突或其他程序错误

贡献

欢迎贡献代码、报告问题或提供改进建议!请通过 GitHub Issues 或 Pull Requests 参与项目开发。

执照

本项目采用 MIT 许可证,详情请参阅 LICENSE 文档。

-
security - not tested
F
license - not found
-
quality - not tested

通过自然语言描述或PlantUML代码生成各种UML图的工具,作为MCP服务器,可以与Claude等客户端集成。

  1. Functional Features
    1. Installation
      1. Installing via Smithery
      2. Manual Installation
    2. Usage Method
      1. Used as a Python Library
      2. Configure MCP in Cursor
      3. Using UML Tools in Cursor
      4. The Results Returned by UML Tools
    3. Troubleshooting
      1. Contribution
        1. License
          ID: o123cncgxb