gemini_analyze_codebase
Analyze codebases to identify patterns, duplications, architectural issues, and suggest improvements across architecture, security, performance, or general code quality.
Instructions
Specialized tool for analyzing entire codebases. Gemini will find patterns, duplications, architectural issues, and suggest improvements.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| codebase | Yes | The entire codebase or multiple files concatenated | |
| focus | No | What to focus on: 'architecture', 'duplications', 'security', 'performance', or 'general' |
Implementation Reference
- index.js:185-229 (handler)The handler function for the 'gemini_analyze_codebase' tool. It extracts arguments, defines focus-specific prompts, constructs a detailed analysis prompt for Gemini 2.5 Flash, generates the response, and returns it formatted.if (name === "gemini_analyze_codebase") { const { codebase, focus = "general" } = args; const focusPrompts = { architecture: "Analyze the overall architecture, design patterns, and structural issues. Suggest improvements.", duplications: "Find duplicated code, similar patterns, and opportunities for refactoring. Be specific.", security: "Identify security vulnerabilities, unsafe practices, and potential exploits.", performance: "Find performance bottlenecks, inefficient algorithms, and optimization opportunities.", general: "Provide a comprehensive analysis covering architecture, code quality, potential issues, and improvements.", }; const model = genAI.getGenerativeModel({ model: "gemini-2.5-flash" }); const prompt = `You are an expert code reviewer. Analyze this codebase with focus on: ${focus} ${focusPrompts[focus]} Codebase: \`\`\` ${codebase} \`\`\` Provide: 1. Key findings 2. Specific issues with file/line references 3. Actionable recommendations 4. Priority ranking (High/Medium/Low)`; const result = await model.generateContent(prompt); const response = await result.response; return { content: [ { type: "text", text: `[Gemini Codebase Analysis - ${focus}]\n\n${response.text()}`, }, ], }; }
- index.js:68-94 (registration)Registers the 'gemini_analyze_codebase' tool in the MCP server's listTools response, defining its name, description, and input schema for validation.{ name: "gemini_analyze_codebase", description: "Specialized tool for analyzing entire codebases. Gemini will find patterns, duplications, architectural issues, and suggest improvements.", inputSchema: { type: "object", properties: { codebase: { type: "string", description: "The entire codebase or multiple files concatenated", }, focus: { type: "string", description: "What to focus on: 'architecture', 'duplications', 'security', 'performance', or 'general'", enum: [ "architecture", "duplications", "security", "performance", "general", ], }, }, required: ["codebase"], }, },
- index.js:68-94 (schema)Defines the input schema for the 'gemini_analyze_codebase' tool, specifying required 'codebase' parameter and optional 'focus' with enum values.{ name: "gemini_analyze_codebase", description: "Specialized tool for analyzing entire codebases. Gemini will find patterns, duplications, architectural issues, and suggest improvements.", inputSchema: { type: "object", properties: { codebase: { type: "string", description: "The entire codebase or multiple files concatenated", }, focus: { type: "string", description: "What to focus on: 'architecture', 'duplications', 'security', 'performance', or 'general'", enum: [ "architecture", "duplications", "security", "performance", "general", ], }, }, required: ["codebase"], }, },