Code Review MCP Server

by crazyrabbitLTC
Verified

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

Integrations

  • Provides functionality to clone and analyze Git repositories, supporting code review workflows for local Git repositories.

  • Enables flattening and analyzing GitHub repositories with Repomix, allowing for comprehensive code reviews of entire codebases or specific files and file types.

  • Connects to OpenAI's API to analyze code and perform detailed code reviews, with support for models like gpt-4o and gpt-4-turbo to identify issues and provide recommendations.

代码审查服务器

使用 Repomix 和 LLM 执行代码审查的自定义 MCP 服务器。

特征

  • 使用 Repomix 扁平化代码库
  • 使用大型语言模型分析代码
  • 获取包含具体问题和建议的结构化代码审查
  • 支持多个 LLM 提供商(OpenAI、Anthropic、Gemini)
  • 处理大型代码库的分块

安装

# Clone the repository git clone https://github.com/yourusername/code-review-server.git cd code-review-server # Install dependencies npm install # Build the server npm run build

配置

基于.env.example模板在根目录下创建.env文件:

cp .env.example .env

编辑.env文件以设置您首选的 LLM 提供程序和 API 密钥:

# LLM Provider Configuration LLM_PROVIDER=OPEN_AI OPENAI_API_KEY=your_openai_api_key_here

用法

作为 MCP 服务器

代码审查服务器实现了模型上下文协议(MCP),可以与任何 MCP 客户端一起使用:

# Start the server node build/index.js

该服务器公开两个主要工具:

  1. analyze_repo :使用 Repomix 扁平化代码库
  2. code_review :使用 LLM 执行代码审查

何时使用 MCP 工具

该服务器针对不同的代码分析需求提供了两种不同的工具:

分析仓库

当您需要执行以下操作时,请使用此工具:

  • 获取代码库结构和组织的高级概述
  • 将存储库扁平化为文本表示形式,以便进行初步分析
  • 无需详细审查即可了解目录结构和文件内容
  • 准备进行更深入的代码审查
  • 快速扫描代码库以识别相关文件以供进一步分析

示例情况:

  • “我想在审查之前先了解一下这个存储库的结构”
  • “告诉我这个代码库中有哪些文件和目录”
  • “给我一个代码的平面视图来了解它的组织”

代码审查

当您需要执行以下操作时,请使用此工具:

  • 执行全面的代码质量评估
  • 识别特定的安全漏洞、性能瓶颈或代码质量问题
  • 获得改进代码的可行建议
  • 对问题进行详细审查,并进行严重程度评级
  • 根据最佳实践评估代码库

示例情况:

  • “检查此代码库是否存在安全漏洞”
  • “分析这些特定 JavaScript 文件的性能”
  • “请给我一份关于这个存储库的详细代码质量评估”
  • “检查我的代码并告诉我如何提高其可维护性”

何时使用参数:

  • specificFiles :当您只想查看某些文件而不是整个存储库时
  • fileTypes :当你想关注特定的文件扩展名时(例如 .js、.ts)
  • detailLevel :使用“basic”进行快速概览或使用“detailed”进行深入分析
  • focusAreas :当你想优先考虑某些方面(安全性、性能等)时

使用 CLI 工具

为了测试目的,您可以使用附带的 CLI 工具:

node build/cli.js <repo_path> [options]

选项:

  • --files <file1,file2> :需要审查的特定文件
  • --types <.js,.ts> :要包含在审核中的文件类型
  • --detail <basic|detailed> :详细程度(默认值:详细)
  • --focus <areas> :需要关注的领域(安全性、性能、质量、可维护性)

例子:

node build/cli.js ./my-project --types .js,.ts --detail detailed --focus security,quality

发展

# Run tests npm test # Watch mode for development npm run watch # Run the MCP inspector tool npm run inspector

LLM 整合

代码审查服务器直接与多个 LLM 提供程序 API 集成:

  • OpenAI (默认值:gpt-4o)
  • 人类学(默认值:claude-3-opus-20240307)
  • 双子座(默认:gemini-1.5-pro)

提供程序配置

.env文件中配置您首选的 LLM 提供程序:

# Set which provider to use LLM_PROVIDER=OPEN_AI # Options: OPEN_AI, ANTHROPIC, or GEMINI # Provider API Keys (add your key for the chosen provider) OPENAI_API_KEY=your-openai-api-key ANTHROPIC_API_KEY=your-anthropic-api-key GEMINI_API_KEY=your-gemini-api-key

模型配置

您可以选择指定每个提供程序要使用的模型:

# Optional: Override the default models OPENAI_MODEL=gpt-4-turbo ANTHROPIC_MODEL=claude-3-sonnet-20240229 GEMINI_MODEL=gemini-1.5-flash-preview

LLM 集成如何运作

  1. code_review工具使用 Repomix 处理代码,以扁平化存储库结构
  2. 如果需要,代码将被格式化和分块以适应 LLM 上下文限制
  3. 根据重点领域和详细程度生成详细提示
  4. 提示和代码将直接发送到您选择的提供商的 LLM API
  5. LLM 响应被解析为结构化格式
  6. 评论以 JSON 对象的形式返回,其中包含问题、优势和建议

该实现包括重试逻辑,用于抵御 API 错误和适当的格式,以确保在审查中包含最相关的代码。

代码审查输出格式

代码审查以结构化的 JSON 格式返回:

{ "summary": "Brief summary of the code and its purpose", "issues": [ { "type": "SECURITY|PERFORMANCE|QUALITY|MAINTAINABILITY", "severity": "HIGH|MEDIUM|LOW", "description": "Description of the issue", "line_numbers": [12, 15], "recommendation": "Recommended fix" } ], "strengths": ["List of code strengths"], "recommendations": ["List of overall recommendations"] }

执照

麻省理工学院

-
security - not tested
F
license - not found
-
quality - not tested

使用 Repomix 和 LLM 分析代码库,提供具有特定问题和建议的结构化代码审查,支持包括 OpenAI、Anthropic 和 Gemini 在内的多个 LLM 提供商。

  1. Features
    1. Installation
      1. Configuration
        1. Usage
          1. As an MCP Server
        2. When to Use MCP Tools
          1. analyze_repo
          2. code_review
          3. Using the CLI Tool
        3. Development
          1. LLM Integration
            1. Provider Configuration
            2. Model Configuration
            3. How the LLM Integration Works
          2. Code Review Output Format
            1. License
              ID: 0tbbehvj9y