Skip to main content
Glama
Njengah
by Njengah

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';
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It mentions analysis outputs (extract elements, calculate coverage) but lacks critical behavioral details: whether this is read-only or has side effects, performance characteristics, error handling, or format of results. For a tool with no annotation coverage, this leaves significant gaps in understanding how it behaves.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately concise (two sentences) and front-loaded with the core purpose. Every sentence adds value: first states purpose, second adds language support. No wasted words, though it could be slightly more structured with bullet points for clarity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations and no output schema, the description is incomplete for a tool that performs code analysis. It doesn't explain what 'extract code elements' means (functions, classes, etc.), how documentation coverage is calculated, or what the output format looks like. For a tool with one parameter but potentially complex behavior, more context is needed.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100% (the 'path' parameter is fully described in schema), so baseline is 3. The description adds no additional parameter semantics beyond what's in the schema—it doesn't clarify path format requirements, wildcard support, or differences between file vs directory analysis.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Analyze a codebase or file to extract code elements and calculate documentation coverage.' It specifies the verb (analyze), resource (codebase/file), and key outputs (extract elements, calculate coverage). However, it doesn't explicitly differentiate from siblings like 'detect_missing_docs' or 'generate_documentation', which appear related to documentation analysis/generation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides minimal usage guidance. It mentions supported languages (TypeScript, JavaScript, Python), which gives some context, but doesn't explain when to use this tool versus alternatives like 'detect_missing_docs' or 'generate_documentation'. No explicit when/when-not instructions or prerequisites are provided.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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