C++ UML Class Diagram Generator
A powerful Model Context Protocol (MCP) server that recursively analyzes C++ source and header files, extracts class definitions, inheritance relationships, and member information, then generates comprehensive UML class diagrams in PlantUML format.
Features
š Multi-format C++ file support: .cpp, .hpp, .h, .cc, .cxx files
šļø Class & struct extraction: Automatically detects class/struct definitions
š Inheritance mapping: Captures inheritance relationships and generates proper UML arrows
šļø Member visibility: Handles public, private, and protected member access levels
š Directory scanning: Recursively processes entire project folders
š Content-based processing: Generate UML from provided file contents directly
š”ļø Error handling: Robust error handling with diagnostic UML output
š MCP server support: Works as both HTTP and stdio MCP server
š³ Docker ready: Containerized deployment support
⨠PlantUML output: Clean, valid PlantUML format for easy rendering
Installation
Quick Start
Docker Deployment
Usage
As a Standalone Script
Example:
As a Python Module
Directory-based Generation
Content-based Generation
As an MCP Server
This tool provides a complete Model Context Protocol (MCP) server implementation with two available tools:
Available MCP Tools
generate_cpp_uml- Directory-based UML generationParameter:
path(string) - Path to directory containing C++ filesReturns: PlantUML diagram as string
Example: Analyze entire C++ project directory
generate_cpp_uml_from_content- Content-based UML generationParameter:
file_contents(Dict[str, str]) - Dictionary mapping file names to their contentsReturns: PlantUML diagram as string
Example: Generate UML from provided source code snippets
Starting the MCP Server
HTTP Mode (recommended for web clients):
Stdio Mode (for command-line clients):
MCP Client Integration Example
Requirements
System Requirements
Python: 3.10 or higher
Operating System: Windows, Linux, macOS
Memory: Minimum 512MB RAM (more for large codebases)
Dependencies
Core Dependencies (included in pyproject.toml)
fastmcp>=0.2.0- For MCP server functionality
Python Standard Library (no installation needed)
os- File system operationsre- Regular expression parsingtyping- Type hintsjson- JSON handling (middleware)base64- Encoding (middleware)urllib.parse- URL parsing (middleware)
Development Dependencies (optional)
PlantUML Rendering (optional)
To view the generated .puml files:
VS Code: Install PlantUML extension
Online: Use PlantUML Online Server
Local: Install PlantUML with Java runtime
Output Examples
Generated PlantUML Structure
The tool generates clean, well-formatted PlantUML diagrams:
Symbol Meanings
+Public members-Private members#Protected members<|--Inheritance relationship (base <|-- derived)
File Output
Script mode: Creates
uml_output.pumlin current directoryModule mode: Returns PlantUML string for programmatic use
MCP mode: Returns PlantUML string via MCP protocol
Project Structure
Supported C++ Features
Class Detection
ā Class definitions
ā Struct definitions
ā Template classes (generics stripped for PlantUML compatibility)
ā Nested classes (basic support)
Inheritance
ā Single inheritance
ā Multiple inheritance
ā Public inheritance
ā Protected inheritance
ā Private inheritance
Member Detection
ā Public, private, protected members
ā Methods and functions
ā Variables and fields
ā Virtual and pure virtual methods
ā Constructors and destructors
ā Static members (basic support)
Limitations
ā ļø Complex template specializations may not be fully captured
ā ļø Preprocessor macros are not expanded
ā ļø Forward declarations without definitions are skipped
ā ļø Some complex C++ syntax may require manual review
Configuration
Environment Variables
TRANSPORT: Set to "http" for HTTP mode, "stdio" for stdio mode (default)PORT: HTTP server port (default: 8081)SERVER_TOKEN: Optional authentication token for stdio mode
Smithery Platform
This project includes smithery.yaml for deployment on the Smithery platform:
Containerized runtime
HTTP transport mode
Auto-scaling support
Troubleshooting
Common Issues
"No C++ classes found" message:
Verify the path contains .cpp, .hpp, .h, .cc, or .cxx files
Check file encoding (UTF-8 recommended)
Ensure class definitions use standard C++ syntax
Empty or malformed UML output:
Review C++ syntax for unsupported constructs
Check for balanced braces in class definitions
Verify inheritance syntax follows standard format
MCP server connection issues:
Ensure correct transport mode (http vs stdio)
Check port availability (8081 by default)
Verify dependencies are installed (
fastmcp)
Debug Mode
Enable verbose logging by modifying server.py:
Contributing
Fork the repository
Create a feature branch:
git checkout -b feature-nameMake your changes and add tests
Commit:
git commit -am 'Add feature-name'Push:
git push origin feature-nameCreate a Pull Request
Development Setup
License
This project is licensed under the MIT License - see the LICENSE file for details.
Changelog
v0.1.0
Initial release
Directory-based UML generation
Content-based UML generation
MCP server with HTTP and stdio transport
Docker containerization support
PlantUML output format
Class, inheritance, and member detection
Author: hydavinci
Repository: https://github.com/hydavinci/uml-diagram
This server cannot be installed