docs_analyze_project
Analyzes project structure and code to extract classes, functions, and documentation coverage for generating comprehensive project documentation.
Instructions
Analyze project structure and perform deep code analysis to understand the project for documentation generation. Supports TypeScript, JavaScript, Python, Go, and more. Deep analysis extracts classes, functions, interfaces, documentation coverage, and more.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectPath | Yes | Path to the project directory to analyze | |
| language | No | Primary programming language (typescript, javascript, python, go, etc.) | |
| deep | No | Enable deep code analysis using language-specific AST parsers (default: true) |
Implementation Reference
- src/tools/analyzeProject.ts:12-86 (handler)Main handler function that scans project directory, detects languages, optionally performs deep AST analysis using language-specific analyzers, builds structure tree, generates suggestions, and returns JSON analysis.export async function analyzeProject(args: any) { const { projectPath, language, deep = true } = args as AnalyzeProjectArgs; try { const stats = await fs.stat(projectPath); if (!stats.isDirectory()) { throw new Error("projectPath must be a directory"); } const files = await scanDirectory(projectPath); const detectedLanguage = language || detectLanguage(files); const allLanguages = detectLanguages(files); // Perform deep analysis if enabled and analyzer available let deepAnalysis: DeepAnalysis | null = null; const languageAnalyses: Record<string, DeepAnalysis> = {}; if (deep) { // If specific language provided, analyze only that if (language) { const analyzer = await createAnalyzer(detectedLanguage, projectPath, files); if (analyzer) { console.log(`Performing deep analysis with ${analyzer.getLanguage()} analyzer...`); deepAnalysis = await analyzer.analyze(); } } else { // Multi-language: Analyze all detected languages console.log(`Detected languages: ${allLanguages.join(", ")}`); for (const lang of allLanguages) { const analyzer = await createAnalyzer(lang, projectPath, files); if (analyzer) { console.log(`Analyzing ${lang} files...`); const analysis = await analyzer.analyze(); if (analysis.files.length > 0) { languageAnalyses[lang] = analysis; } } } // Use primary language or merge results if (Object.keys(languageAnalyses).length > 0) { if (languageAnalyses[detectedLanguage]) { deepAnalysis = languageAnalyses[detectedLanguage]; } else { // Use first available deepAnalysis = Object.values(languageAnalyses)[0]; } } } } const analysis = { path: projectPath, language: detectedLanguage, languages: allLanguages, // All detected languages fileCount: files.length, structure: buildStructureTree(files, projectPath), suggestions: generateSuggestions(files, detectedLanguage), deepAnalysis, // Primary language deep analysis multiLanguageAnalysis: Object.keys(languageAnalyses).length > 1 ? languageAnalyses : undefined, }; return { content: [ { type: "text", text: JSON.stringify(analysis, null, 2), }, ], }; } catch (error) { throw new Error(`Failed to analyze project: ${error}`); } }
- src/index.ts:33-56 (registration)Tool registration in the tools array, including name, description, and input schema definition.{ name: "docs_analyze_project", description: "Analyze project structure and perform deep code analysis to understand the project for documentation generation. Supports TypeScript, JavaScript, Python, Go, and more. Deep analysis extracts classes, functions, interfaces, documentation coverage, and more.", inputSchema: { type: "object", properties: { projectPath: { type: "string", description: "Path to the project directory to analyze", }, language: { type: "string", description: "Primary programming language (typescript, javascript, python, go, etc.)", enum: ["typescript", "javascript", "python", "go", "rust", "java", "csharp"], }, deep: { type: "boolean", description: "Enable deep code analysis using language-specific AST parsers (default: true)", default: true, }, }, required: ["projectPath"], }, },
- src/index.ts:300-301 (handler)Dispatch case in the CallToolRequestSchema handler that invokes the analyzeProject function.case "docs_analyze_project": return await analyzeProject(args);
- src/core/analyzer.ts:40-73 (helper)Factory function that creates language-specific CodeAnalyzer instances for deep code analysis (TypeScript/JS, Python, Go, PHP). Used by the main handler.export async function createAnalyzer( language: string, projectPath: string, files: string[] ): Promise<CodeAnalyzer | null> { switch (language) { case "typescript": case "javascript": const { TypeScriptAnalyzer } = await import( "../analyzers/typescript.js" ); return new TypeScriptAnalyzer(projectPath, files); case "python": const { PythonAnalyzer } = await import("../analyzers/python.js"); return new PythonAnalyzer(projectPath, files); case "go": const { GoAnalyzer } = await import("../analyzers/go.js"); return new GoAnalyzer(projectPath, files); case "php": const { PhpAnalyzer } = await import("../analyzers/php.js"); return new PhpAnalyzer(projectPath, files); // Future analyzers: // case "rust": // const { RustAnalyzer } = await import("../analyzers/rust.js"); // return new RustAnalyzer(projectPath, files); default: return null; // Fallback to shallow analysis } }