mcp git评审员
在提交级别进行上下文感知、人工智能驱动的代码审查。使用本地git历史记录-不需要PR。
作为MCP主机构建,它协调工具服务器从代码库中收集上下文,并将其提供给LLM进行智能的、特定于项目的审查。
盒子里有什么
src/
cli.ts CLI entry point (commander)
config.ts YAML/JSON config loader (zod validated)
reviewer.ts Review orchestration + watch mode
output.ts Terminal rendering (chalk, boxen)
cache.ts Hash-based review caching
usage.ts Token usage tracking and cost estimation
errors.ts Typed error hierarchy (ToolServerError, ApiError, etc.)
git/
resolver.ts Translates user input to git revision ranges
commands.ts simple-git wrappers (diff, blame, log)
host/
mcp-host.ts MCP host lifecycle — spawns tool servers
transport.ts Stdio JSON-RPC transport
tool-registry.ts Tool capability discovery and call routing
conversation.ts LLM conversation loop with usage tracking
llm/
provider.ts Shared LLMProvider interface and types
anthropic.ts Anthropic SDK provider with rate-limit retry
openai.ts OpenAI-compatible provider (OpenRouter, DeepSeek, Kimi, etc.)
index.ts Provider factory + model alias resolution
tools/
git-diff/ Diff, stats, commit messages
file-context/ File reading with line numbers, directory listing
conventions/ Lint config scanning, pattern search, project conventions
related-files/ Import graph, exports, test file discovery, type references
prompts/
system.ts System prompt with review instructions
templates.ts Security and performance review templates技术栈
| 类别 | 工具 |
|---|---|
| 语言 | TypeScript 5(严格) |
| 运行时 | Node.js 20+/Bun |
| 包管理器 | Bun |
| AI | Anthropic SDK、OpenAI兼容API、MCP SDK |
| Git | 简单Git |
| CLI | 指挥官,粉笔,拳击手 |
| 配置 | zod、yaml、dotenv |
| 棉绒和格式 | 生物特征 |
| 测试 | Vitest |
| CI | GitHub Actions,SonarCloud |
设置
# Install bun (if not already installed)
curl -fsSL https://bun.sh/install | bash
# Install dependencies
bun install
# Build the project
bun run build
# Copy environment template and add your API key
cp .env.example .env必填项 .env (取决于供应商):
ANTHROPIC_API_KEY=sk-ant-... # For Anthropic (default)
OPENROUTER_API_KEY=sk-or-... # For OpenRouter models (qwen3-coder, etc.)
DEEPSEEK_API_KEY=sk-... # For DeepSeek
MOONSHOT_API_KEY=sk-... # For Kimi / Moonshot全局安装
链接CLI以便运行 mcp-review 从任何git仓库:
npm link在另一个项目中使用
导航到任何git repo并运行 mcp-review 直接:
cd /path/to/your-project
mcp-review --staged(可选)创建 .mcp-review.yml 在该项目的根目录中自定义审核行为:
model: qwen3-coder
focus:
- security
- performance
ignore:
- "*.test.ts"
- dist
conventions:
- "Use named exports"
- "Error messages should be user-facing"看 配置 所有可用选项。
发展
# Run in dev mode
bun run dev
# Type check
bun run typecheck
# Lint and format
bun run lint
bun run format
# Run tests
bun run test
bun run test:watch
bun run test:coverage验证
在本地运行完整的CI管道:
bun run verify这将运行lint、格式检查、类型检查、构建和测试,并在最后显示通过/失败摘要。
用法
# Review the last commit
mcp-review HEAD~1..HEAD
# Review staged changes (pre-commit)
mcp-review --staged
# Review a specific commit
mcp-review abc123
# Review last N commits
mcp-review --last 3
# Review everything since yesterday
mcp-review --since yesterday
# Focus on specific areas
mcp-review --staged --focus security,performance
# Watch mode — auto-review each new commit
mcp-review --watch
# Skip cache for a fresh review
mcp-review HEAD~1..HEAD --no-cache
# JSON output for CI pipelines (exit code 1 on critical findings)
mcp-review HEAD~1..HEAD --output json
# Verbose mode — show token usage and cost
mcp-review HEAD~1..HEAD --verbose
# Use a specific model
mcp-review HEAD~1 --model qwen3-coder
# Use a custom OpenAI-compatible endpoint
mcp-review HEAD~1 --provider openai --base-url https://openrouter.ai/api/v1 --model qwen/qwen3-coder:free --api-key-env OPENROUTER_API_KEY多提供商支持
mcp review通过摘要支持多个LLM提供者 LLMProvider 界面。
模型别名
自动配置提供程序、基本URL和API密钥的短名称:
| 别名 | 模型 | 提供商 | API关键环境 |
|---|---|---|---|
qwen3-coder | qwen/qwen3-coder:free 通过OpenRouter | openai | OPENROUTER_API_KEY |
deepseek | deepseek-chat 通过DeepSeek API | openai | DEEPSEEK_API_KEY |
kimi | kimi-k2.5 通过Moonshot API | openai | MOONSHOT_API_KEY |
使用别名 --model 或者在您的配置文件中:
mcp-review HEAD~1 --model qwen3-coder提供商
- Anthropic (默认)--使用Anthropic SDK。模型:
claude-sonnet-4-20250514,claude-opus-4-20250514,claude-haiku-3-5-20241022 - OpenAI兼容 -适用于实现OpenAI聊天完成API的任何端点:OpenRouter、DeepSeek、Kimi/Moonshot和其他
配置
创建 .mcp-review.yml 在项目根目录中:
model: qwen3-coder
focus:
- security
- performance
ignore:
- "*.test.ts"
- dist
conventions:
- "Use named exports"
- "Error messages should be user-facing"所有配置字段:
| 字段 | 类型 | 默认值 | 描述 | |
|---|---|---|---|---|
model | 字符串 | claude-sonnet-4-20250514 | 型号名称或别名 | |
provider | anthropic | openai | anthropic | LLM提供程序(由别名自动设置) |
base_url | string | - | 与OpenAI兼容的API的基本URL | |
api_key_env | string | - | API键的环境变量名称 | |
focus | string\[\] | [] | 重点领域:安全性、性能、一致性 | |
ignore | string\[\] | [] | 要跳过的文件的全局模式 | |
conventions | string\[\] | [] | 执行项目惯例 | |
max_files | 编号 | 20 | 要查看的最大文件数 | |
context_lines | 编号 | 5 | 围绕变化的背景线 | |
no_cache | 布尔值 | false | 跳过审阅缓存 |
CI集成
该仓库包括GitHub Actions工作流:
.github/workflows/ci.yml--在push/PR上运行lint、类型检查、构建和测试.github/workflows/sonarqube.yml--将覆盖范围上传到SonarCloud
CI的退出代码:
0--审查通过(无关键发现)1--检测到关键发现2--运行时错误
建筑
mcp评论是 MCP主机 将工具服务器作为子进程生成:
CLI → MCPHost.initialize()
├── git-diff server (diff, stats, commit messages)
├── file-context server (read files, list directories)
├── conventions server (lint configs, pattern search)
└── related-files server (imports, exports, test files, types)
↓
LLMProvider (Anthropic or OpenAI-compatible)
↓
Structured ReviewResult → terminal output每个工具服务器都是一个使用stdio传输的独立MCP服务器。主机通过以下方式发现工具 tools/list 并通过以下方式将LLM工具调用路由到正确的服务器 tools/call.
评论按内容哈希缓存。对同一个diff的重复审查完全跳过API调用。
许可证
麻省理工学院
