Skip to main content
Glama

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}`); } }

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