Skip to main content
Glama

generate_documentation

Generate comprehensive markdown documentation for codebases and files, including all code elements and existing documentation to improve project understanding and maintenance.

Instructions

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

Input Schema

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

Implementation Reference

  • The primary handler function for the 'generate_documentation' tool. Analyzes the codebase path, generates markdown documentation using MarkdownGenerator, computes statistics, and returns a structured success/error response.
    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 input schema for the tool, defining 'path' (string, required) and 'format' (enum ['markdown'], optional with 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 used by MCP's listTools handler, specifying name, description, and inputSchema.
    { name: 'generate_documentation', description: 'Generate comprehensive markdown documentation for a codebase or file, including all code elements and their existing documentation.', inputSchema: GenerateDocumentationSchema },
  • MCP callTool dispatch handler case that validates input with schema, calls the generateDocumentation function, and formats 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 class that transforms analysis results into formatted markdown documentation with 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'); }

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