analyze_codebase
Analyze codebases and files to extract code elements and calculate documentation coverage for TypeScript, JavaScript, and Python projects.
Instructions
Analyze a codebase or file to extract code elements and calculate documentation coverage. Supports TypeScript, JavaScript, and Python.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | No | Path to file or directory to analyze |
Implementation Reference
- src/tools/analyze-codebase.ts:10-52 (handler)The core handler function for the 'analyze_codebase' tool. It creates a CodebaseAnalyzer instance, analyzes the specified path, computes documentation coverage statistics, and returns a structured result including summary and per-file details.export async function analyzeCodebase(input: AnalyzeCodebaseInput) { try { const analyzer = new CodebaseAnalyzer(); const results = await analyzer.analyzePath(input.path); if (results.length === 0) { return { success: false, error: 'No supported source files found in the specified path' }; } const summary = { totalFiles: results.length, totalElements: results.reduce((sum, r) => sum + r.totalElements, 0), documentedElements: results.reduce((sum, r) => sum + r.documentedElements, 0), averageCoverage: results.reduce((sum, r) => sum + r.documentationCoverage, 0) / results.length }; return { success: true, summary, results: results.map(r => ({ file: r.filePath, language: r.language, elements: r.totalElements, documented: r.documentedElements, coverage: r.documentationCoverage, details: r.elements.map(e => ({ type: e.type, name: e.name, line: e.line, hasDoc: e.hasDocumentation })) })) }; } catch (error) { return { success: false, error: (error as Error).message }; } }
- src/tools/analyze-codebase.ts:4-6 (schema)Zod input schema for the 'analyze_codebase' tool, defining a single required 'path' parameter as a string.export const AnalyzeCodebaseSchema = z.object({ path: z.string().describe('Path to file or directory to analyze') });
- src/index.ts:47-51 (registration)Tool registration object in the TOOLS array, specifying the name, description, and input schema reference for MCP tool listing.{ name: 'analyze_codebase', description: 'Analyze a codebase or file to extract code elements and calculate documentation coverage. Supports TypeScript, JavaScript, and Python.', inputSchema: AnalyzeCodebaseSchema },
- src/index.ts:95-106 (registration)Dispatch logic in the MCP CallTool handler that validates input using the schema, invokes the analyzeCodebase function, and returns the result as MCP content.case 'analyze_codebase': { const validated = AnalyzeCodebaseSchema.parse(args); const result = await analyzeCodebase(validated); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2) } ] }; }