File size: 6,788 Bytes
29cc16e 99a41ea ba181c2 99a41ea 29cc16e 99a41ea 29cc16e 99a41ea 29cc16e 99a41ea ba181c2 99a41ea ba181c2 99a41ea ba181c2 99a41ea |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
---
title: Python UML Diagram Generator & MCP Server
video: https://youtu.be/n2uV_mX9Byc
emoji: π
colorFrom: blue
colorTo: purple
sdk: gradio
sdk_version: 5.33.0
app_file: app.py
pinned: false
license: mit
models:
- PlantUML
tags:
- uml
- python
- diagrams
- mcp
- code-analysis
- visualization
- mcp-server-track
short_description: Python UML diagram generator with MCP server support
---
# π Python UML Diagram Generator & MCP Server
A powerful tool that generates UML class diagrams from Python code with integrated Model Context Protocol (MCP) server functionality for AI assistants.
## π Features
- **π¨ Interactive Web Interface**: Generate UML class diagrams interactively from Python code
- **π€ MCP Server Integration**: Works with Claude Desktop, Cursor, and other MCP clients
- **π Advanced Code Analysis**: Enhanced analysis with call graphs, complexity metrics, and function dependencies
- **π Function Call Graphs**: Visualize function relationships and dependencies using pyan3 + graphviz
- **π Complexity Metrics**: Cyclomatic complexity, lines of code, parameter analysis
- **βοΈ Standalone Function Analysis**: Perfect for utility scripts with functions (not just classes)
- **π Real-time Processing**: Fast diagram generation using PlantUML
- **πΎ Multiple Formats**: PNG images, PlantUML source code, and call graph visualizations
- **π Inheritance Visualization**: Clear parent-child class relationships
## π― Quick Start
1. **Paste Python Code**: Enter your Python code in the text area
2. **Generate Diagram**: Click "Generate Diagram" to create UML visualization
3. **Analyze Structure**: Use "Analyze Code" for detailed code analysis
4. **Download Results**: Save generated diagrams and analysis
## π€ MCP Server Integration
This Space automatically serves as an MCP server! To integrate with AI assistants:
### For Claude Desktop (with mcp-remote):
```json
{
"mcpServers": {
"python-diagram-generator": {
"command": "npx",
"args": [
"mcp-remote",
"https://agents-mcp-hackathon-python-code-to-diagram-gene-cc753c2.hf.space/gradio_api/mcp/sse",
"--transport",
"sse-only"
]
}
}
}
```
### For Cursor, Cline, and other SSE-compatible clients:
```json
{
"mcpServers": {
"python-diagram-generator": {
"url": "https://agents-mcp-hackathon-python-code-to-diagram-gene-cc753c2.hf.space/gradio_api/mcp/sse"
}
}
}
```
### For Private Spaces:
```json
{
"mcpServers": {
"python-diagram-generator": {
"url": "https://agents-mcp-hackathon-python-code-to-diagram-gene-cc753c2.hf.space/gradio_api/mcp/sse",
"headers": {
"Authorization": "Bearer hf_your_token_here"
}
}
}
}
```
## π οΈ Available MCP Tools
1. **generate_diagram**: Creates UML class diagrams from Python code
2. **analyze_code_structure**: Provides detailed code structure analysis with enhanced metrics
## π Advanced Analysis Features
### **π¬ Advanced Analysis Tab**
- **Function Call Graphs**: Visual network diagrams showing function dependencies
- **Complexity Analysis**: Cyclomatic complexity scoring for each function
- **Function Metrics**: Lines of code, parameter counts, docstring detection
- **Call Relationship Mapping**: Which functions call which, and call frequency analysis
- **Isolated Function Detection**: Find functions that aren't connected to others
- **Code Quality Recommendations**: Suggestions for refactoring and improvements
### **Enhanced for Standalone Functions**
Perfect for analyzing utility scripts, mathematical functions, data processing pipelines, and other function-heavy code that traditional class-based UML tools miss.
## π‘ Usage Examples
### Example 1: Basic Classes
```python
class Animal:
def __init__(self, name: str):
self.name = name
def speak(self) -> str:
pass
class Dog(Animal):
def speak(self) -> str:
return f"{self.name} says Woof!"
```
### Example 2: Complex Inheritance
```python
class Vehicle:
def __init__(self, brand: str, model: str):
self.brand = brand
self.model = model
class Car(Vehicle):
def __init__(self, brand: str, model: str, doors: int):
super().__init__(brand, model)
self.doors = doors
def start_engine(self):
return "Engine started"
class ElectricCar(Car):
def __init__(self, brand: str, model: str, doors: int, battery_capacity: float):
super().__init__(brand, model, doors)
self.battery_capacity = battery_capacity
def charge(self):
return "Charging battery"
```
## π§ Technical Details
- **Built with**: Gradio 5.33+ with MCP support
- **Analysis Engine**: Python AST + py2puml + pyan3
- **Call Graph Generation**: pyan3 + graphviz for function dependency visualization
- **Diagram Rendering**: PlantUML web service + graphviz DOT rendering
- **Output Formats**: PNG images, PlantUML source code, DOT call graphs
- **MCP Protocol**: Server-Sent Events (SSE) transport
- **Function Analysis**: Cyclomatic complexity, parameter analysis, docstring detection
## π¨ Features Showcase
- **Real-time Analysis**: Code structure updates as you type
- **Inheritance Detection**: Visualizes parent-child relationships
- **Method & Attribute Mapping**: Complete class member analysis
- **Function Call Graphs**: Interactive network diagrams of function dependencies
- **Complexity Metrics**: Cyclomatic complexity analysis with recommendations
- **Standalone Function Support**: Perfect for utility scripts and mathematical functions
- **Error Handling**: Syntax error detection and reporting
- **Sample Code**: Ready-to-use examples for both classes and functions
## π± Compatible MCP Clients
- **Claude Desktop** (via mcp-remote)
- **Cursor IDE**
- **Cline VS Code Extension**
- **Continue VS Code Extension**
- **Custom MCP implementations**
## π Perfect For
- **Developers**: Understanding code structure and function dependencies quickly
- **Code Reviews**: Visualizing class relationships and call patterns
- **Documentation**: Generating architectural diagrams and function flow charts
- **Education**: Teaching OOP concepts and functional programming patterns
- **Utility Script Analysis**: Understanding standalone function files and mathematical algorithms
- **Refactoring**: Identifying complex functions and isolated code segments
- **AI Assistants**: Enhanced code analysis capabilities with complexity metrics
## π Support & Feedback
- Test with the provided sample code first
- Check the MCP configuration tab for setup instructions
- View API documentation via the "View API" link in the footer
---
**Transform your Python code into beautiful UML diagrams! π¨β¨**
|