mcp__gemini__codereview_expert
Analyze code for security, performance, and maintainability issues, providing actionable fixes, risk scoring, and automated suggestions to improve code quality.
Instructions
Multi-perspective code review with actionable fixes, risk scoring, and automated suggestions
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | Code to review | |
| context | No | Code context or description | |
| generate_fixes | No | Generate automated fix suggestions | |
| language | No | Programming language | javascript |
| review_focus | No | Focus areas |
Implementation Reference
- src/tools/enhanced-tools.js:464-539 (handler)The core handler function for the 'mcp__gemini__codereview_expert' tool. It performs multi-perspective code review (security, performance, etc.) by calling the AI client for each focus area, generates a comprehensive summary, and formats the results.handler: async (args) => { const { code, language = 'javascript', review_focus = ['security', 'performance', 'maintainability'], context = '', generate_fixes = true } = args; validateString(code, 'code', 20000); const timer = performanceMonitor.startTimer('codereview_expert'); const focusAreas = Array.isArray(review_focus) ? review_focus : [review_focus]; // Multi-perspective review const reviewPrompts = { security: `Security Review - Focus on vulnerabilities, injection risks, authentication, authorization, data validation:`, performance: `Performance Review - Focus on efficiency, optimization opportunities, resource usage, algorithms:`, maintainability: `Maintainability Review - Focus on code clarity, structure, documentation, technical debt:`, architecture: `Architecture Review - Focus on design patterns, separation of concerns, scalability:`, testing: `Testing Review - Focus on testability, coverage opportunities, test quality:` }; const reviews = {}; for (const focus of focusAreas) { if (reviewPrompts[focus]) { const reviewPrompt = `${reviewPrompts[focus]} ${context ? `Context: ${context}\n\n` : ''}Code to review: \`\`\`${language} ${code} \`\`\` Provide: 1. Overall ${focus} assessment (1-10 scale) 2. Specific issues found with line references 3. Risk level for each issue (Critical/High/Medium/Low) 4. ${generate_fixes ? 'Suggested fixes with code examples' : 'Improvement recommendations'} 5. Best practices violations 6. Positive aspects worth noting Be thorough and specific.`; reviews[focus] = await aiClient.call(reviewPrompt, 'review'); } } // Generate comprehensive summary const summaryPrompt = `Create a comprehensive code review summary from these expert reviews: ${Object.entries(reviews).map(([focus, review]) => `**${focus.toUpperCase()} REVIEW:**\n${review}\n\n---\n`).join('')} Provide: 1. **Executive Summary** with overall quality score (1-10) 2. **Critical Issues** requiring immediate attention 3. **Risk Assessment** with prioritized action items 4. **Quality Metrics** breakdown by category 5. **Improvement Roadmap** with suggested order of fixes 6. **Compliance Check** against ${language} best practices ${generate_fixes ? 'Include specific code examples for top 3 fixes.' : ''}`; const summary = await aiClient.call(summaryPrompt, 'analysis', { maxTokens: 3000 }); timer.end(); return `🔍 **Expert Code Review** (${language}) **Focus Areas**: ${focusAreas.join(', ')} **Auto-fixes**: ${generate_fixes ? 'Enabled' : 'Disabled'} ${summary} --- **Detailed Reviews by Focus Area:** ${Object.entries(reviews).map(([focus, review]) => `### ${focus.toUpperCase()} ${review}`).join('\n\n---\n\n')}`; }
- src/tools/enhanced-tools.js:457-462 (schema)Input schema defining parameters for the code review tool: code (required), language, review_focus, context, generate_fixes.parameters: { code: { type: 'string', description: 'Code to review', required: true }, language: { type: 'string', description: 'Programming language', default: 'javascript' }, review_focus: { type: 'array', description: 'Focus areas', default: ['security', 'performance', 'maintainability'] }, context: { type: 'string', description: 'Code context or description' }, generate_fixes: { type: 'boolean', description: 'Generate automated fix suggestions', default: true }
- src/tools/enhanced-tools.js:455-540 (registration)Tool definition object in enhancedTools export, which includes name, description, parameters (schema), and handler. This object is used for registration.'mcp__gemini__codereview_expert': { description: 'Multi-perspective code review with actionable fixes, risk scoring, and automated suggestions', parameters: { code: { type: 'string', description: 'Code to review', required: true }, language: { type: 'string', description: 'Programming language', default: 'javascript' }, review_focus: { type: 'array', description: 'Focus areas', default: ['security', 'performance', 'maintainability'] }, context: { type: 'string', description: 'Code context or description' }, generate_fixes: { type: 'boolean', description: 'Generate automated fix suggestions', default: true } }, handler: async (args) => { const { code, language = 'javascript', review_focus = ['security', 'performance', 'maintainability'], context = '', generate_fixes = true } = args; validateString(code, 'code', 20000); const timer = performanceMonitor.startTimer('codereview_expert'); const focusAreas = Array.isArray(review_focus) ? review_focus : [review_focus]; // Multi-perspective review const reviewPrompts = { security: `Security Review - Focus on vulnerabilities, injection risks, authentication, authorization, data validation:`, performance: `Performance Review - Focus on efficiency, optimization opportunities, resource usage, algorithms:`, maintainability: `Maintainability Review - Focus on code clarity, structure, documentation, technical debt:`, architecture: `Architecture Review - Focus on design patterns, separation of concerns, scalability:`, testing: `Testing Review - Focus on testability, coverage opportunities, test quality:` }; const reviews = {}; for (const focus of focusAreas) { if (reviewPrompts[focus]) { const reviewPrompt = `${reviewPrompts[focus]} ${context ? `Context: ${context}\n\n` : ''}Code to review: \`\`\`${language} ${code} \`\`\` Provide: 1. Overall ${focus} assessment (1-10 scale) 2. Specific issues found with line references 3. Risk level for each issue (Critical/High/Medium/Low) 4. ${generate_fixes ? 'Suggested fixes with code examples' : 'Improvement recommendations'} 5. Best practices violations 6. Positive aspects worth noting Be thorough and specific.`; reviews[focus] = await aiClient.call(reviewPrompt, 'review'); } } // Generate comprehensive summary const summaryPrompt = `Create a comprehensive code review summary from these expert reviews: ${Object.entries(reviews).map(([focus, review]) => `**${focus.toUpperCase()} REVIEW:**\n${review}\n\n---\n`).join('')} Provide: 1. **Executive Summary** with overall quality score (1-10) 2. **Critical Issues** requiring immediate attention 3. **Risk Assessment** with prioritized action items 4. **Quality Metrics** breakdown by category 5. **Improvement Roadmap** with suggested order of fixes 6. **Compliance Check** against ${language} best practices ${generate_fixes ? 'Include specific code examples for top 3 fixes.' : ''}`; const summary = await aiClient.call(summaryPrompt, 'analysis', { maxTokens: 3000 }); timer.end(); return `🔍 **Expert Code Review** (${language}) **Focus Areas**: ${focusAreas.join(', ')} **Auto-fixes**: ${generate_fixes ? 'Enabled' : 'Disabled'} ${summary} --- **Detailed Reviews by Focus Area:** ${Object.entries(reviews).map(([focus, review]) => `### ${focus.toUpperCase()} ${review}`).join('\n\n---\n\n')}`; } },
- src/tools/registry.js:237-237 (registration)Registration call that registers all tools from enhancedTools module, including 'mcp__gemini__codereview_expert', by iterating over the object and calling registerTool for each.this.registerToolsFromModule(enhancedTools);