Skip to main content
Glama

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.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathNoPath to file or directory to analyze

Implementation Reference

  • 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 }; } }
  • 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';

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/Njengah/claude-4.5-mcp-tutorial'

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