An AI-powered Model Context Protocol (MCP) server for Cursor that provides comprehensive code review functionality between commits and branches.
- 🔍 Code Review Between Commits: Compare any two commits and get detailed analysis
- 🌿 Branch Comparison: Review changes between branches (e.g., feature branch vs main)
- 🎯 Customizable Review Prompts: Use predefined templates or create custom review criteria
- 📊 Detailed Reports: Get comprehensive reports with file references and line numbers
- 🚨 Security Analysis: Detect potential security vulnerabilities
- ⚡ Performance Review: Identify performance bottlenecks and improvements
- 📋 Best Practices: Ensure code follows industry standards and conventions
- 🔧 Language Support: Works with multiple programming languages
- 🐛 Advanced Logical Bug Detection: Find null pointer access, infinite loops, type coercion issues
- 📝 JSDoc Analysis: Automatically suggest missing JSDoc and validate documentation completeness
- 🔄 Smart Context Analysis: Understand code context for better issue detection
- Clone and install dependencies:
git clone <repository-url>
cd ai-code-reviewer
npm install- Build the TypeScript code:
npm run build- Configure Cursor MCP:
Add this MCP server to your Cursor settings. In Cursor, go to
Settings>MCP Serversand add the following configuration:
{
"code-reviewer": {
"command": "node",
"args": ["<path-to-project>/dist/index.js"],
"cwd": "<path-to-project>",
"env": {}
}
}Compare code changes between two commits.
Parameters:
from_commit(required): Source commit hash or branch nameto_commit(optional): Target commit hash or branch name (default: HEAD)repository_path(optional): Path to git repository (default: current directory)review_prompt(optional): Custom review prompt or template namefile_extensions(optional): Array of file extensions to review (e.g., [".ts", ".js"])exclude_patterns(optional): Array of patterns to exclude (e.g., ["test", "spec"])
Example:
review_commits from_commit="abc123" to_commit="def456" review_prompt="security"
Compare code changes between two branches.
Parameters:
source_branch(required): Source branch nametarget_branch(optional): Target branch name (default: main/master)repository_path(optional): Path to git repositoryreview_prompt(optional): Custom review prompt or template namefile_extensions(optional): File extensions to reviewexclude_patterns(optional): Patterns to exclude
Example:
review_branches source_branch="feature/new-api" target_branch="main" review_prompt="comprehensive"
List all available review prompt templates.
Get a specific review template.
Parameters:
template_name(required): Name of the template
The system includes several predefined review templates:
- comprehensive: Complete code review covering all aspects
- security: Security-focused review for vulnerabilities
- performance: Performance impact analysis
- maintainability: Long-term maintainability assessment
- bestPractices: Coding standards and best practices
- bugPrevention: Logic errors and potential bugs
- logicalBugs: Advanced logical bug detection and runtime errors
- documentation: JSDoc and documentation compliance analysis
- api: API design and implementation review
- database: Database operations and design review
# Code Review Report
**Review Summary:**
- Files Changed: 5
- Lines Added: 127
- Lines Removed: 23
- Issues Found: 4
## Issues and Recommendations
### 1. CRITICAL: Potential hardcoded secret
**File:** `src/config.ts`
**Line:** 15
**Description:** Line 15 appears to contain a hardcoded secret or sensitive information.
**Suggestion:** Move sensitive information to environment variables or secure configuration.
**Code:**
```typescript
13 // Configuration settings
14+ const BASE_URL = 'https://api.example.com';
> 15+ const API_KEY = "***";
16+ const TIMEOUT = 5000;File: src/api.ts
Line: 28
Description: Object property access without null checking
Suggestion: Add null check or use optional chaining (?.)
Code:
25 function updateUser(user) {
26+ if (user) {
> 27+ user.profile.name = 'John';
28+ user.profile.email = email;
29+ }File: src/helpers.ts
Line: 15
Description: Function 'calculateTotal' lacks JSDoc documentation
Code:
14
> 15+ function calculateTotal(items, tax) {
16+ let total = 0;
17+ for (let item of items) {Suggestion: Add JSDoc:
/**
* Description of calculateTotal
* @param {*} items - Description
* @param {*} tax - Description
* @returns {*} Description
*/File: src/utils.ts
Line: 42
Description: Line 42 is 135 characters long, which exceeds the recommended 120 character limit.
Suggestion: Consider breaking this line into multiple lines for better readability.
This code review analyzed 5 files with 127 additions and 23 deletions.
Found 4 issues requiring attention:
- 🚨 1 critical issues that must be addressed
⚠️ 1 major issues that should be fixed- 💡 2 minor improvements suggested
Key Recommendations:
- Potential hardcoded secret (src/config.ts)
- Potential null/undefined access (src/api.ts)
- Missing JSDoc documentation (src/helpers.ts)
## Development
### Scripts
- `npm run build`: Build TypeScript to JavaScript
- `npm run dev`: Watch mode for development
- `npm run start`: Start the MCP server
- `npm run lint`: Run ESLint
- `npm run format`: Format code with Prettier
### Project Structure
src/ ├── index.ts # Main MCP server entry point ├── code-reviewer.ts # Core code review functionality ├── code-analyzer.ts # Static code analysis engine └── review-prompts.ts # Review prompt templates
## Customization
### Adding Custom Review Templates
You can add custom review templates by extending the `ReviewPromptManager`:
```typescript
// Add a new template
promptManager.addTemplate('custom', `
Focus on:
1. Custom criteria
2. Specific patterns
3. Domain-specific rules
`);
Add new analysis rules by extending the CodeAnalyzer class and implementing additional analysis methods.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
MIT License - see LICENSE file for details.