analyze_codebase
Analyze codebases or 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.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "analyze_codebase"
}
}Input 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 main handler function for the 'analyze_codebase' tool. It creates a CodebaseAnalyzer instance, analyzes the input path, computes summary statistics on documentation coverage, and returns detailed results per file or structured output.
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 schema defining the input for the analyze_codebase tool: a path to the file or directory.
export const AnalyzeCodebaseSchema = z.object({ path: z.string().describe('Path to file or directory to analyze') }); - src/index.ts:48-52 (registration)Registration of the 'analyze_codebase' tool in the TOOLS array, including name, description, and input schema reference.
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 handler in the tool execution switch statement that validates input with AnalyzeCodebaseSchema and calls the analyzeCodebase function.
case 'analyze_codebase': { const validated = AnalyzeCodebaseSchema.parse(args); const result = await analyzeCodebase(validated); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2) } ] }; } - src/index.ts:12-15 (registration)Import statement bringing in the handler function and schema from the analyze-codebase module.
import { analyzeCodebase, AnalyzeCodebaseSchema } from './tools/analyze-codebase.js';