Kilocode Review MCP Integration Guide
Describes how to integrate an MCP server that runs automated, context-aware code reviews with two-phase validation and actionable fixes.
What this file does
Describes how to integrate an MCP server that runs automated, context-aware code reviews with two-phase validation and actionable fixes.
When to use it
- You want an automated code review step that enforces project-specific constraints
- You need a self-correction workflow for Claude Code agents
- You are building MCP servers that produce structured review output files
- You want to offload code review to background processing with multiple model validations
Assumes this stack
Kilocode Review MCP Integration Guide
Overview
The kilocode-review MCP server provides an automated code review system that understands project-specific constraints and applies contextual fixes. It integrates with Claude Code through the MCP (Model Context Protocol) to enable self-correction workflows.
Key Features
- Context-Aware Reviews: Understands project-specific patterns and constraints
- Actionable Fixes: Provides pre-validated fixes that are safe to apply
- Asynchronous Processing: Reviews run in background, allowing other work to continue
- Two-Phase Validation: Uses multiple models for comprehensive analysis
Architecture
Claude Code Agent
↓
mcp_kilocode_review.py (MCP Server)
↓
kilocode CLI tool (review-contextual command)
↓
Two-Phase Review Process:
- Phase 1: O3 model with context analysis
- Phase 2: Gemini 2.5 Pro validation
↓
Structured Output Files:
- review_summary.md
- actionable_fixes.md
- incompatible_suggestions.md
- context_applied.md
Setup
1. MCP Configuration
The server is already configured in ~/.claude/claude_code/.mcp.json:
"kilocode-review": {
"command": "uv",
"args": [
"--directory",
"/home/graham/workspace/experiments/cc_executor",
"run",
"--script",
"src/cc_executor/servers/mcp_kilocode_review.py"
],
"env": {
"PYTHONPATH": "/home/graham/workspace/experiments/cc_executor/src",
"UV_PROJECT_ROOT": "/home/graham/workspace/experiments/cc_executor"
}
}
2. Available Tools
The server provides two MCP tools:
mcp__kilocode-review__start_review: Initiates an asynchronous reviewmcp__kilocode-review__get_review_results: Retrieves completed review results
Usage Workflow
Step 1: Start Review
# Agent calls start_review with files to review
result = await mcp__kilocode-review__start_review(
files="src/server1.py src/server2.py",
focus="security", # Optional: security, performance, maintainability, architecture
severity="medium" # Optional: low, medium, high, critical
)
# Returns:
{
"success": true,
"review_id": "docs/code_review/20250117_120000_abc123",
"message": "Review started successfully..."
}
Step 2: Wait for Completion
The review process typically takes 2-3 minutes. The agent should wait before checking results.
Step 3: Get Results
# Agent retrieves results using the review_id
results = await mcp__kilocode-review__get_review_results(
review_id="docs/code_review/20250117_120000_abc123"
)
# Returns:
{
"success": true,
"results": {
"summary": "Review summary...",
"actionable_fixes": "Markdown with specific fixes...",
"incompatible_suggestions": "Standard fixes not applicable...",
"context_applied": "Project constraints considered..."
}
}
Step 4: Apply Fixes
The agent parses actionable_fixes and applies changes using Edit/MultiEdit tools.
Context Management
The system uses multiple context sources:
- Auto-detection: First .md file with "context" in name
- Project Context:
.kilocode/CONTEXT.md(fallback) - Inline Context: Via
--contextparameter - Context File: Via
--context-fileparameter
Example Context File
# CC Executor MCP Context
## Project Type
MCP servers using FastMCP framework for Claude Code integration
## Critical Constraints
1. **FastMCP Return Values**: All @mcp.tool functions MUST return JSON strings
2. **Lazy Loading**: Heavy resources (models, connections) load on first use
3. **Thread Safety**: Use locks for shared state in concurrent environments
## Patterns to Follow
- Single-file MCP servers with embedded usage examples
- Graceful error handling with MCP logger integration
- Double-checked locking for singleton resources
Integration with Claude Code
Mandatory Self-Correction Prompt
Add this to your task instructions:
### **Mandatory Final Step: Self-Correction and Verification**
Once you believe you have completed the primary coding task, you **MUST** perform a final quality check using the `kilocode-review` tool. This is a non-negotiable step to ensure your work adheres to all project constraints.
Follow this procedure exactly:
1. **Identify Changed Files**: List all files you created or modified
2. **Initiate Review**: Call `mcp__kilocode-review__start_review` with file paths
3. **Wait for Completion**: Wait 2-3 minutes for review to complete
4. **Retrieve Results**: Call `mcp__kilocode-review__get_review_results`
5. **Apply Fixes**: If `actionable_fixes` contains suggestions, apply them exactly
6. **Conclude**: Confirm the task is complete and has passed review
Benefits
- Consistency: Ensures all code follows project patterns
- Quality: Catches common mistakes before human review
- Learning: Incompatible suggestions teach project-specific rules
- Efficiency: Automated fixes save manual correction time
Troubleshooting
Review Not Starting
- Check if kilocode CLI is installed and accessible
- Verify file paths are correct and files exist
- Check server logs for detailed error messages
Results Not Found
- Ensure sufficient wait time (2-3 minutes minimum)
- Verify review_id matches the one returned by start_review
- Check if review output directory exists
Fixes Not Applying
- Parse markdown carefully to extract file paths and changes
- Ensure exact string matching when using Edit tool
- Use MultiEdit for multiple changes to same file
Advanced Features
Focus Areas
security: SQL injection, XSS, authentication issuesperformance: N+1 queries, inefficient algorithmsmaintainability: Code complexity, duplicationarchitecture: Design patterns, modularity
Severity Levels
low: Style and minor improvementsmedium: Important but not critical issueshigh: Significant problems affecting functionalitycritical: Security vulnerabilities or major bugs
Best Practices
- Always Review Before Committing: Make it part of your workflow
- Use Appropriate Focus: Target specific concerns when needed
- Apply All Actionable Fixes: They're pre-validated for your project
- Learn from Incompatible Suggestions: Understand why they don't apply
- Maintain Context Files: Keep project constraints documented
Example Implementation
See examples/demo_kilocode_review.py for a complete demonstration of the workflow.
Future Enhancements
- Streaming Progress: Real-time updates during review
- Batch Reviews: Review multiple PRs or branches
- Custom Rules: Project-specific linting rules
- Integration Tests: Verify fixes don't break functionality
What's inside
9 sections covering architecture, setup, usage workflow, context management, troubleshooting, and best practices, plus 4 code examples and 2 tool definitions.
Change this for your project
- Replace
"/home/graham/workspace/experiments/cc_executor"with your project's directory path - Replace
"PYTHONPATH": "/home/graham/workspace/experiments/cc_executor/src"with your source root - Replace
"UV_PROJECT_ROOT": "/home/graham/workspace/experiments/cc_executor"with your project root - Replace
grahama1970/cc_executorwith your own repository name
Where it goes
A standard operating procedure. Keep where the team or agent running the process will find it.
Worth borrowing
- Two-phase validation using different models (O3 then Gemini 2.5 Pro) to catch more issues
- Mandatory self-correction prompt that forces agents to run review before concluding a task
- Structured output files (review_summary.md, actionable_fixes.md, incompatible_suggestions.md) for programmatic fix application
Related Documents
Comprehensive AI Assistant Tools Reference
Lists 80+ tools with MCP server associations, bulk support, parallel capability, resource impact, and execution type for AI agent workflows.
iOS Deployment Guide
Walks through setting up an iOS development environment, building a Tauri app for iOS, and publishing to the App Store or alternative channels.
How to Add Resources to Your FastMCP Server
Teaches how to add static and dynamic MCP resources to a FastMCP server, with six ready-to-copy examples for a GitHub crawler.
Continue.dev MCP Integration Setup Guide
Walks through configuring Continue.dev to connect an MCP server for spatial transcriptomics tasks, with local and remote setup options.