MCP-CodeReviewer

MCP-CodeReviewer

A three-layer funnel AI code review engine that reduces LLM token consumption by 70%+ while providing deep code analysis. It integrates with GitHub PRs via MCP protocol to automate code review with static analysis, RAG, and LLM-based checks.

Category
访问服务器

README

🔍 MCP-CodeReviewer

基于 MCP 协议的三层漏斗式 AI 代码审查引擎 通过确定性静态分析与动态模型路由,在保证审查深度的同时降低 70%+ 的 LLM Token 消耗。

Python 3.11+ MCP Protocol License: MIT


🏗️ 架构

PR 触发 → GitHub Actions
  → git diff (宿主机) → Docker 容器
    → ci_runner.py
      → 白名单代码提取 + 正则函数提取
      → RAG 规范检索 (独立降级)
      → 影响面雷达 ripgrep (独立降级)
      → Phase3 Prompt 拼装
      → LLM 审查 (deepseek-v4-flash)
      → 三级防御 L1/L2/L3 → GitHub 行级评论 (含 Suggestion)
      → ReviewMetrics 落盘 → upload-artifact

🚀 快速开始

1. 安装

git clone <repo-url>
cd mcp-code-reviewer
pip install -r requirements.txt

2. Mock 模式(无需 API Key)

python orchestrator.py --mock

3. 真实审查

export DEEPSEEK_API_KEY=***
python orchestrator.py

4. 接入 GitHub PR

# 复制 workflow 到目标仓库
cp .github/workflows/ai-review.yml <target-repo>/.github/workflows/

# 配置 Secrets: DEEPSEEK_API_KEY
# 配置 Actions 权限: Read and write
# 创建 PR,自动触发审查

详见 DEPLOYMENT_GUIDE.md

📁 项目结构

├── mcp_server.py          # MCP Server (3 Tools)
├── orchestrator.py        # MCP Client + Prompt 工程
├── ci_runner.py           # CI/CD 桥梁 + 三级防御
├── rag_engine.py          # 轻量 RAG (SQLite)
├── impact_analyzer.py     # 影响面雷达 (ripgrep)
├── metrics.py             # ReviewMetrics 黑匣子
├── Dockerfile             # 生产级镜像
├── scripts/
│   └── aggregate_metrics.py  # Metrics 聚合分析
└── test_cases/            # 测试用例

🛡️ 三级防御

级别 方法 防护目标
L1 unidiff 行号映射 O(1) 精确匹配 防 LLM 幻觉原代码
L2 物理字符串切片提取缩进 防正则跨行漏洞
L3 AST 宽容预检 + 补 pass 防破坏性提交

校验失败不丢弃 issue → 降级为纯文本警告评论。

🧪 测试

python test_static_analysis.py     # 15 用例 ✅
python test_complexity_router.py   # 9 用例 ✅
python eval_quality.py             # LLM 质量评估 (30 bugs)

📊 可观测性

每次审查自动生成 review_metrics.json,包含 30+ 指标:

  • 管线各阶段耗时 (RAG/雷达/LLM)
  • 三级防御 L1/L2/L3 通过/失败计数
  • Suggestion 成功率
  • RAG 降级率
# 本地聚合分析
python scripts/aggregate_metrics.py ./downloaded_metrics/

🔧 技术栈

组件 技术
MCP Server Python + mcp SDK + FastAPI
静态分析 ast.NodeVisitor
Diff 解析 unidiff
影响面分析 ripgrep
RAG SQLite + numpy
LLM Gateway litellm
容器化 Docker (python:3.11-slim)
CI/CD GitHub Actions

📝 技术债

TECH_DEBT.md

License

MIT

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选