Agents-MCP-Hackathon/Python-Code-to-Diagram-Generator-MCP
6
๐ 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
- Paste Python Code: Enter your Python code in the text area
- Generate Diagram: Click "Generate Diagram" to create UML visualization
- Analyze Structure: Use "Analyze Code" for detailed code analysis
- 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):
{
"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:
{
"mcpServers": {
"python-diagram-generator": {
"url": "https://agents-mcp-hackathon-python-code-to-diagram-gene-cc753c2.hf.space/gradio_api/mcp/sse"
}
}
}For Private Spaces:
{
"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
- generate_diagram: Creates UML class diagrams from Python code
- 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
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
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! ๐จโจ
