--- 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! 🎨✨**