クロード・コードレビュー MCP
OpenAI、Google、Anthropicモデルを用いたコードレビュー機能を提供するMCP(Model Context Protocol)サーバー。Claude Code、Claude Desktop、Cursor、Windsurfなど、あらゆるMCPクライアントで利用可能な、コードレビューのための「セカンドオピニオン」ツールとして機能します。
特徴
- マルチプロバイダーサポート:コードレビューにOpenAI、GoogleのGemini、AnthropicのClaudeモデルを活用
- 2つのレビュータイプ: 構造化されたレビュー(分類されたフィードバック付き)または自由形式の物語レビューから選択します
- コンテキスト認識: プロジェクト構造、関連ファイル、コミット メッセージ、依存関係を含めて、より関連性の高いレビューを実現します。
- インテリジェントなコード処理: プログラミング言語を自動的に検出し、大きなファイルを処理し、出力を適切にフォーマットします。
- 堅牢なエラー処理: API障害の再試行ロジックと正常なエラー回復機能が含まれています
- MCP 互換: すべての MCP クライアント (Claude Code、Claude Desktop、Cursor、Windsurf) で動作します
- 簡単なセットアップ:環境変数による簡単な設定
インストール
グローバルインストール
npm install -g claude-code-review-mcp
npx での使用(インストール不要)
# Set environment variables separately
export OPENAI_API_KEY=<key>
npx -y claude-code-review-mcp
# Or use inline environment setting
OPENAI_API_KEY=<key> npx -y claude-code-review-mcp
# Or with Google API key
GOOGLE_API_KEY=<key> npx -y claude-code-review-mcp
# Or with Anthropic API key
ANTHROPIC_API_KEY=<key> npx -y claude-code-review-mcp
# Or use multiple API keys for more model options
OPENAI_API_KEY=<key> GOOGLE_API_KEY=<key> ANTHROPIC_API_KEY=<key> npx -y claude-code-review-mcp
構成
サーバーには、次の API キーの少なくとも 1 つが必要です。
OPENAI_API_KEY
: OpenAI API キーGOOGLE_API_KEY
: Google Gemini APIキーANTHROPIC_API_KEY
: Anthropic APIキー
オプション構成:
PORT
: サーバーポート (デフォルト: 動的 - 利用可能なポートが選択されます)HOST
: サーバーホスト(デフォルト: 127.0.0.1)LOG_LEVEL
: ログレベル (0=DEBUG、1=INFO、2=WARN、3=ERROR、デフォルト: 1)
利用可能なモデル
OpenAI モデル(OPENAI_API_KEY が必要)
gpt-4.1
- OpenAI GPT-4.1o4-mini
- OpenAI O4 Minio3-mini
- OpenAI O3 Mini
Google モデル(GOOGLE_API_KEY が必要です)
gemini-2.5-pro-preview-05-06
- Google Gemini 2.5 Progemini-2.5-flash-preview-04-17
- Google Gemini 2.5 Flash
人間モデル(ANTHROPIC_API_KEY が必要)
claude-3-opus-20240229
- アントロピック・クロード 3 作品claude-3-sonnet-20240229
- クロードのソネット3claude-3-haiku-20240307
- 人類学的なクロード3の俳句
利用可能なツール
MCP サーバーは次の 3 つのツールを提供します。
1. レビューコード構造化
次のセクションでは、詳細かつ構造化されたコードレビューを提供します。
- 全体概要
- コードの品質(長所と短所)
- バグ(重大度と修正案を含む)
- 改善提案
- セキュリティ上の問題(ある場合)
2. レビューコードフリーフォーム
一般的な印象や会話形式のフィードバックに適した、自由形式のテキスト形式で物語的なコードレビューを提供します。
3. リストモデル
提供された API キーに基づいて、モデル ID や人間が判読できる名前など、利用可能なすべてのモデルを一覧表示します。
Claude Codeとの統合
この MCP サーバーを Claude Code に追加するには:
# Use environment variables properly (recommended approach)
claude mcp add code-review -s user -e OPENAI_API_KEY=<key> -e GOOGLE_API_KEY=<key> -e ANTHROPIC_API_KEY=<key> -- npx -y claude-code-review-mcp
# Alternative: Export the variables before adding the MCP
export OPENAI_API_KEY=<key>
export GOOGLE_API_KEY=<key>
export ANTHROPIC_API_KEY=<key>
claude mcp add code-review -s user -- npx -y claude-code-review-mcp
.claude/commands/review-with.md
にファイルを作成して、カスタム スラッシュ コマンドを作成することもできます。
I'll review your code using alternative LLM models. Model to use: $ARGUMENTS
Claude Codeは、MCPサーバーとのやり取りを容易にするカスタムスラッシュコマンドをサポートしています。これらのコマンドをプロジェクト内の.claude/commands/
ディレクトリに作成することで、強力なコードレビューワークフローを実現できます。
基本設定
まず、コマンド ディレクトリが存在しない場合は作成します。
mkdir -p .claude/commands
モデルリストコマンド
利用可能なモデルを一覧表示するコマンドを作成します。
# Create the list-review-models.md file
cat > .claude/commands/list-review-models.md << 'EOF'
I'll check which alternative code review models are available through our MCP server.
First, I'll use the MCP server to list all available models for code review.
After that, I'll present the models in a clear table format with:
- Model ID (what you'll use when requesting a review)
- Provider (OpenAI or Google)
- Description (size and capabilities)
- Speed (relative performance)
This will help you choose the right model for your code review needs.
EOF
基本的なコードレビューコマンド
モデル名を受け入れる簡単なレビュー コマンドを作成します。
# Create the review-with.md file
cat > .claude/commands/review-with.md << 'EOF'
I'll review the code I've just worked on using an alternative LLM model to provide a second opinion.
First, I'll identify the code changes or file you want reviewed. If you don't specify a file, I'll look at recent changes.
Then, I'll send this code to be reviewed by the specified model through our MCP server.
Available models (run /project:list-review-models to see all options):
- OpenAI models (if configured): "gpt-4.1", "o4-mini", "o3-mini"
- Google models (if configured): "gemini-2.5-pro-preview-05-06", "gemini-2.5-flash-preview-04-17"
Model to use (leave blank for default): $ARGUMENTS
EOF
構造化レビューコマンド
構造化レビュー専用のコマンドを作成します。
# Create the structured-review.md file
cat > .claude/commands/structured-review.md << 'EOF'
I'll perform a structured code review using an alternative LLM model.
This review will be organized into clear sections:
1. Overall summary
2. Code quality assessment (strengths and weaknesses)
3. Potential bugs with severity ratings (Low/Medium/High)
4. Specific improvement suggestions
5. Security considerations (if applicable)
If you don't specify a model, I'll use the default available model.
Model to use (optional): $ARGUMENTS
EOF
フリーフォームレビューコマンド
物語形式のレビュー用のコマンドを作成します。
# Create the freeform-review.md file
cat > .claude/commands/freeform-review.md << 'EOF'
I'll provide a conversational, narrative-style code review using an alternative LLM model.
This will be a more holistic assessment of your code with flowing paragraphs rather than structured categories. This style works well for:
- General impressions
- High-level feedback
- More nuanced commentary on code style and approach
If you don't specify a model, I'll use the default available model.
Model to use (optional): $ARGUMENTS
EOF
特定のファイルを確認するコマンド
特定のファイルを確認するコマンドを作成します。
# Create the review-file.md file
cat > .claude/commands/review-file.md << 'EOF'
I'll review a specific file using an alternative LLM model.
Please provide the file path to review and optionally the model to use.
Format: [file_path] [model_name]
For example:
- "src/utils.js gemini-2.5-pro-preview-05-06" - Reviews utils.js with Gemini Pro
- "lib/auth.ts" - Reviews auth.ts with the default model
Input: $ARGUMENTS
EOF
フォーカス固有のレビューコマンド
特殊なレビュー用のコマンドを作成します。
# Create security review command
cat > .claude/commands/security-review.md << 'EOF'
I'll perform a security-focused code review using an alternative LLM model.
This review will specifically examine:
- Potential security vulnerabilities
- Input validation issues
- Authentication/authorization flaws
- Data protection concerns
- Injection vulnerabilities
- Secure coding best practices
If you don't specify a model, I'll use a model recommended for security analysis.
Model to use (optional): $ARGUMENTS
EOF
# Create performance review command
cat > .claude/commands/performance-review.md << 'EOF'
I'll perform a performance-focused code review using an alternative LLM model.
This review will specifically examine:
- Algorithm efficiency
- Memory usage
- Unnecessary computations
- Loop optimizations
- Data structure choices
- Caching opportunities
- Async/parallel processing considerations
If you don't specify a model, I'll use a model that's good at performance analysis.
Model to use (optional): $ARGUMENTS
EOF
包括的プロジェクトレビューコマンド
完全なプロジェクト コンテキストでコードをレビューするためのコマンドを作成します。
# Create the project-review.md file
cat > .claude/commands/project-review.md << 'EOF'
I'll perform a comprehensive code review with full project context using an alternative LLM model.
This review will:
1. Analyze the code structure and organization
2. Consider related files and dependencies
3. Evaluate consistency with project patterns
4. Assess integration with existing components
5. Check alignment with project architecture
I'll gather project context, including directory structure and related files, to ensure a thorough, context-aware review.
Format: [file_to_review] [model_name]
Example: "src/components/Button.jsx gemini-2.5-pro-preview-05-06"
Input: $ARGUMENTS
EOF
前後レビューコマンド
コードの変更を比較するコマンドを作成します。
# Create the diff-review.md file
cat > .claude/commands/diff-review.md << 'EOF'
I'll review the changes you've made to a file using an alternative LLM model.
This will:
1. Identify what was changed between versions
2. Evaluate if the changes address the intended purpose
3. Check for any new issues introduced
4. Suggest potential improvements to the changes
I'll need to know which file to examine. If you've been working on a file with Claude Code, I'll automatically find the changes.
Model to use (optional): $ARGUMENTS
EOF
カスタムスラッシュコマンドの使用
これらのコマンドを作成したら、Claude Codeで/project:
に続けてコマンド名を入力することで使用できます。例:
/project:list-review-models
/project:review-with gemini-2.5-pro-preview-05-06
/project:structured-review o4-mini
/project:security-review
/project:review-file src/utils.js gemini-2.5-flash-preview-04-17
カスタムコマンドのヒント
- コマンド検出: Claude Code で
/project:
と入力すると、使用可能なコマンドのリストが表示されます。 - デフォルトモデル: モデルを指定しない場合、コマンドはデフォルトモデル(通常はo4-mini)を使用します。
- 複数のレビュー: 異なるモデルでレビューを実行することで、複数の視点を得ることができます。
- プロジェクトコンテキスト: 最も関連性の高いレビューには、プロジェクトコンテキストを含むコマンドを使用します。
- 特殊なフォーカス: セキュリティ、パフォーマンスなどについて特に懸念がある場合は、フォーカス固有のコマンドを使用します。
ワークフローの例
典型的なワークフローは次のようになります。
- Claude Code と一緒にコードに取り組む
- 利用可能なオプションを確認するには
/project:list-review-models
を実行してください。 - Googleのモデルから構造化されたレビューを取得するには
/project:structured-review gemini-2.5-pro-preview-05-06
実行します。 - クロードの提案と比較する
- 両方の視点に基づいて改善を行う
- 変更を確認するには
/project:diff-review
実行します。
これらのカスタム コマンドにより、Claude Code と claude-code-review-mcp サーバー間のスムーズな統合が可能になり、コードに対する貴重な「セカンド オピニオン」が提供されます。
使用例
MCPサーバーの起動
# Start with OpenAI API key (using exports, recommended)
export OPENAI_API_KEY=<key>
npx -y claude-code-review-mcp
# Or with inline environment variables
OPENAI_API_KEY=<key> npx -y claude-code-review-mcp
# Start with Google Gemini API key
export GOOGLE_API_KEY=<key>
npx -y claude-code-review-mcp
# Start with Anthropic Claude API key
export ANTHROPIC_API_KEY=<key>
npx -y claude-code-review-mcp
# Use multiple API keys for more model options
export OPENAI_API_KEY=<key>
export GOOGLE_API_KEY=<key>
export ANTHROPIC_API_KEY=<key>
npx -y claude-code-review-mcp
# Use custom port and host
export OPENAI_API_KEY=<key>
export PORT=8080
export HOST=0.0.0.0
npx -y claude-code-review-mcp
MCPクライアントでの使用
サーバーが起動したら、Claude Code、Claude Desktop、Cursor、WindsurfなどのMCPクライアントからサーバーのURLを使用して接続できます。サーバーの起動ログには、実際のURLとポート番号が表示されます(ポートの競合を避けるため、動的に割り当てられます)。
入力スキーマ
すべてのレビュー ツールは次の入力を受け入れます。
{
code: string; // Required: The code to review
filename?: string; // Optional: The filename with extension
language?: string; // Optional: Programming language
model: string; // Required: Model ID to use for review
projectContext?: { // Optional: Additional context
projectStructure?: string; // Directory structure
relatedFiles?: Array<{ // Related code files
name: string; // Filename with path
language?: string; // File language
content: string; // File content
}>;
commitMessage?: string; // Purpose of changes
dependencies?: Record<string, string>; // Project dependencies
}
}
出力スキーマ
構造化されたレビュー出力
{
review?: { // Present on success
summary: string; // Overall assessment
quality: {
strengths: string[]; // Good aspects
weaknesses: string[]; // Areas for improvement
};
bugs: Array<{
description: string; // Issue description
severity: "Low" | "Medium" | "High"; // Impact level
suggestion: string; // How to fix
}>;
improvements: string[]; // Enhancement suggestions
securityIssues?: string[]; // Security concerns if any
};
modelUsed: string; // Human-readable model name
error?: string; // Present on error
availableModels?: Record<string, string>; // Present on error or listModels
}
フリーフォームレビュー出力
{
reviewText?: string; // Present on success
modelUsed: string; // Human-readable model name
error?: string; // Present on error
availableModels?: Record<string, string>; // Present on error or listModels
}
モデル出力のリスト
{
availableModels: Record<string, string>; // Model ID to name mapping
modelUsed: string; // Always "None" for this tool
}
MCPクライアント統合
クロード・コード
- MCP サーバーを追加します。
claude mcp add code-review -s user npx -y claude-code-review-mcp
- クロードコードでの使用:
/code-review:reviewCodeStructured --model o4-mini
クロードデスクトップ
Claude Desktop 設定で、MCP を次のように構成します。
"claude-code-review-mcp": {
"command": "npx",
"args": ["-y", "claude-code-review-mcp"],
"env": {
"OPENAI_API_KEY": "your-openai-key",
"GOOGLE_API_KEY": "your-google-key",
"ANTHROPIC_API_KEY": "your-anthropic-key"
}
}
サーバーは、Claude Desktop を含むすべての MCP クライアントとの完全な互換性を確保するために、高度な JSON 出力サニタイズを使用します。
カーソルとウィンドサーフィン
同じコマンドと環境変数を使用して、クライアントの特定の MCP 構成ガイドラインに従います。
トラブルシューティング
APIキーの問題
- 「モデル X は利用できません」 : モデルに適切な API キーを指定していることを確認してください。
- API キーが指定されていません: OPENAI_API_KEY、GOOGLE_API_KEY、または ANTHROPIC_API_KEY の少なくとも 1 つを指定する必要があります。
- 推奨モデル: 要求されたモデルが利用できない場合は、サーバーが代替モデルを提案します。
レート制限とAPIエラー
- レート制限または API エラーが発生した場合は、エラー メッセージに問題が示されます。
- 1 つのプロバイダーで問題が発生している場合は、別のモデルの使用を検討してください。
セキュリティに関する考慮事項
- APIキーは記録も公開もされません
- コードの内容はプライバシー保護のため最小限に記録されます
- セキュリティ面を減らすために依存関係は最小限に抑えられています
- リクエスト処理には入力検証とサニタイズが含まれる
- エラーメッセージは機密情報の漏洩を防ぐように設計されています
互換性
- Node.js 18.0.0以降が必要です
- Linux、macOS、Windows で動作します(必要に応じて WSL 経由)
- すべての MCP クライアント (Claude Code、Claude Desktop、Cursor、Windsurf) と互換性があります
- 大規模なコードファイルとプロジェクトコンテキストを適切に処理
- 一時的な API 障害に対する自動再試行メカニズム
発達
# Install dependencies
npm install
# Start in development mode
npm run dev
# Build for production
npm run build
# Start in production mode
npm run start
ライセンス
マサチューセッツ工科大学
寄稿者