使用说明
代码审查MCP服务器
通过MCP(模型上下文协议)公开的AI驱动的代码审查工具。直接在Claude code或任何MCP客户端中从LLM获取详细的代码审查。
特性
review_file-使用焦点选项(常规、安全、性能)查看单个文件review_diff-查看git差异或补丁review_directory-查看与glob模式匹配的多个文件review_git_staged-在提交之前审查当前阶段的更改
安装
# Clone the repo
git clone https://github.com/JasonBates/code-review-mcp.git
cd code-review-mcp
# Install with uv
uv sync
配置
设置环境变量:
# Required: Your API key
export OPENAI_API_KEY="sk-..."
# Optional: Custom endpoint (defaults to LaoZhang)
export OPENAI_BASE_URL="https://api.laozhang.ai/v1"
# Optional: Model to use (defaults to gpt-4o)
export REVIEW_MODEL="gpt-4o"
使用Claude代码
添加到您的Claude Code MCP配置中(~/.claude/claude_desktop_config.json):
{
"mcpServers": {
"code-review": {
"command": "uv",
"args": ["run", "--directory", "/path/to/code-review-mcp", "python", "main.py"],
"env": {
"OPENAI_API_KEY": "your-api-key-here",
"OPENAI_BASE_URL": "https://api.laozhang.ai/v1",
"REVIEW_MODEL": "gpt-4o"
}
}
}
}
然后在克劳德代码中:
Review src/auth.py for security issues
Review my staged changes before I commit
工具详细信息
review_file
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
path |
string | 必需 | 文件路径 |
focus |
string | “general” | 审查重点:一般、安全或性能 |
context |
string | null | 审阅者的其他上下文 |
review_diff
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
diff |
string | 必填 | Git差异文本 |
focus |
string | “常规” | 复习重点 |
context |
string | null | 其他上下文 |
review_directory
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
path |
string | 必需 | 目录路径 |
pattern |
string | “**/*.py” | 文件的全局模式 |
focus |
string | “常规” | 复习重点 |
max_files |
int | 10 | 要包含的最大文件数 |
review_git_staged
无参数-查看当前进行的git更改。
测试
# Test with MCP inspector
npx @modelcontextprotocol/inspector uv run python main.py
许可证
麻省理工学院