code-health-mcp

code-health-mcp

Provides comprehensive code quality analysis with quantitative metrics, historical trends, and refactoring risk prediction for C#, Python, and TypeScript codebases.

Category
访问服务器

README

Code Health MCP Server

A Model Context Protocol (MCP) server that provides comprehensive code quality analysis through quantitative metrics and trend analysis. Supports C#, Python, and TypeScript codebases with historical tracking and refactoring risk prediction.

npm version Beta License: MIT Node.js Version

Features

Core Analysis

  • File Analysis: Analyze individual files for readability, maintainability, and complexity metrics
  • Repository Analysis: Batch analyze entire repositories with intelligent caching
  • Multi-Language Support: Comprehensive support for TypeScript, JavaScript, Python, and C#

Advanced Capabilities

  • Historical Trends: Track complexity changes over time using git history (automatically builds cache on first request)
  • Risk Prediction: Predict files likely to need refactoring based on trend analysis
  • Dependency Analysis: Analyze dependency relationships, coupling, and circular dependencies
  • Performance Optimized: Handles repositories with 100k+ lines of code efficiently
  • Smart Caching: Automatically populates historical data cache when needed - no manual setup required

Metrics Provided

  • Readability scores (identifier entropy, comment ratio, line length)
  • Maintainability scores (cyclomatic complexity, coupling, cohesion)
  • Nesting depth and code structure analysis
  • Dependency fan-in/fan-out metrics
  • Git churn and change frequency
  • Refactoring risk scores with explanations

Quick Start

Installation

# No installation needed! Use npx to run directly:
npx code-health-mcp

# Or install globally if you prefer:
npm install -g code-health-mcp

Note: When using npx in your MCP configuration, the package is automatically downloaded and cached. No manual installation required!

MCP Client Configuration

For VS Code (GitHub Copilot)

Prerequisites: VS Code 1.96.0+, GitHub Copilot, and GitHub Copilot Chat extensions

Setup:

  1. Press Ctrl+Shift+P (or Cmd+Shift+P on macOS)
  2. Type: "MCP: Add Server"
  3. Select "npm"
  4. Enter package: code-health-mcp
  5. Enter name: code-health
  6. Restart VS Code

Use @code-health in Copilot Chat. See VS Code Setup Guide for more details.

For Claude Desktop

Add to your Claude Desktop configuration:

macOS/Linux: ~/.config/claude/config.json
Windows: %APPDATA%\Claude\config.json

{
  "mcpServers": {
    "code-health": {
      "command": "npx",
      "args": ["code-health-mcp"]
    }
  }
}

For Other MCP Clients

The server uses stdio transport and works with any MCP-compatible client:

npx code-health-mcp

Basic Usage

Once configured, use natural language with your MCP client:

Analyze the file src/index.ts for code quality metrics
Show me which files in this repository are at highest risk of needing refactoring
What are the complexity trends for src/server.ts over the last 50 commits?

Available Tools

The server exposes five MCP tools:

Tool Description Use Case
analyze_file Analyze a single source file Get detailed metrics for one file
analyze_repository Batch analyze entire repository Get overview of codebase health
get_complexity_trends Retrieve historical complexity data Track quality over time (auto-builds cache on first use)
predict_refactor_risk Get refactoring risk predictions Prioritize technical debt
get_dependency_graph Analyze dependency relationships Understand coupling and architecture

Documentation

Getting Started

Reference

Development

Prerequisites

  • Node.js >= 18.0.0
  • npm >= 8.0.0
  • Git (for historical analysis features)

Setup

# Clone the repository
git clone https://github.com/nagavitalp/code-health-mcp.git
cd code-health-mcp

# Install dependencies
npm install

# Build the project
npm run build

# Run in development mode
npm run dev

Available Scripts

npm run build        # Build TypeScript to JavaScript
npm run build:prod   # Production build (no source maps)
npm run dev          # Run in development mode with tsx
npm run start        # Run the built server
npm run watch        # Watch mode for development
npm run clean        # Clean build artifacts
npm run test         # Run tests
npm run lint         # Type check without emitting
npm run validate     # Run lint and tests

Project Structure

codebase-health-mcp/
├── src/
│   ├── analysis/          # Code analysis engine
│   │   ├── parsers/       # Language-specific parsers
│   │   ├── metrics/       # Metric calculation
│   │   └── __tests__/     # Tests
│   ├── server.ts          # Main MCP server
│   ├── server-config.ts   # Configuration management
│   ├── logger.ts          # Logging utilities
│   ├── error-handler.ts   # Error handling
│   └── index.ts           # Entry point
├── docs/                  # Documentation
├── dist/                  # Built output
└── package.json

Language Support

TypeScript/JavaScript

  • Full AST analysis using TypeScript compiler API
  • ES modules and CommonJS support
  • Modern JavaScript features
  • Type definitions and interfaces

Python

  • AST-based analysis using Python's ast module
  • Python 3.x syntax support
  • Class, function, and module analysis
  • Import and package dependency tracking

C#

  • Syntax tree parsing for .NET code
  • Support for modern C# features
  • Class, method, and namespace analysis
  • Using statements and assembly references

Performance

  • Analysis Speed: < 5 seconds for repositories up to 100k lines
  • Memory Usage: < 500MB for large repository analysis
  • Caching: Intelligent caching avoids recomputing unchanged files
  • Scalability: Handles large monorepos efficiently

Requirements

Required

  • Node.js >= 18.0.0
  • Git (for historical analysis)

Optional

  • .NET SDK (for enhanced C# analysis)
  • Python 3.x (for enhanced Python analysis)

Configuration

Environment Variables

Configure via environment variables:

NODE_ENV=production          # Environment mode
LOG_LEVEL=info              # Logging verbosity
CACHE_DIR=.cache            # Cache directory
GIT_HISTORY_DEPTH=100       # Commits to analyze
ENABLE_CACHE=true           # Enable caching

Optional Configuration File

Create code-health.config.json in your project root to customize analysis behavior:

# Copy the example configuration
cp node_modules/code-health-mcp/code-health.config.example.json code-health.config.json

# Edit to customize thresholds and weights

Example configuration:

{
  "complexityThresholds": {
    "cyclomaticComplexity": {
      "low": 5,
      "medium": 10,
      "high": 20
    }
  },
  "riskFactorWeights": {
    "complexityTrend": 0.4,
    "churnFrequency": 0.25
  }
}

Note: code-health.config.json is for your local use only and should be added to .gitignore.

See Configuration Guide for detailed options.

Troubleshooting

Common Issues

Server not starting: Verify Node.js version >= 18.0.0

node --version

Permission errors: Use npx or configure npm prefix

npx codebase-health-mcp

Git not found: Install Git for historical analysis

git --version

See Installation Guide for more troubleshooting.

Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Submit a pull request

License

MIT License - see LICENSE file for details

Support

Acknowledgments

Built with:


Made with ❤️ for better code quality

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选