AI代码审查工具

基于Google Gemini CLI的AI代码审查与分析工具,支持30+编程语言,提供代码质量评估、架构验证和改进建议。

  • by iamrichardD
  • JavaScript
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 iamrichardD/claude-gemini-mcp-server

使用说明

Gemini代码审查员

一个通用的模型上下文协议(MCP)服务器,为以下对象提供AI驱动的代码审查和分析 任何编程语言 使用谷歌的Gemini CLI。非常适合那些希望在开发工作流程中直接获得智能代码反馈的开发人员。

🎯 目的

此MCP服务器充当您的AI代码审阅器,提供:

  • 全面的代码审查 具有严重性评级和可操作的反馈
  • 代码分析与解释 理解复杂逻辑
  • 改进建议 通过清晰的代码示例为您的特定目标量身定制
  • 架构验证 设计模式和可扩展性
  • 多语言支持 具有特定语言的最佳实践
  • 结构化输出 -清晰的解释和格式化的代码建议

🚀 快速开始

先决条件

  • Node.js v18+
  • Gemini CLI 已安装并配置
  • 克劳德代码CLI或克劳德桌面
  • 任何类Unix环境(Linux、macOS、WSL)

安装

# Install as project dependency
npm install --save-dev github:iamrichardd/claude-gemini-mcp-server

# Add MCP server to Claude CLI
claude mcp add -s project gemini-code-reviewer npx @iamrichardd/claude-gemini-mcp-server

# Initialize and approve the MCP server
claude init
# Choose option 1: "Use this and all future MCP servers in this project"

关于上下文文件的重要说明: 此套餐包括 GEMINI.md 和 CLAUDE.md 为其自身开发提供上下文的文件。为了防止这些文件干扰项目的上下文 postinstall 脚本将在安装时自动删除它们。这确保了Gemini和Claude CLI使用项目的特定上下文文件,而不是来自此服务器的文件。

验证安装

# Check if MCP server is registered and connected
claude mcp list
# Should show: gemini-code-reviewer ✓ connected

# Test basic functionality
claude "Use get_review_history"

📋 可用工具

工具 描述 最适合
gemini_code_review 全面的代码审查,包括评级和优先级 代码质量、错误检测、最佳实践
gemini_analyze_code 深度代码分析和解释 理解复杂代码,优化
gemini_suggest_improvements 通过代码示例提出具体的改进建议 重构、性能、可维护性
gemini_validate_architecture 架构和设计模式验证 系统设计、可扩展性、SOLID原则
gemini_propose_plan 为其他AI生成结构化的实施计划以供遵循 任务规划、工作流设计、AI协作
get_review_history 会话历史和回顾跟踪 项目概述、进度跟踪

🌍 支持的语言

自动检测到支持30多种语言:

网站开发

  • JavaScript、TypeScript、HTML、CSS、SCSS、Sass
  • React(JSX/TSX)、Vue.js、Angular

后端和系统

  • Python、Java、C++、C、C#、Go、Rust
  • PHP、ruby、node.js、kotlin、swift

数据与分析

  • R、 SQL、MATLAB、Python(NumPy/Pandas)

移动开发

  • Swift(iOS)、Kotlin(Android)、Dart(Flutter)

功能性和专业性

  • Haskell、Clojure、OCaml、Elixir、Erlang、Scala

脚本和配置

  • Shell、Bash、PowerShell、Perl、Lua、Vim脚本

金融与贸易

  • Pine Script(TradingView指标/策略)

语言检测是基于文件扩展名自动进行的。也支持手动规范。

💡 使用示例

全面的代码审查

claude "Use gemini_code_review with file_path './src/api.js' and context 'REST API endpoint' and focus_areas 'security'"
# Get detailed security review with specific recommendations

代码分析与解释

claude "Use gemini_analyze_code with file_path './algorithm.py' and analysis_type 'optimize'"

获取改进建议

claude "Use gemini_suggest_improvements with file_path './component.tsx' and improvement_goals 'performance'"
# Get specific performance improvements with code examples

