MCP Code Review Agent
Personal Use Repository This is a personal repository for my own use. Feel free to use it if you find it helpful.
A sophisticated code review tool built with the Model Context Protocol (MCP) framework, designed to improve code quality through multiple AI-powered analysis strategies with distinct personas and expertise areas.
๐ Prerequisites
Codex CLI Login & Permissions
This tool requires Codex CLI to be installed and authenticated. You need to log in to Codex and have the necessary permissions to use the AI-powered analysis features.
Required Steps:
- Install Codex CLI (if not already installed)
- Login to Codex using your credentials
- Ensure proper permissions for AI analysis features
Codex CLI Resources:
Note: Without proper Codex CLI authentication, the AI-powered analysis strategies (Codex, Toxic Architect, Accessibility Expert) will not function. Only the static analysis strategy will be available.
๐ Quick Start
Installation
# Clone and build the tool locally (package not yet published to npm)
git clone https://github.com/lodado/MCP-Code-Review-Agent
cd MCP-Code-Review-Agent
npm install
npm run build
npm link
Basic Usage
# Get balanced AI review (Codex)
echo '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"codex_review","arguments":{"reviewType":"modified","analysisType":"codex"}}}' | node mcp-code-review-agent
# Get accessibility expert review
echo '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"codex_review","arguments":{"reviewType":"full","analysisType":"accessibility"}}}' | node mcp-code-review-agent
# Get brutally honest architect review (prepare for tough love!)
echo '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"codex_review","arguments":{"reviewType":"full","analysisType":"toxic-architect"}}}' | node mcp-code-review-agent
๐ค AI Review Agents & Personas
This tool features multiple AI agents, each with distinct personalities and expertise areas, providing comprehensive code review from different perspectives.
1. Codex Analysis (codex) - The Generalist
- Persona: Balanced AI code reviewer
- Expertise: Comprehensive analysis across all areas
- Style: Professional, thorough, and constructive
- Focus: Security, performance, architecture, and logic issues
- Best for: General code quality improvement
2. Toxic Architect (toxic-architect) - The Perfectionist
- Persona: Brutally honest senior architect with zero tolerance for poor code
- Expertise: SOLID principles, Clean Architecture, design patterns
- Style: Sarcastic, condescending, but technically accurate
- Focus: Architectural flaws, SOLID violations, design pattern misuse
- Best for: When you need tough love and architectural discipline
3. Web Accessibility Expert (accessibility) - The Inclusive Designer
- Persona: Senior Frontend Publisher with 10+ years of accessibility experience
- Expertise: WCAG compliance, semantic web, React accessibility
- Style: Professional, detail-oriented, user-focused
- Focus: Web accessibility, inclusive design, semantic HTML
- Best for: Frontend code, especially React/TypeScript components
4. Static Analyzer (static) - The Rule Enforcer
- Persona: Consistent, rule-based code analyzer
- Expertise: TypeScript patterns, code metrics, complexity analysis
- Style: Systematic, objective, fast
- Focus: Code metrics, complexity, basic patterns
- Best for: Quick feedback and consistent rule enforcement
5. Hybrid Analysis (hybrid) - The Team Player
- Persona: Combines multiple analysis approaches
- Expertise: Best of all worlds
- Style: Comprehensive and balanced
- Focus: Multiple perspectives in one review
- Best for: When you want comprehensive coverage
๐ Detailed Usage
Method 1: Direct Execution (Development)
# Get balanced AI review (Codex)
echo '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"codex_review","arguments":{"reviewType":"modified","analysisType":"codex"}}}' | node dist/index.js
# Get accessibility expert review
echo '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"codex_review","arguments":{"reviewType":"full","analysisType":"accessibility"}}}' | node dist/index.js
# Get brutally honest architect review (prepare for tough love!)
echo '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"codex_review","arguments":{"reviewType":"full","analysisType":"toxic-architect"}}}' | node dist/index.js
# Get quick static analysis
echo '{"jsonrpc":"2.0","id":4,"method":"tools/call","params":{"name":"codex_review","arguments":{"reviewType":"modified","analysisType":"static"}}}' | node dist/index.js
# Get comprehensive hybrid review
echo '{"jsonrpc":"2.0","id":5,"method":"tools/call","params":{"name":"codex_review","arguments":{"reviewType":"full","analysisType":"hybrid"}}}' | node dist/index.js
Method 2: Global Installation (Production)
After running npm link, you can use the tool globally from any directory:
# Install globally (run once after npm link)
npm link
# Now you can use it from anywhere:
# Get balanced AI review (Codex)
echo '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"codex_review","arguments":{"reviewType":"modified","analysisType":"codex"}}}' | mcp-code-review-agent
# Get accessibility expert review
echo '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"codex_review","arguments":{"reviewType":"full","analysisType":"accessibility"}}}' | mcp-code-review-agent
# Get brutally honest architect review
echo '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"codex_review","arguments":{"reviewType":"full","analysisType":"toxic-architect"}}}' | mcp-code-review-agent
# Get quick static analysis
echo '{"jsonrpc":"2.0","id":4,"method":"tools/call","params":{"name":"codex_review","arguments":{"reviewType":"modified","analysisType":"static"}}}' | mcp-code-review-agent
# Get comprehensive hybrid review
echo '{"jsonrpc":"2.0","id":5,"method":"tools/call","params":{"name":"codex_review","arguments":{"reviewType":"full","analysisType":"hybrid"}}}' | mcp-code-review-agent
Method 3: MCP Client Integration
If you're using an MCP client (like Cursor, Claude Desktop, etc.), the tool will be automatically available as codex_review with the following parameters:
{
"name": "codex_review",
"arguments": {
"repositoryPath": "/path/to/your/repo",
"reviewType": "modified",
"analysisType": "codex",
"includeSuggestions": true,
"outputFormat": "text",
"noEmoji": false
}
}
When to Use Each Agent
- Codex: Daily development, general code quality
- Toxic Architect: When you need architectural discipline and tough feedback
- Accessibility Expert: Frontend development, React components, user-facing code
- Static Analyzer: Quick feedback, CI/CD pipelines, consistent rule enforcement
- Hybrid: Comprehensive reviews, important milestones, final checks
Parameters
repositoryPath: Path to Git repository (default: current directory)reviewType: Type of files to review (full,staged,modified)analysisType: Analysis strategy (codex,static,hybrid,accessibility,toxic-architect)includeSuggestions: Include improvement suggestions (default:true)outputFormat: Output format (text,json)noEmoji: Disable emoji in output
Environment Variables
DEFAULT_REPO_PATH: Default repository pathDEFAULT_INCLUDE_SUGGESTIONS: Default suggestion inclusionDEFAULT_USE_CODEX: Default Codex usage (deprecated)DEFAULT_ANALYSIS_TYPE: Default analysis typeNO_EMOJI: Disable emoji globally
๐ค AI Provider & MCP Connection
Current AI Provider: OpenAI Codex
This tool currently uses OpenAI Codex as the primary AI provider for intelligent code analysis. The Codex integration provides sophisticated code understanding and review capabilities across multiple programming languages.
Note: The tool is designed to be provider-agnostic and can be extended to support other AI providers in the future.
MCP (Model Context Protocol) Connection
This tool is built as an MCP server that can be connected to MCP-compatible clients. Here's how to connect:
For MCP-Compatible IDEs/Editors
- Clone and build the tool locally (package not yet published to npm):
git clone https://github.com/lodado/MCP-Code-Review-Agent
cd MCP-Code-Review-Agent
npm install
npm run build
npm link
Future: Once published to npm, you'll be able to install with:
npm install -g mcp-code-review-agent
- Configure your MCP client (e.g., codex, Claude Desktop):
{
"mcpServers": {
"code-review-agent": {
"command": "mcp-code-review-agent",
"args": []
}
}
}
- Use the tool through your MCP client's interface
โ ๏ธ Cursor IDE Limitation
Important: Due to permission restrictions in Cursor IDE, this MCP tool may not work properly when connected through Cursor's MCP integration. The tool requires file system access and Git operations that may be restricted by Cursor's security model.
Workaround: Use the tool directly via command line or through other MCP-compatible clients that have appropriate permissions.
๐ Key Capabilities
- Multi-Persona Reviews: Get feedback from different AI personalities and expertise areas
- Parallel Processing: Multiple files analyzed concurrently using
p-limit - Path Security: Safe path validation preventing directory traversal attacks
- File Filtering: Intelligent filtering based on file type, size, and complexity
- Git Integration: Seamless integration with Git repositories
- Multiple Output Formats: Text and JSON output support
- Configurable Analysis: Customizable analysis parameters and limits
- Personal Code Quality Journey: Continuous improvement through AI-powered feedback
๐ฏ Purpose & Goals
This project was created to explore the potential of AI-powered code review using different specialized personas. The goal is to demonstrate how various AI agents with distinct personalities and expertise can provide comprehensive code quality improvements from multiple perspectives.
Why This Project Exists
- Personal Code Quality Improvement: Use MCP agents to continuously improve code quality through automated reviews
- Multi-Perspective Analysis: Leverage different AI personas (senior architect, accessibility expert, etc.) to get diverse feedback
- Learning Tool: Understand how different AI personalities approach code review and what insights they provide
- MCP Framework Exploration: Experiment with the Model Context Protocol for building AI-powered development tools
The Vision
Imagine having a team of expert code reviewers available 24/7, each with their own specialty:
- A brutally honest senior architect who catches SOLID violations and architectural flaws
- A web accessibility expert who ensures inclusive design
- An AI-powered generalist who provides comprehensive analysis
- A rule-based analyzer for consistent, fast feedback
This tool makes that vision a reality through MCP agents with distinct personas and expertise areas.
๐๏ธ Architecture Overview
This project implements a Clean Architecture pattern with clear separation of concerns. The architecture was designed based on comprehensive code review feedback from MCP agents - I had no involvement in the architectural decisions!
Architecture Layers
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Presentation Layer โ โ CLI output, JSON reports
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Application Layer โ โ Use Case orchestration
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Domain Layer โ โ Business logic, port interfaces
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Infrastructure Layer โ โ Git, FS, AI Provider implementations
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
The architecture follows Clean Architecture principles with clear separation of concerns, making it easy to add new analysis strategies and maintain the codebase.
๐ Project Structure
src/
โโโ domain/ # Domain Layer
โ โโโ ports.ts # Port interfaces (contracts)
โ โโโ entities.ts # Business entities and logic
โโโ application/ # Application Layer
โ โโโ CodeReviewUseCase.ts # Main business orchestration
โ โโโ AnalysisOrchestrator.ts # Analysis strategy coordination
โโโ infrastructure/ # Infrastructure Layer
โ โโโ git/
โ โ โโโ NodeGitClient.ts # Git operations adapter
โ โโโ filesystem/
โ โ โโโ NodeFileSystem.ts # File system operations adapter
โ โโโ ai/
โ โ โโโ CodexClient.ts # AI provider adapter
โ โโโ path/
โ โโโ SafePathPolicy.ts # Path security validation
โโโ presentation/ # Presentation Layer
โ โโโ CliReporter.ts # Text output formatter
โ โโโ JsonReporter.ts # JSON output formatter
โโโ strategies/ # Analysis Strategies
โ โโโ CodeAnalysisStrategy.ts # Abstract base strategy
โ โโโ CodexAnalysisStrategy.ts # AI-powered analysis
โ โโโ WebAccessibilityAnalysisStrategy.ts # Accessibility-focused
โ โโโ ToxicArchitectAnalysisStrategy.ts # Architecture-focused
โ โโโ TypeScriptStaticAnalysisStrategy.ts # Rule-based analysis
โ โโโ AnalysisStrategyFactory.ts # Strategy factory
โโโ composition/ # Dependency Injection
โ โโโ container.ts # DI container and wiring
โโโ config/ # Configuration
โ โโโ analysisConfig.ts # Analysis settings
โโโ tools/ # MCP Tools
โโโ CodexReviewTool.ts # Main MCP tool (thin wrapper)
๐๏ธ Architecture Details
Domain Layer
The domain layer contains the core business logic and defines the contracts (ports) that external dependencies must implement.
Key Components:
ports.ts: Interface definitions for all external dependenciesentities.ts: Business entities with domain logic
Application Layer
The application layer orchestrates the business logic and coordinates between different services.
Key Components:
CodeReviewUseCase: Main orchestration logicAnalysisOrchestrator: Manages analysis strategy selection and execution
Infrastructure Layer
The infrastructure layer provides concrete implementations of the domain interfaces.
Key Components:
NodeGitClient: Git operations using Node.js child processesNodeFileSystem: File system operations using Node.js fs moduleCodexClient: OpenAI Codex SDK integrationSafePathPolicy: Security-focused path validation
Presentation Layer
The presentation layer handles output formatting and user interface concerns.
Key Components:
CliReporter: Human-readable text outputJsonReporter: Machine-readable JSON output
๐ง Configuration
Analysis Configuration
export const defaultAnalysisConfig: AnalysisConfig = {
maxFileSize: 50 * 1024, // 50KB
maxLines: 2500, // Maximum lines per file
maxFunctions: 50, // Maximum functions per file
maxClasses: 10, // Maximum classes per file
concurrency: 3, // Parallel processing limit
supportedExtensions: [".ts", ".tsx"],
excludedPatterns: [
"\\.d\\.ts$",
"\\.(test|spec)\\.tsx?$",
"/node_modules/",
"/dist/",
"/build/",
],
};
๐งช Testing
# Build the project
npm run build
# Test with different analysis strategies
npm test
๐ Security Features
- Path Traversal Protection: Prevents directory traversal attacks
- File Size Limits: Prevents memory exhaustion from large files
- Input Validation: Comprehensive input sanitization and validation
- Safe Git Operations: Secure Git command execution
๐ Performance Features
- Parallel Processing: Concurrent file analysis using
p-limit - Intelligent Filtering: Skip unsuitable files early
- Memory Management: Efficient file size and complexity checks
- Caching: Dependency injection container with instance caching
๐ Development
Adding New Analysis Strategies
- Create a new strategy class extending
CodeAnalysisStrategy - Implement the required abstract methods
- Register the strategy in
AnalysisStrategyFactory - Update the schema validation
Adding New Output Formats
- Create a new reporter implementing
Reporterinterface - Register the reporter in the dependency container
- Update the tool's output format handling
๐ค Contributing
This project follows clean architecture principles and SOLID design patterns. When contributing:
- Maintain separation of concerns
- Use dependency injection
- Write tests for new features
- Follow the existing code structure
๐ License
MIT License - see LICENSE file for details.
---
Note: This architecture was designed based on comprehensive code review feedback from MCP agents. The architectural decisions, design patterns, and code structure were all determined by the AI review process - I had no involvement in the architectural design!






