loading…
Search for a command to run...
loading…
An AI-powered server for code analysis, requirements validation, and automated fix proposals with human-in-the-loop confirmation. It supports multiple LLM provi
An AI-powered server for code analysis, requirements validation, and automated fix proposals with human-in-the-loop confirmation. It supports multiple LLM providers and ensures safe file modifications through automatic backups and path validation.
A powerful second-layer LLM MCP server that refines and reviews code using AI. Perfect for improving AI-generated code or enhancing human-written code through natural language feedback.
This is an MCP (Model Context Protocol) server that adds code refinement and review capabilities to any MCP client like Claude Desktop. It acts as a "second layer" AI that specializes in code improvement, working alongside your primary AI assistant.
Use it to:
git clone https://github.com/yourusername/mcp_code_review.git
cd mcp_code_review
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
pip install -r requirements.txt
Create a .env file from the example:
cp .env.example .env
Edit .env and add at least ONE API key:
# Recommended: Google Gemini (free tier available)
GOOGLE_API_KEY=your-gemini-api-key-here
# Alternative: Anthropic Claude
ANTHROPIC_API_KEY=your-anthropic-api-key-here
# Alternative: OpenAI
OPENAI_API_KEY=your-openai-api-key-here
Get API keys from:
Edit your Claude Desktop config file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
Add the server configuration:
{
"mcpServers": {
"code-refiner": {
"command": "python",
"args": ["/absolute/path/to/mcp_code_review/mcp_server.py"],
"env": {
"GOOGLE_API_KEY": "your-gemini-api-key"
}
}
}
}
Important: Replace /absolute/path/to/mcp_code_review/ with the actual path on your system.
Restart Claude Desktop to load the server.
Once configured, just talk to Claude naturally in Claude Desktop. The tools are automatically available!
Improve existing code with natural language instructions:
You: "Refine ./my_script.py to make it more logical and add error handling"
Claude will:
refine_code_tool with your requestapply_refinement_tool if you confirmGet comprehensive code analysis:
You: "Review ./server.py for security issues and performance problems"
Claude will:
review_code_tool on the fileRefinement:
Review:
Configure via ai_provider parameter or Claude will use the default (gemini).
gemini - Gemini 2.0 Flash (fast, free tier)gemini-pro - Gemini 1.5 Pro (more capable)claude or claude-sonnet - Claude 3.5 Sonnet (high quality)claude-opus - Claude 3 Opus (most capable)claude-haiku - Claude 3.5 Haiku (fastest)openai or gpt-4o - GPT-4o (balanced)gpt-4 - GPT-4 Turbogpt-3.5 - GPT-3.5 Turbo (fastest)This server provides three MCP tools that Claude Desktop can call automatically:
refine_code_toolPurpose: Improves existing code based on natural language feedback using a second-layer LLM.
Parameters:
user_request (string, required) - What you want to improve (e.g., "make it more logical", "add error handling")file_path (string, required) - Path to the code file to refineai_provider (string, optional) - AI model to use (default: "gemini")Returns:
{
"status": "success",
"explanation": "Added error handling and simplified logic...",
"diff": "--- original\n+++ refined\n...",
"refined_code": "def improved_function():\n ...",
"file_path": "./app.py"
}
review_code_toolPurpose: Analyzes code for bugs, security vulnerabilities, performance issues, and quality.
Parameters:
file_path (string, required) - Path to the code file to reviewai_provider (string, optional) - AI model to use (default: "gemini")Returns:
{
"status": "success",
"issues": [
{
"severity": "high",
"category": "security",
"issue": "SQL injection vulnerability",
"line": 42,
"suggestion": "Use parameterized queries..."
}
],
"strengths": ["Good error handling", "Clear naming"],
"overall_assessment": "Code is functional but has security concerns...",
"score": 7
}
apply_refinement_toolPurpose: Applies refined code to the file after user approval.
Parameters:
file_path (string, required) - Path to the file to updaterefined_code (string, required) - The improved code from refine_code_toolReturns:
{
"status": "success",
"message": "Code successfully applied to ./app.py"
}
Important: Only use this after the user has reviewed and approved the changes!
Test the server without Claude Desktop:
python client.py
This runs a simple test client to verify the server works.
mcp_code_review/
├── mcp_server.py # Main MCP server entry point
├── client.py # Test client for local testing
├── requirements.txt # Python dependencies
├── .env.example # Environment variables template
├── .env # Your API keys (git-ignored)
│
├── tools/ # MCP tool implementations
│ ├── __init__.py
│ ├── file_ops.py # File read/write utilities
│ ├── code_refinement.py # Code refinement logic
│ └── code_review.py # Code review logic
│
├── prompts/ # AI prompt templates
│ ├── code_refinement.txt # Refinement prompt template
│ └── code_review.txt # Review prompt template
│
└── utils/ # Helper utilities
├── __init__.py
├── llm_client.py # LiteLLM wrapper for multi-provider support
└── diff_generator.py # Unified diff generation
This server implements a "second-layer LLM" architecture:
This two-layer approach combines Claude's conversational abilities with specialized code analysis/refinement models.
First LLM generates code → Use this to improve it
Get AI-powered feedback on your code
Keep refining until perfect
See how AI would improve your code and learn from it
requirements.txt:fastmcp - FastMCP frameworkmcp - Model Context Protocol SDKlitellm - Multi-provider LLM wrapperrich - Terminal formattingpython-dotenv - Environment variable managementclaude_desktop_config.json is absolute, not relativewhich python in your activated venv)~/Library/Logs/Claude/%APPDATA%\Claude\logs\.env fileclaude_desktop_config.json env section/ or escaped backslashes \\ls /path/to/file.pypip install -r requirements.txt --upgradepython --version (must be 3.10+)Run the test client to verify the server works:
python client.py
This bypasses Claude Desktop and tests the MCP server directly.
Contributions are welcome! Here's how you can help:
prompts/ can always be refinedMIT License - see LICENSE file for details
Built with:
Questions or issues? Open an issue on GitHub or check the troubleshooting section above.
Добавь это в claude_desktop_config.json и перезапусти Claude Desktop.
{
"mcpServers": {
"mcp-code-reviewer": {
"command": "npx",
"args": []
}
}
}