review_code
Analyze code changes, provide feedback, and improve quality by reviewing security, performance, style, or logic. Supports Git diffs and custom context for targeted insights.
Instructions
Review code changes and provide feedback
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| context | No | Context about the changes | |
| diff | Yes | Git diff or code changes to review | |
| reviewType | No | Type of review to perform | all |
Implementation Reference
- src/tools/reviewCode.ts:5-36 (handler)ReviewCodeTool class: core handler logic for the review_code tool, generates AI prompts for code review based on options.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}` : ''}`; } }
- src/tools/reviewCode.ts:40-42 (handler)Exported reviewCode function: entrypoint handler that executes the ReviewCodeTool instance.export async function reviewCode(args: CodeReviewOptions): Promise<CallToolResult> { return tool.execute(args); }
- src/types/index.ts:44-48 (schema)CodeReviewOptions interface: input schema defining parameters for code review tool (diff, context, reviewType).export interface CodeReviewOptions { diff: string; context?: string; reviewType?: 'security' | 'performance' | 'style' | 'logic' | 'all'; }
- src/tools/reviewCode.ts:6-12 (helper)reviewFocus object: helper mapping review types to specific focus descriptions used in system prompt.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', };