A newer version of the Gradio SDK is available:
6.5.1
metadata
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
pip install "gradio[mcp]"
Usage
Running the MCP Server
python server.py
The server will start on http://0.0.0.0:7860 with MCP protocol enabled.
MCP Tools Available
full_code_analysis- Complete code analysis with all metricscalculate_cyclomatic_complexity- Complexity calculation onlyanalyze_code_metrics- Code metrics onlydetect_code_smells- Code smell detection only
Example Usage
# 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