review_code
Analyze code changes to identify issues in security, performance, style, or logic. Provide actionable feedback on Git diffs to improve code quality during development.
Instructions
Review code changes and provide feedback
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| diff | Yes | Git diff or code changes to review | |
| context | No | Context about the changes | |
| reviewType | No | Type of review to perform | all |
Implementation Reference
- src/tools/reviewCode.ts:5-42 (handler)The ReviewCodeTool class extends BaseAITool and implements the core logic for code review, including prompts and focus areas. The reviewCode function is the entry point that executes the tool.class ReviewCodeTool extends BaseAITool<CodeReviewOptions> { private readonly reviewFocus = { security: 'Security vulnerabilities, input validation, authentication/authorization issues, data exposure risks', performance: 'Performance bottlenecks, inefficient algorithms, memory leaks, unnecessary computations', style: 'Code style consistency, naming conventions, code organization, readability', logic: 'Business logic errors, edge cases, error handling, correctness of implementation', all: 'All aspects including security, performance, code style, and logic', }; protected getActionName(): string { return 'reviewing code'; } protected getSystemPrompt(args: CodeReviewOptions): string { const { reviewType = 'all' } = args; return `You are an expert code reviewer. Review the provided code changes critically and provide actionable feedback. Focus on: ${this.reviewFocus[reviewType]} Provide: - Specific line-by-line feedback where issues are found - Severity level for each issue (critical, major, minor) - Concrete suggestions for improvement - Recognition of good practices when present Be constructive but thorough in identifying potential issues.`; } protected getUserPrompt(args: CodeReviewOptions): string { const { diff, context } = args; return `Review these code changes:\n\n${diff}${context ? `\n\nContext: ${context}` : ''}`; } } const tool = new ReviewCodeTool(); export async function reviewCode(args: CodeReviewOptions): Promise<CallToolResult> { return tool.execute(args); }
- src/types/index.ts:44-48 (schema)TypeScript interface defining the input options for the review_code tool, matching the Zod schema in registration.export interface CodeReviewOptions { diff: string; context?: string; reviewType?: 'security' | 'performance' | 'style' | 'logic' | 'all'; }
- src/index.ts:57-68 (registration)Registers the 'review_code' tool with the MCP server, providing description, Zod inputSchema for validation, and the handler function.server.registerTool( 'review_code', { description: 'Review code changes and provide feedback', inputSchema: { diff: z.string().describe('Git diff or code changes to review'), context: z.string().optional().describe('Context about the changes'), reviewType: z.enum(['security', 'performance', 'style', 'logic', 'all']).optional().default('all').describe('Type of review to perform'), }, }, async (args) => reviewCode(args) );