A powerful second-layer LLM MCP server that refines and reviews code using AI.
MCP Code Refiner
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.
What is This?
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:
- Refine code generated by ChatGPT, Claude, or any AI with natural language feedback
- Get comprehensive code reviews with security and performance analysis
- Iteratively improve code until it meets your standards
- Learn from AI-suggested improvements
Features
- Code Refinement - Improve code with natural language feedback ("make it more logical", "add error handling")
- Code Review - AI-powered analysis for bugs, security, performance, and best practices
- Multi-Model Support - Choose between Gemini, Claude, or OpenAI models
- Plug & Play - Works with Claude Desktop and any MCP client
- Smart Prompts - Optimized prompts for high-quality, actionable results
- Diff View - See exactly what changes before applying them
Quick Start
Prerequisites
- Python 3.10 or higher
- At least one AI provider API key (Gemini recommended for free tier)
1. Clone and Install
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
2. Configure API Keys
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:
- Gemini: https://ai.google.dev/
- Claude: https://console.anthropic.com/
- OpenAI: https://platform.openai.com/api-keys
3. Connect to Claude Desktop
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.
Usage
Once configured, just talk to Claude naturally in Claude Desktop. The tools are automatically available!
Code Refinement
Improve existing code with natural language instructions:
You: "Refine ./my_script.py to make it more logical and add error handling"
Claude will:
- Call
refine_code_toolwith your request - Show you a diff of proposed changes
- Explain what was changed and why
- Ask for your approval
- Apply changes with
apply_refinement_toolif you confirm
Code Review
Get comprehensive code analysis:
You: "Review ./server.py for security issues and performance problems"
Claude will:
- Call
review_code_toolon the file - Show issues found with severity levels (high/medium/low)
- Highlight code strengths
- Provide an overall quality score
- Suggest specific improvements
Real-World Examples
Refinement:
- "Make ./app.py more performant by optimizing loops"
- "Simplify the logic in ./utils/helper.py"
- "Add comprehensive error handling to ./api/routes.py"
- "Refactor ./legacy_code.py to follow modern Python best practices"
- "Add type hints and docstrings to ./calculator.py"
Review:
- "Review ./authentication.py for security vulnerabilities"
- "Check ./database.py for SQL injection risks"
- "Analyze ./api_client.py for error handling issues"
- "Review ./main.py and suggest improvements"
Available Models
Configure via ai_provider parameter or Claude will use the default (gemini).
Gemini (Google)
gemini- Gemini 2.0 Flash (fast, free tier)gemini-pro- Gemini 1.5 Pro (more capable)
Claude (Anthropic)
claudeorclaude-sonnet- Claude 3.5 Sonnet (high quality)claude-opus- Claude 3 Opus (most capable)claude-haiku- Claude 3.5 Haiku (fastest)
OpenAI
openaiorgpt-4o- GPT-4o (balanced)gpt-4- GPT-4 Turbogpt-3.5- GPT-3.5 Turbo (fastest)
MCP Tools Reference
This server provides three MCP tools that Claude Desktop can call automatically:
1. `refine_code_tool`
Purpose: Improves existing code based on natural language feedback using a second-layer LLM.
Parameters:
user_request(string, required) - What yo
Tools (3)
refine_code_toolImproves existing code based on natural language feedback using a second-layer LLM.review_code_toolAI-powered analysis for bugs, security, performance, and best practices.apply_refinement_toolApply proposed code changes after human confirmation.Environment Variables
GOOGLE_API_KEYrequiredGoogle Gemini API key (recommended, free tier available)ANTHROPIC_API_KEYAnthropic Claude API key (alternative)OPENAI_API_KEYOpenAI API key (alternative)Configuration
{
"mcpServers": {
"code-refiner": {
"command": "python",
"args": ["/absolute/path/to/mcp_code_review/mcp_server.py"],
"env": {
"GOOGLE_API_KEY": "your-gemini-api-key"
}
}
}
}