Code Analysis Context Python
FreeNot checkedA Model Context Protocol server for deep codebase understanding of Python projects, focusing on data analysis and scientific computing. It provides architectura
About
A Model Context Protocol server for deep codebase understanding of Python projects, focusing on data analysis and scientific computing. It provides architectural analysis, pattern detection, dependency mapping, test coverage analysis, and AI-optimized context generation.
README
A sophisticated Model Context Protocol (MCP) server that provides deep codebase understanding for Python projects, with a focus on data analysis frameworks and scientific computing.
🎯 Overview
This MCP server is specifically designed for Python projects, especially those using data analysis and scientific computing libraries. It provides architectural analysis, pattern detection, dependency mapping, test coverage analysis, and AI-optimized context generation.
✨ Features
- 🏗️ Architecture Analysis: Comprehensive architectural overview with module relationships, class hierarchies, and data flow patterns
- 🔍 Pattern Detection: Identify data analysis patterns, best practices, and antipatterns
- 📊 Dependency Mapping: Visualize module dependencies, detect circular dependencies, and analyze coupling
- 🧪 Coverage Analysis: Find untested code with actionable test suggestions based on complexity
- ✅ Convention Validation: Validate adherence to PEP 8 and project-specific coding conventions
- 🤖 Context Generation: Build optimal AI context packs respecting token limits and maximizing relevance
🐍 Supported Frameworks & Libraries
Data Analysis & Scientific Computing
- ✅ Pandas - DataFrame operations, data transformations, aggregations
- ✅ NumPy - Array manipulations, mathematical operations, broadcasting
- ✅ Scikit-learn - ML pipelines, model training, feature engineering
- ✅ Matplotlib/Seaborn - Visualization patterns, plot types
- ✅ Jupyter Notebooks - Notebook structure, cell analysis
Web Frameworks
- ✅ FastAPI - Async endpoints, dependency injection, Pydantic models
- ✅ Django - Models, views, ORM patterns, middleware
- ✅ Flask - Routes, blueprints, decorators
Testing Frameworks
- ✅ Pytest - Test discovery, fixtures, parametrization
- ✅ Unittest - Test cases, mocking, assertions
📦 Installation
Prerequisites
- Python 3.10 or higher
- pip or poetry for package management
Install from source
git clone https://github.com/andreahaku/code-analysis-context-python-mcp.git
cd code-analysis-context-python-mcp
pip install -e .
Development installation
pip install -e ".[dev]"
🚀 Usage
As an MCP Server
Add to your MCP client configuration:
{
"mcpServers": {
"code-analysis-python": {
"command": "python",
"args": ["-m", "src.server"]
}
}
}
Or using the installed script:
{
"mcpServers": {
"code-analysis-python": {
"command": "code-analysis-python-mcp"
}
}
}
💬 Example Usage
Once configured as an MCP server in your LLM client, you can use natural language prompts:
Analyzing a Data Science Project
"Analyze the architecture of my pandas project and show me the complexity metrics"
This will invoke the arch tool with appropriate parameters to:
- Detect pandas framework usage
- Calculate complexity for all Python files
- Show module structure and class hierarchies
- Identify high-complexity functions needing refactoring
"Find all DataFrame operations in my project and check if they follow best practices"
This will use the patterns tool to:
- Detect DataFrame chaining, groupby, merge operations
- Compare against pandas best practices
- Suggest optimizations (e.g., vectorization instead of loops)
Finding Code Issues
"Check my project for circular dependencies and show me the dependency graph"
Uses the deps tool to:
- Build import graph using NetworkX
- Detect any circular import cycles
- Calculate coupling/cohesion metrics
- Generate Mermaid diagram of dependencies
"Which files in my project have no test coverage and are most critical to test?"
The coverage tool will:
- Parse coverage.xml or .coverage file
- Prioritize gaps based on complexity and file location
- Generate pytest test scaffolds for critical files
- Show untested functions with complexity scores
Code Quality
"Validate my project follows PEP 8 conventions and show naming violations"
The conventions tool will:
- Check snake_case, PascalCase, UPPER_SNAKE_CASE naming
- Validate import grouping and ordering
- Check for missing docstrings and type hints
- Report consistency score by category
AI-Assisted Development
"Generate a context pack for adding data validation to my pandas DataFrame processing pipeline"
The context tool will:
- Extract keywords ("data validation", "pandas", "DataFrame")
- Score files by relevance to the task
- Select most relevant files within token budget
- Format as markdown with code snippets and suggestions
🛠️ Available Tools
1. arch - Architecture Analysis
Analyze Python project architecture and structure.
{
"path": "/path/to/project",
"depth": "d",
"types": ["mod", "class", "func", "api"],
"diagrams": true,
"metrics": true,
"details": true,
"minCx": 10,
"maxFiles": 50
}
Parameters:
path: Project root directorydepth: Analysis depth - "o" (overview), "d" (detailed), "x" (deep)types: Analysis types - mod, class, func, api, model, view, notebook, pipeline, dataflowdiagrams: Generate Mermaid diagramsmetrics: Include code metricsdetails: Per-file detailed metricsminCx: Minimum complexity threshold for filteringmaxFiles: Maximum number of files in detailed outputmemSuggest: Generate memory suggestions for llm-memory MCPfw: Force framework detection - pandas, numpy, sklearn, fastapi, django, flask, jupyter
Detects:
- Module structure and organization
- Class hierarchies and inheritance patterns
- Function definitions and decorators
- API endpoints (FastAPI/Django/Flask)
- Data models and Pydantic schemas
- Jupyter notebook structure
- Data processing pipelines
2. deps - Dependency Analysis
Analyze module dependencies and imports.
{
"path": "/path/to/project",
"circular": true,
"metrics": true,
"diagram": true,
"focus": "src/models",
"depth": 3
}
Parameters:
path: Project root directorycircular: Detect circular dependenciesmetrics: Calculate coupling/cohesion metricsdiagram: Generate Mermaid dependency graphfocus: Focus on specific moduledepth: Maximum dependency depth to traverseexternal: Include site-packages dependencies
Features:
- Import graph construction
- Circular dependency detection with cycle paths
- Coupling and cohesion metrics
- Dependency hotspots (hubs and bottlenecks)
- Module classification (utility, service, model, etc.)
3. patterns - Pattern Detection
Detect data analysis and coding patterns.
{
"path": "/path/to/project",
"types": ["dataframe", "array", "pipeline", "model", "viz"],
"custom": true,
"best": true,
"suggest": true
}
Parameters:
path: Project root directorytypes: Pattern types to detectdataframe: Pandas DataFrame operationsarray: NumPy array manipulationspipeline: Scikit-learn pipelinesmodel: ML model training patternsviz: Matplotlib/Seaborn visualizationsapi: FastAPI/Django/Flask endpointsorm: Django ORM patternsasync: Async/await patternsdecorator: Custom decoratorscontext: Context managers
custom: Detect custom patternsbest: Compare with best practicessuggest: Generate improvement suggestions
Detected Patterns:
- Pandas: DataFrame chaining, groupby operations, merge strategies
- NumPy: Broadcasting, vectorization, array creation patterns
- Scikit-learn: Pipelines, transformers, model training
- Visualization: Plot types, figure management, style patterns
- API: Endpoint patterns, request/response models, middleware
- Async: Async functions, coroutines, event loops
- Testing: Fixtures, mocking, parametrization
4. coverage - Test Coverage Analysis
Analyze test coverage and generate test suggestions.
{
"path": "/path/to/project",
"report": ".coverage",
"fw": "pytest",
"threshold": {
"lines": 80,
"functions": 80,
"branches": 75
},
"priority": "high",
"tests": true,
"cx": true
}
Parameters:
path: Project root directoryreport: Coverage report path (.coverage, coverage.xml)fw: Test framework - pytest, unittest, nosethreshold: Coverage thresholdspriority: Filter priority - crit, high, med, low, alltests: Generate test scaffoldscx: Analyze complexity for prioritization
Features:
- Parse coverage.py reports
- Identify untested modules and functions
- Complexity-based prioritization
- Test scaffold generation (pytest/unittest)
- Framework-specific test patterns
5. conventions - Convention Validation
Validate PEP 8 and coding conventions.
{
"path": "/path/to/project",
"auto": true,
"severity": "warn",
"rules": {
"naming": {
"functions": "snake_case",
"classes": "PascalCase"
}
}
}
Parameters:
path: Project root directoryauto: Auto-detect project conventionsseverity: Minimum severity - err, warn, inforules: Custom convention rules
Checks:
- PEP 8 compliance
- Naming conventions (snake_case, PascalCase, UPPER_CASE)
- Import ordering and grouping
- Docstring presence
- Type hint usage
- Line length and formatting
6. context - Context Pack Generation
Generate AI-optimized context packs.
{
"task": "Add data preprocessing pipeline with pandas",
"path": "/path/to/project",
"tokens": 50000,
"include": ["files", "arch", "patterns"],
"focus": ["src/preprocessing", "src/models"],
"format": "md",
"lineNums": true,
"strategy": "rel"
}
Parameters:
task: Task description (required)path: Project root directorytokens: Token budget (default: 50000)include: Content types - files, deps, tests, types, arch, conv, notebooksfocus: Priority files/directorieshistory: Include git historyformat: Output format - md, json, xmllineNums: Include line numbersstrategy: Optimization strategy - rel (relevance), wide (breadth), deep (depth)
Features:
- Task-based file relevance scoring
- Token budget management
- Multiple output formats
- Architectural context inclusion
- Dependency traversal
📝 Configuration
Create a .code-analysis.json file in your project root:
{
"project": {
"name": "MyDataProject",
"type": "pandas"
},
"analysis": {
"includeGlobs": ["src/**/*.py", "notebooks/**/*.ipynb"],
"excludeGlobs": ["**/test_*.py", "**/__pycache__/**", "**/venv/**"]
},
"conventions": {
"naming": {
"functions": "snake_case",
"classes": "PascalCase",
"constants": "UPPER_SNAKE_CASE"
},
"imports": {
"order": ["stdlib", "third_party", "local"],
"grouping": true
}
},
"coverage": {
"threshold": {
"lines": 80,
"functions": 80,
"branches": 75
}
}
}
🔧 Development
Project Structure
code-analysis-context-python-mcp/
├── src/
│ ├── __init__.py
│ ├── server.py # MCP server entry point
│ ├── tools/ # Tool implementations
│ │ ├── architecture_analyzer.py
│ │ ├── pattern_detector.py
│ │ ├── dependency_mapper.py
│ │ ├── coverage_analyzer.py
│ │ ├── convention_validator.py
│ │ └── context_pack_generator.py
│ ├── analyzers/ # Framework-specific analyzers
│ ├── utils/ # Utilities (AST, complexity, etc.)
│ └── types/ # Type definitions
├── tests/ # Test suite
├── pyproject.toml
└── README.md
Running Tests
pytest
pytest --cov=src --cov-report=html
Code Quality
# Format code
black src tests
isort src tests
# Lint
flake8 src tests
# Type checking
mypy src
🎯 Implementation Status
✅ All Features Complete!
Core Tools (100% Complete)
- ✅ Architecture Analyzer - AST parsing, complexity metrics, framework detection, Mermaid diagrams
- ✅ Pattern Detector - DataFrame/array/ML patterns, async/decorators, antipatterns, best practices
- ✅ Dependency Mapper - Import graphs, circular detection, coupling metrics, hotspots
- ✅ Coverage Analyzer - Coverage.py integration, test scaffolds, complexity-based prioritization
- ✅ Convention Validator - PEP 8 checking, naming conventions, docstrings, auto-detection
- ✅ Context Pack Generator - Task-based relevance, token budgets, multiple formats, AI optimization
Utilities (100% Complete)
- ✅ AST Parser - Classes, functions, imports, complexity
- ✅ Complexity Analyzer - Radon integration, maintainability index
- ✅ File Scanner - Glob patterns, intelligent filtering
- ✅ Framework Detector - 14+ frameworks, pattern matching
- ✅ Diagram Generator - Mermaid architecture & dependency graphs
Features
- ✅ Circular dependency detection with cycle paths
- ✅ LLM memory integration for persistent context
- ✅ Test scaffold generation (pytest/unittest)
- ✅ Multi-format output (JSON, Markdown, XML)
- ✅ Token budget management for AI tools
- ✅ Complexity-based prioritization
- ✅ Mermaid diagram generation
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
📄 License
MIT
👨💻 Author
Andrea Salvatore (@andreahaku) with Claude (Anthropic)
🔗 Related Projects
- llm-memory-mcp - Persistent memory for LLM tools
- code-analysis-context-mcp - TypeScript/JavaScript version
🧪 Testing
Test all tools on this project itself:
python3 test_tools.py
This will run all 6 tools and display:
- Project architecture and complexity metrics
- Pattern detection (async, decorators, context managers)
- Dependency graph and coupling metrics
- Coverage gaps with priorities
- Convention violations and consistency scores
- AI context pack generation
📊 Example Output
Running the tools on this project shows:
- 18 modules, 9 classes, 61 functions, 3,787 lines of code
- 38 patterns detected (17 async functions, 21 decorators)
- 0 circular dependencies - clean architecture!
- 0% test coverage - needs tests (demonstrates coverage tool)
- High complexity (avg 36.8) - identifies refactoring targets
- 100% naming consistency - follows PEP 8
Status: ✅ Production Ready - All 6 tools fully implemented and tested
Python Version: 3.10+
Lines of Code: 3,787 Test Coverage: Functional (integration tests via test_tools.py) Code Quality: High consistency, follows PEP 8
Installing Code Analysis Context Python
This server has no published package — it is built from source. Open the repository and follow its README.
▸ github.com/andreahaku/code-analysis-context-python-mcpFAQ
Is Code Analysis Context Python MCP free?
Yes, Code Analysis Context Python MCP is free — one-click install via Unyly at no cost.
Does Code Analysis Context Python need an API key?
No, Code Analysis Context Python runs without API keys or environment variables.
Is Code Analysis Context Python hosted or self-hosted?
Self-hosted: the server runs locally on your machine via the install command above.
How do I install Code Analysis Context Python in Claude Desktop, Claude Code or Cursor?
Open Code Analysis Context Python on unyly.org, pick your client tab (Claude Desktop, Claude Code, Cursor) and press Install — the config is generated automatically, no JSON editing.
Related MCPs
GitHub
PRs, issues, code search, CI status
by GitHubFilesystem
Secure file operations with configurable access controls.
Memory
Knowledge graph-based persistent memory system.
Template MCP Server
A CLI tool to create a new Model Context Protocol server project with TypeScript support, dual transport options, and an extensible structure
by mcpdotdirectCompare Code Analysis Context Python with
Not sure what to pick?
Find your stack in 60 seconds
Author?
Embed badge for your README
Browse similar
All development MCPs
