File size: 2,525 Bytes
70be908 f44fd20 | 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 | ---
title: Code Complexity Analyzer
emoji: 📊
colorFrom: gray
colorTo: pink
sdk: gradio
sdk_version: 5.49.1
app_file: app.py
pinned: false
license: mit
short_description: An MCP Server to analyse Python code complexity
---
# Code Complexity Analyzer MCP Server
**Category**: Enterprise MCP Server
**Tags**: `building-mcp-track-enterprise`
## Overview
An MCP server that analyzes Python code complexity and provides actionable insights about code quality, maintainability, and potential refactoring opportunities.
## Features
### 1. Cyclomatic Complexity Analysis
- Calculates cyclomatic complexity metric
- Provides complexity level assessment (Low/Moderate/High/Critical)
- Offers specific refactoring recommendations
### 2. Code Metrics
- Lines of Code (LOC)
- Source Lines of Code (SLOC)
- Comment lines and ratio
- Function and class counts
- Comment-to-code ratio analysis
### 3. Code Smell Detection
- Long functions (>50 lines)
- Too many parameters (>5)
- Deep nesting (>4 levels)
- Duplicate code detection
### 4. Comprehensive Analysis
- Combined report with all metrics
- Markdown-formatted output
- Clear recommendations
## Installation
```bash
pip install "gradio[mcp]"
```
## Usage
### Running the MCP Server
```bash
python server.py
```
The server will start on `http://0.0.0.0:7860` with MCP protocol enabled.
### MCP Tools Available
1. `full_code_analysis` - Complete code analysis with all metrics
2. `calculate_cyclomatic_complexity` - Complexity calculation only
3. `analyze_code_metrics` - Code metrics only
4. `detect_code_smells` - Code smell detection only
### Example Usage
```python
# Example code to analyze
code = """
def complex_function(a, b, c, d, e, f):
if a > 0:
if b > 0:
if c > 0:
if d > 0:
if e > 0:
return a + b + c + d + e + f
return 0
"""
```
## Why This Matters
- **For Teams**: Maintain code quality standards across projects
- **For Developers**: Get immediate feedback on code complexity
- **For Code Reviews**: Automated complexity assessment
- **For Legacy Code**: Identify refactoring priorities
## Technical Details
- Built with Gradio MCP server capabilities
- AST-based Python code analysis
- Real-time complexity calculation
- No external dependencies for analysis
## Future Enhancements
- Support for more programming languages
- Integration with CI/CD pipelines
- Historical complexity tracking
- Custom complexity thresholds
- Team-wide analytics dashboard
|