Skip to main content
Glama
Njengah
by Njengah

generate_documentation

Create comprehensive markdown documentation for codebases or files, detailing code elements and existing documentation to improve project understanding.

Instructions

Generate comprehensive markdown documentation for a codebase or file, including all code elements and their existing documentation.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathNoPath to file or directory to document
formatNoOutput format for documentation

Implementation Reference

  • Main tool handler function that analyzes the specified path, generates analysis results, uses MarkdownGenerator to create documentation, and returns success/error with stats.
    export async function generateDocumentation(input: GenerateDocumentationInput) {
      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 generator = new MarkdownGenerator();
        const documentation = generator.generateDocumentation(results);
    
        return {
          success: true,
          documentation,
          stats: {
            filesProcessed: results.length,
            totalElements: results.reduce((sum, r) => sum + r.totalElements, 0),
            documentationCoverage: (results.reduce((sum, r) => sum + r.documentationCoverage, 0) / results.length).toFixed(2) + '%'
          }
        };
      } catch (error) {
        return {
          success: false,
          error: (error as Error).message
        };
      }
    }
  • Zod schema defining the input for the generate_documentation tool: path (required) and format (markdown default).
    export const GenerateDocumentationSchema = z.object({
      path: z.string().describe('Path to file or directory to document'),
      format: z.enum(['markdown']).default('markdown').describe('Output format for documentation')
    });
  • src/index.ts:52-56 (registration)
    Tool registration in the TOOLS array, specifying name, description, and input schema.
    {
      name: 'generate_documentation',
      description: 'Generate comprehensive markdown documentation for a codebase or file, including all code elements and their existing documentation.',
      inputSchema: GenerateDocumentationSchema
    },
  • src/index.ts:108-119 (registration)
    Dispatch handler in the MCP server that validates input, calls the generateDocumentation function, and formats the response as MCP content.
    case 'generate_documentation': {
      const validated = GenerateDocumentationSchema.parse(args);
      const result = await generateDocumentation(validated);
      return {
        content: [
          {
            type: 'text',
            text: result.success ? result.documentation : JSON.stringify(result, null, 2)
          }
        ]
      };
    }
  • Core helper method in MarkdownGenerator that orchestrates the creation of markdown documentation from analysis results, including summary and per-file sections.
    generateDocumentation(results: AnalysisResult[]): string {
      const sections: string[] = [];
    
      sections.push('# Codebase Documentation\n');
      sections.push(this.generateSummary(results));
      
      for (const result of results) {
        sections.push(this.generateFileDocumentation(result));
      }
    
      return sections.join('\n\n');
    }

Tool Definition Quality

Score is being calculated. Check back soon.

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