docs_analyze_project
Analyze project structure and code to extract classes, functions, interfaces, and documentation coverage for generating professional 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)Core handler function that scans the project directory, detects languages, performs deep AST analysis using language-specific analyzers, builds structure tree, generates suggestions, and returns comprehensive analysis JSON.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 MCP server tools list, 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:36-55 (schema)Input schema defining parameters for the tool: projectPath (required), language, deep (boolean).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 handler in the MCP server's CallToolRequestSchema handler that invokes the analyzeProject function.case "docs_analyze_project": return await analyzeProject(args);
- src/tools/analyzeProject.ts:88-107 (helper)Helper function to recursively scan project directory, excluding node_modules, .git, dist.async function scanDirectory(dir: string): Promise<string[]> { const files: string[] = []; const items = await fs.readdir(dir, { withFileTypes: true }); for (const item of items) { const fullPath = path.join(dir, item.name); if (item.name === "node_modules" || item.name === ".git" || item.name === "dist") { continue; } if (item.isDirectory()) { files.push(...(await scanDirectory(fullPath))); } else { files.push(fullPath); } } return files; }