review-code
Analyze code for bugs, security vulnerabilities, performance bottlenecks, and style inconsistencies to improve code quality and reliability.
Instructions
Review code for bugs, security issues, performance, or style problems
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| task | Yes | What to review (e.g., 'review pull request changes', 'check for security issues') | |
| files | No | File paths to review (optional) | |
| focus | No | Review focus area | all |
| provider | No | AI provider to use | gemini |
Implementation Reference
- src/server.ts:295-302 (registration)Registration of the 'review-code' tool in the MCP server, specifying title, description, input schema (ReviewCodeSchema), and handler function that delegates to AIToolHandlers.handleReviewCodeserver.registerTool("review-code", { title: "Review Code", description: "Review code for bugs, security issues, performance, or style problems", inputSchema: ReviewCodeSchema.shape, }, async (args) => { const aiHandlers = await getHandlers(); return await aiHandlers.handleReviewCode(args); });
- src/server.ts:41-46 (schema)Zod schema definition for 'review-code' tool input validation: task, optional files, focus (bugs/security/performance/style/all), providerconst ReviewCodeSchema = z.object({ task: z.string().describe("What to review (e.g., 'review pull request changes', 'check for security issues')"), files: z.array(z.string()).optional().describe("File paths to review (optional)"), focus: z.enum(["bugs", "security", "performance", "style", "all"]).default("all").describe("Review focus area"), provider: z.enum(["openai", "gemini", "azure", "grok"]).optional().default("gemini").describe("AI provider to use"), });
- src/handlers/ai-tools.ts:350-398 (handler)Core handler implementation in AIToolHandlers class: selects provider, builds focus-specific system prompt for code review, generates AI response with low temperature, returns structured content and metadataasync handleReviewCode(params: z.infer<typeof ReviewCodeSchema>) { // Use provided provider or get the preferred one (Azure if configured) const providerName = params.provider || (await this.providerManager.getPreferredProvider(['openai', 'gemini', 'azure', 'grok'])); const provider = await this.providerManager.getProvider(providerName); const focusPrompts = { bugs: "Focus on identifying potential bugs, logic errors, and runtime issues", security: "Focus on security vulnerabilities, input validation, and secure coding practices", performance: "Focus on performance bottlenecks, inefficient algorithms, and optimization opportunities", style: "Focus on code style, formatting, naming conventions, and readability", all: "Provide comprehensive code review covering bugs, security, performance, and style" }; const systemPrompt = `You are an expert code reviewer. Review the provided code thoroughly. ${focusPrompts[params.focus]} Provide detailed feedback on: - Issues found and their severity - Specific recommendations for improvement - Code quality assessment - Best practices and standards compliance Be constructive and specific in your review comments.`; const prompt = `Review the following: ${params.task}${params.files ? `\n\nFiles to review: ${params.files.join(", ")}` : ""}`; const response = await provider.generateText({ prompt, systemPrompt, temperature: 0.2, // Very low temperature for code review accuracy reasoningEffort: (providerName === "openai" || providerName === "azure" || providerName === "grok") ? "high" : undefined, useSearchGrounding: false, // No search needed for code review }); return { content: [ { type: "text", text: response.text, }, ], metadata: { provider: providerName, model: response.model, focus: params.focus, usage: response.usage, ...response.metadata, }, };