Skip to main content
Glama
crazyrabbitLTC

Code Review MCP Server

code_review

Analyze code for quality, security, performance, and maintainability issues with structured feedback and actionable recommendations.

Instructions

Use this tool when you need a comprehensive code review with specific feedback on code quality, security issues, performance problems, and maintainability concerns. This tool performs in-depth analysis on a repository or specific files and returns structured results including issues found, their severity, recommendations for fixes, and overall strengths of the codebase. Use it when you need actionable insights to improve code quality or when evaluating a codebase for potential problems.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repoPathYesPath to the repository to analyze
specificFilesNoSpecific files to review
fileTypesNoFile types to include in the review
detailLevelNoLevel of detail for the code review
focusAreasNoAreas to focus on during the code review

Implementation Reference

  • The main handler function for the 'code_review' MCP tool. It executes repomix to flatten the repository, creates a CodeReviewService instance, calls reviewCodeFromRepomix to perform the LLM-powered review, handles errors, and returns structured JSON results.
    async (params) => {
      try {
        // Execute Repomix to get the flattened codebase
        const repomixOptions: RepomixOptions = {
          includePaths: params.specificFiles || [params.repoPath],
          fileTypes: params.fileTypes,
          outputFormat: 'plain',
        };
        
        const repomixOutput = await executeRepomix(repomixOptions);
        
        // Set up review options
        const reviewOptions: CodeReviewOptions = {
          detailLevel: params.detailLevel || 'detailed',
          focusAreas: params.focusAreas || ['security', 'performance', 'quality', 'maintainability'],
        };
        
        // Create the code review service
        try {
          const codeReviewService = createCodeReviewService();
          
          // Perform the code review
          const reviewResult = await codeReviewService.reviewCodeFromRepomix(repomixOutput, reviewOptions);
          
          // Format the response
          return {
            content: [
              { 
                type: 'text',
                text: JSON.stringify(reviewResult, null, 2) 
              }
            ]
          };
        } catch (error) {
          console.error('Error initializing code review service:', error);
          return {
            content: [
              { 
                type: 'text',
                text: `Error initializing code review service: ${(error as Error).message}. Make sure you have set the necessary environment variables (LLM_PROVIDER and the corresponding API key).`
              }
            ],
            isError: true
          };
        }
      } catch (error) {
        console.error('Error in code review:', error);
        return {
          content: [
            { 
              type: 'text',
              text: `Error performing code review: ${(error as Error).message}`
            }
          ],
          isError: true
        };
      }
    }
  • Zod schema defining the input parameters for the 'code_review' tool, including repoPath, optional specificFiles, fileTypes, detailLevel, and focusAreas.
    const codeReviewParams = {
      repoPath: z.string().describe('Path to the repository to analyze'),
      specificFiles: z.array(z.string()).optional().describe('Specific files to review'),
      fileTypes: z.array(z.string()).optional().describe('File types to include in the review'),
      detailLevel: z.enum(['basic', 'detailed']).optional().describe('Level of detail for the code review'),
      focusAreas: z.array(z.enum(['security', 'performance', 'quality', 'maintainability'])).optional().describe('Areas to focus on during the code review')
    };
  • src/index.ts:67-129 (registration)
    Registration of the 'code_review' tool on the MCP server using server.tool(), including name, description, parameter schema, and handler function.
    server.tool(
      'code_review',
      'Use this tool when you need a comprehensive code review with specific feedback on code quality, security issues, performance problems, and maintainability concerns. This tool performs in-depth analysis on a repository or specific files and returns structured results including issues found, their severity, recommendations for fixes, and overall strengths of the codebase. Use it when you need actionable insights to improve code quality or when evaluating a codebase for potential problems.',
      codeReviewParams,
      async (params) => {
        try {
          // Execute Repomix to get the flattened codebase
          const repomixOptions: RepomixOptions = {
            includePaths: params.specificFiles || [params.repoPath],
            fileTypes: params.fileTypes,
            outputFormat: 'plain',
          };
          
          const repomixOutput = await executeRepomix(repomixOptions);
          
          // Set up review options
          const reviewOptions: CodeReviewOptions = {
            detailLevel: params.detailLevel || 'detailed',
            focusAreas: params.focusAreas || ['security', 'performance', 'quality', 'maintainability'],
          };
          
          // Create the code review service
          try {
            const codeReviewService = createCodeReviewService();
            
            // Perform the code review
            const reviewResult = await codeReviewService.reviewCodeFromRepomix(repomixOutput, reviewOptions);
            
            // Format the response
            return {
              content: [
                { 
                  type: 'text',
                  text: JSON.stringify(reviewResult, null, 2) 
                }
              ]
            };
          } catch (error) {
            console.error('Error initializing code review service:', error);
            return {
              content: [
                { 
                  type: 'text',
                  text: `Error initializing code review service: ${(error as Error).message}. Make sure you have set the necessary environment variables (LLM_PROVIDER and the corresponding API key).`
                }
              ],
              isError: true
            };
          }
        } catch (error) {
          console.error('Error in code review:', error);
          return {
            content: [
              { 
                type: 'text',
                text: `Error performing code review: ${(error as Error).message}`
              }
            ],
            isError: true
          };
        }
      }
    );
  • Core helper method in CodeReviewService that processes Repomix output and delegates to the private reviewCode method, which builds prompts and calls the LLM service for analysis.
    async reviewCodeFromRepomix(repomixOutput: string, options: CodeReviewOptions): Promise<CodeReviewResult> {
      console.log('Processing Repomix output...');
      const processedRepo = await this.codeProcessor.processRepomixOutput(repomixOutput);
      console.log(`Processed Repomix output (${processedRepo.length} characters)`);
      return this.reviewCode(processedRepo, options);
    }
  • Private helper method that constructs the code review prompt and invokes the LLM service with retry logic to generate the review result.
    private async reviewCode(code: string, options: CodeReviewOptions): Promise<CodeReviewResult> {
      try {
        console.log('Building code review prompt...');
        const prompt = this.promptBuilder.buildCodeReviewPrompt(code, options);
        
        console.log('Sending code to LLM for review...');
        // Use retry logic for robustness
        const result = await callWithRetry(
          () => this.llmService.generateReview(prompt),
          3,  // max retries
          2000 // initial delay
        );
        
        console.log('Review completed successfully');
        return result;
      } catch (error) {
        console.error('Error reviewing code:', error);
        throw new Error(`Failed to review code: ${(error as Error).message}`);
      }
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It describes the tool's behavior ('performs in-depth analysis', 'returns structured results including issues found, their severity, recommendations') but lacks details on permissions needed, rate limits, error handling, or whether it modifies the codebase. It adequately covers the core operation but misses some behavioral traits.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded, with the first sentence clearly stating the purpose and key features. It uses two sentences efficiently, though the second sentence could be slightly more concise by combining some clauses without losing clarity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of a code review tool with 5 parameters, no annotations, and no output schema, the description is fairly complete. It covers purpose, usage, and output structure, but could benefit from more details on behavioral aspects like execution time or limitations to fully compensate for the lack of annotations and output schema.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, so the schema already documents all parameters. The description adds context by mentioning 'specific files' and 'focus areas' like security and performance, which align with parameters, but doesn't provide additional semantics beyond what the schema offers. Baseline 3 is appropriate as the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with specific verbs ('perform in-depth analysis', 'returns structured results') and resources ('repository or specific files'), distinguishing it from the sibling tool 'analyze_repo' by emphasizing comprehensive review with specific feedback areas like security, performance, and maintainability.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly states when to use the tool ('when you need a comprehensive code review', 'when you need actionable insights to improve code quality or when evaluating a codebase for potential problems'), providing clear context and distinguishing it from alternatives without being misleading.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/crazyrabbitLTC/mcp-code-review-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server