code_review
Analyze codebases to identify quality, security, performance, and maintainability issues. Receive structured feedback with actionable recommendations to improve code and address potential problems.
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
| Name | Required | Description | Default |
|---|---|---|---|
| detailLevel | No | Level of detail for the code review | |
| fileTypes | No | File types to include in the review | |
| focusAreas | No | Areas to focus on during the code review | |
| repoPath | Yes | Path to the repository to analyze | |
| specificFiles | No | Specific files to review |
Implementation Reference
- src/index.ts:71-128 (handler)The MCP tool handler function that executes the 'code_review' tool logic: validates params, runs repomix on repo, invokes CodeReviewService.reviewCodeFromRepomix, and formats LLM review 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 }; } }
- src/index.ts:58-64 (schema)Zod schema defining input parameters for the 'code_review' tool.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' MCP tool using server.tool(name, description, schema, handler).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 }; } } );
- src/llm/codeReviewService.ts:51-56 (helper)Core helper method in CodeReviewService that processes repomix output and delegates to private reviewCode method which builds prompt and calls LLM.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); }