Skip to main content
Glama

review-code

Analyze code for bugs, security vulnerabilities, performance bottlenecks, or style inconsistencies using AI models. Define review tasks, specify focus areas, and select preferred AI provider for tailored results.

Instructions

Review code for bugs, security issues, performance, or style problems

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filesNoFile paths to review (optional)
focusNoReview focus areaall
providerNoAI provider to usegemini
taskYesWhat to review (e.g., 'review pull request changes', 'check for security issues')

Implementation Reference

  • The core handler function `handleReviewCode` in AIToolHandlers class. Selects AI provider, constructs specialized system prompt based on review focus (bugs/security/performance/style), generates code review analysis using provider.generateText, and returns structured MCP response with content and metadata.
    async 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, }, };
  • src/server.ts:295-302 (registration)
    Tool registration in createServer(). Registers 'review-code' tool with title, description, ReviewCodeSchema input validation, and handler that delegates to AIToolHandlers.handleReviewCode via getHandlers().
    server.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); });
  • Zod input schema definition for 'review-code' tool used in registration. Defines task (required), optional files array, focus enum (bugs/security/performance/style/all, default 'all'), and provider enum (default 'gemini').
    const 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"), });
  • Duplicate Zod schema definition in ai-tools.ts for type inference in handleReviewCode method params.
    const 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"), });
  • getHandlers() lazy-initializes and returns AIToolHandlers instance with ProviderManager. Sets env vars from config, required for all AI tools including review-code.
    async function getHandlers() { if (!handlers) { const { ConfigManager } = require("./config/manager"); const { ProviderManager } = require("./providers/manager"); const { AIToolHandlers } = require("./handlers/ai-tools"); const configManager = new ConfigManager(); // Load config and set environment variables const config = await configManager.getConfig(); if (config.openai?.apiKey) { process.env.OPENAI_API_KEY = config.openai.apiKey; } if (config.openai?.baseURL) { process.env.OPENAI_BASE_URL = config.openai.baseURL; } if (config.google?.apiKey) { process.env.GOOGLE_API_KEY = config.google.apiKey; } if (config.google?.baseURL) { process.env.GOOGLE_BASE_URL = config.google.baseURL; } if (config.azure?.apiKey) { process.env.AZURE_API_KEY = config.azure.apiKey; } if (config.azure?.baseURL) { process.env.AZURE_BASE_URL = config.azure.baseURL; } if (config.xai?.apiKey) { process.env.XAI_API_KEY = config.xai.apiKey; } if (config.xai?.baseURL) { process.env.XAI_BASE_URL = config.xai.baseURL; } providerManager = new ProviderManager(configManager); handlers = new AIToolHandlers(providerManager); } return handlers; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/RealMikeChong/ultra-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server