架构验证

claude "Use gemini_validate_architecture with file_path './service.go' and validation_focus 'scalability'"

审核会话跟踪

claude "Use get_review_history"

人工智能协作规划

claude "Use gemini_propose_plan with prompt 'Create a user authentication system with JWT tokens'"
# Get a structured plan that Claude can then execute step by step

📝 代码建议格式

当Gemini识别出特定的代码改进时,您将收到:

结构化响应格式

💡 Gemini Improvement Suggestion - api.js (JavaScript)

**Rationale:**
This code uses nested callbacks which can lead to callback hell. Converting to async/await will improve readability and error handling.

**Suggested Code Change:**

Old Code:
```javascript
getData(callback) {
  db.query('SELECT * FROM users', (err, result) => {
    if (err) callback(err);
    else callback(null, result);
  });
}

新代码: ```javascript 异步获取数据链路){ 试试看{ const result=await-db.query(“选择*来自用户”); 返回结果; }catch(err){ 投掷错误; } } ```

特性

  • 清晰的解释:每项建议的详细理由
  • 格式化代码:正确突出显示新旧代码块
  • 特定语言:根据您的编程语言惯例量身定制
  • 复制粘贴就绪:格式良好的代码,易于实现

🔧 配置

Claude CLI MCP设置

MCP服务器使用项目级配置与Claude CLI集成:

# Add MCP server to your project
claude mcp add -s project gemini-code-reviewer npx @iamrichardd/claude-gemini-mcp-server

# Initialize and approve MCP servers
claude init
# Choose option 1 for persistent approval

手动配置(如果需要)

创建 .mcp.json 在项目根目录中:

生产使用(已发布包):

{
  "mcpServers": {
    "gemini-code-reviewer": {
      "command": "npx",
      "args": ["@iamrichardd/claude-gemini-mcp-server"],
      "transport": "stdio"
    }
  }
}

地方发展:

{
  "mcpServers": {
    "gemini-code-reviewer": {
      "command": "node",
      "args": ["server.js"],
      "transport": "stdio"
    }
  }
}

🔍 刀具参数

gemini_code_review

  • 文件路径 (必填):源代码文件的路径
  • 上下文 (可选):关于代码的其他上下文
  • 焦点_区域 (可选): syntax, logic, performance, best_practices, security, testing
  • 语言 (可选):编程语言(如果未指定,则自动检测)

gemini_analyze_code

  • 文件路径 (必填):源代码文件的路径
  • **为Gemini CLI提供AI提示**(可选): explain, optimize, debug, refactor, compare
  • 语言 (可选):编程语言(自动检测)

gemini_suggest_improvements

  • 文件路径 (必填):源代码文件的路径
  • 改进_目标 (可选): performance, readability, maintainability, scalability, security
  • 语言 (可选):编程语言(自动检测)

gemini_validate_architecture

  • 文件路径 (必填):源代码文件或目录的路径
  • 验证_焦点 (可选): architecture, design_patterns, scalability, testability, maintainability
  • 语言 (可选):编程语言(自动检测)

gemini_propose_plan

  • 提示 (必填):需要计划的高级用户请求或任务描述
  • 对话_历史 (可选):用于迭代细化计划的先前对话上下文

🛠️ 开发工作流程

推荐使用模式

  1. 实施 直接使用Claude code CLI编写代码
  2. 审查 使用 gemini_code_review 获取包含具体建议的全面反馈
  3. 分析 复杂路段 gemini_analyze_code
  4. 改进 基于 gemini_suggest_improvements 带有清晰代码示例的建议
  5. 验证 整体架构 gemini_validate_architecture
  6. 轨道 进度 get_review_history

标准工作流程

  1. 请求审查/建议 → 服务器使用Gemini分析代码
  2. 接收详细反馈 → 获取格式化代码建议的解释
  3. 审查和实施 → 检查建议并手动应用改进
  4. 复制/粘贴 → 使用提供的代码示例来实现更改
  5. 迭代 → 继续下一个建议或转到验证

与IDE集成

与以下设备无缝协作:

  • 克劳德代码CLI (初级整合)
  • 克劳德桌面 (替代设置)
  • WebStorm/IntelliJ (通过克劳德代码插件)
  • VS代码 (通过Claude Code集成)

🚨 故障排除

未找到MCP服务器

# Check installation
npm list | grep claude-gemini-mcp-server

# Reinstall if needed
npm install --save-dev github:iamrichardd/claude-gemini-mcp-server
claude mcp add -s project gemini-code-reviewer npx @iamrichardd/claude-gemini-mcp-server
claude init

MCP服务器连接挂起

如果命令如下 claude "Use get_review_history" 挂起或超时:

# For local development, use local server instead of npm package
claude mcp add -s project gemini-code-reviewer node server.js
claude init

# Verify server starts locally
node server.js
# Should show: "Gemini Code Review MCP Server (Security-Hardened v2.1.1) running on stdio"

# Check .mcp.json uses correct configuration
cat .mcp.json
# For local dev: should use "command": "node", "args": ["server.js"]
# For published package: should use "command": "npx", "args": ["@iamrichardd/claude-gemini-mcp-server"]

Gemini CLI问题

# Test Gemini CLI directly
gemini -p "test prompt"

# Verify authentication and availability
gemini --version

# Check if Gemini CLI is in PATH
which gemini

权限问题

# Ensure MCP server is approved
claude init
# Choose option 1: "Use this and all future MCP servers in this project"

# Check MCP server status
claude mcp list
# Should show: gemini-code-reviewer ✓ connected

二进制文件错误

# The server automatically detects and rejects binary files
# Error: "File appears to be binary, not a text-based source code file"
# Solution: Ensure you're pointing to text-based source code files only

语言检测问题

# Manually specify language if auto-detection fails
claude "Use gemini_code_review with file_path './script' and language 'Python'"

服务器执行问题

# Verify server starts correctly
npx @iamrichardd/claude-gemini-mcp-server
# Should show: "Gemini Code Review MCP Server (Security-Hardened v2.0.7) running on stdio"

# Check file permissions
chmod +x node_modules/@iamrichardd/claude-gemini-mcp-server/server.js

错误堆栈跟踪问题

# The server preserves complete error context for debugging
# Check logs for detailed error information including:
# - Original error message and stack trace
# - Operation context (file path, operation type)
# - Error cause chain for complete debugging context

🤝 贡献

欢迎投稿!请查看我们的 贡献指南 了解详情。

开发设置

git clone https://github.com/iamrichardd/claude-gemini-mcp-server.git
cd claude-gemini-mcp-server
npm install

# Configure MCP server for local development
claude mcp add -s project gemini-code-reviewer node server.js

# Initialize and approve the MCP server
claude init
# Choose option 1: "Use this and all future MCP servers in this project"

# Start development server
npm run dev

本地开发配置

对于本地开发,使用本地服务器而不是npm包:

{
  "mcpServers": {
    "gemini-code-reviewer": {
      "command": "node",
      "args": ["server.js"],
      "transport": "stdio"
    }
  }
}

📄 许可证

MIT许可证-请参阅 许可证 文件以获取详细信息。

🔗 相关工具

📊 用例

对于个人开发者

  • 代码质量保证:提交前自动审核
  • 学习手段:了解复杂的代码库和模式
  • 性能优化:确定瓶颈和改进
  • 最佳实践:针对特定语言的建议

对于团队

  • 代码审查自动化:预审筛选和反馈
  • 架构验证:确保设计一致性
  • 入职:帮助新团队成员理解代码
  • 文档:生成复杂逻辑的解释

对于特定域名

  • 网站开发:安全、性能、可访问性审查
  • 后端系统:可扩展性、可靠性、架构验证
  • 数据科学:算法优化,代码清晰
  • 移动开发:特定平台的最佳实践
  • 金融/贸易:Pine Script策略验证和优化

由谷歌Gemini AI提供技术支持 | 与Claude Code兼容 | 通用语言支持