mcp-code-reviewer

mcp-code-reviewer

A code review MCP server built on FastMCP, supporting security audit, style check, complexity analysis, and bug pattern detection for Python code.

Category
Visit Server

README

mcp-code-reviewer

CI Python 3.10+ MCP License: MIT

基于 FastMCP 构建的代码审查 MCP Server,支持对 Python 代码进行安全审查、风格检查、复杂度分析和 Bug 模式检测。

功能特性

工具 说明 输入 输出
review_code 全面代码审查 code + language Markdown 报告 (安全+风格+复杂度+Bug)
check_security 安全漏洞检测 code + language Markdown 安全报告
analyze_complexity 圈复杂度分析 code + language Markdown 复杂度报告
suggest_fixes 自动修复建议 code + issue_type Markdown 修复方案
review_diff Git Diff 增量审查 diff + language Markdown Diff 报告

检测能力

  • 安全审查: SQL注入、命令注入、exec/evalpickle.loads、硬编码密钥、SSRF、不安全的 yaml.load
  • 风格检查: 行过长 (>120字符)、缺失 docstring、命名规范、魔法数字、未使用 import、尾随空格
  • 复杂度分析: 圈复杂度 (McCabe)、函数长度、嵌套深度、参数数量、返回语句数量
  • Bug 检测: 可变默认参数、除零风险、类型不匹配 (str+int)、循环中修改列表、裸露 except

快速开始

前置要求

  • Python 3.10+
  • uv (推荐) 或 pip

安装

# 克隆仓库
git clone https://github.com/your-username/mcp-code-reviewer.git
cd mcp-code-reviewer

# 使用 pip 安装依赖
pip install -r requirements.txt

# 或使用 uv
uv sync

运行

# 直接运行
python server.py

# 使用 uv
uv run python server.py

MCP 客户端配置

将以下配置添加到你的 MCP 客户端配置文件中:

Cursor

{
  "mcpServers": {
    "code-reviewer": {
      "command": "uv",
      "args": ["run", "--directory", "/path/to/mcp-code-reviewer", "server.py"]
    }
  }
}

Claude Desktop

{
  "mcpServers": {
    "code-reviewer": {
      "command": "uv",
      "args": ["run", "--directory", "/path/to/mcp-code-reviewer", "server.py"]
    }
  }
}

VS Code (vscode-mcp)

{
  "servers": {
    "code-reviewer": {
      "type": "command",
      "command": "uv",
      "args": ["run", "--directory", "/path/to/mcp-code-reviewer", "server.py"]
    }
  }
}

注意: 将 /path/to/mcp-code-reviewer 替换为实际的项目路径。

使用示例

全面代码审查

# 完整的 MCP 工具调用
review_result = await mcp.call_tool("review_code", {
    "code": '''
def process(data):
    import subprocess
    subprocess.run("rm -rf " + data, shell=True)
    return data
''',
    "language": "python"
})

安全审查

result = await mcp.call_tool("check_security", {
    "code": 'eval(user_input)',
    "language": "python"
})

Git Diff 审查

result = await mcp.call_tool("review_diff", {
    "diff": """
diff --git a/app.py b/app.py
+import os
+os.system("rm -rf /tmp")
""",
    "language": "python"
})

项目结构

mcp-code-reviewer/
├── server.py              # MCP Server 主程序
├── reviewers/
│   ├── __init__.py
│   ├── security.py        # 安全检查器
│   ├── style.py           # 代码风格检查
│   ├── complexity.py      # 复杂度分析
│   └── bugfinder.py       # Bug 模式检测
├── tests/
│   ├── __init__.py
│   ├── test_security.py
│   ├── test_style.py
│   ├── test_complexity.py
│   └── test_bugfinder.py
├── requirements.txt
├── pyproject.toml
├── .gitignore
└── README.md

运行测试

# 运行所有测试
pytest

# 运行特定测试文件
pytest tests/test_security.py -v

# 生成覆盖率报告
pytest --cov=reviewers --cov-report=term-missing

支持的资源

MCP Server 提供了以下只读资源:

  • reviewer://languages - 支持的语言列表
  • reviewer://metrics - 审查指标说明
  • reviewer://about - 关于信息

许可证

MIT

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured