analyze_document_quality
Analyze documentation quality by checking for duplicates, relevance, and completeness using AI-powered insights to improve content accuracy.
Instructions
Perform comprehensive quality analysis on documentation with AI insights
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| documentPath | Yes | Path to the document to analyze | |
| includeAI | No | Include AI-powered analysis | |
| analysisTypes | No | Types of analysis to perform |
Implementation Reference
- src/tools/enhanced/index.ts:319-373 (handler)The main execution handler for the analyze_document_quality tool. It checks document existence, performs AI analyses based on specified types (quality, duplicate, completeness), computes basic metrics, and compiles a quality report with scores and recommendations.tools.set('analyze_document_quality', async (args: any) => { try { logger.info(`Analyzing document quality: ${args.documentPath}`); // Check if document exists const documentExists = await checkDocumentExists(args.documentPath); if (!documentExists) { throw new Error(`Document not found: ${args.documentPath}`); } const analyses: any[] = []; const qualityReport: string[] = []; // Perform requested analysis types if (args.includeAI && aiService) { for (const analysisType of args.analysisTypes) { let analysis; switch (analysisType) { case 'quality': analysis = await aiService.analyzeQuality(args.documentPath); break; case 'duplicate': analysis = await aiService.detectDuplicates(args.documentPath); break; case 'completeness': const recentWork = await getRecentWorkContext(args.documentPath, connectionService); analysis = await aiService.calculateRelevance(args.documentPath, recentWork); break; default: continue; } analyses.push(analysis); qualityReport.push(`${analysisType.toUpperCase()} (${Math.round(analysis.score * 100)}%): ${analysis.insights.join(', ')}`); } } // Generate basic quality metrics const basicMetrics = await generateBasicQualityMetrics(args.documentPath); return { success: true, documentPath: args.documentPath, overallScore: analyses.length > 0 ? Math.round(analyses.reduce((sum, a) => sum + a.score, 0) / analyses.length * 100) : null, basicMetrics, qualityReport, recommendations: analyses.flatMap(a => a.suggestions), analyzedAt: localizationService.getCurrentDateTimeString() }; } catch (error) { logger.error('Failed to analyze document quality:', error); throw error; } });
- src/tools/enhanced/index.ts:108-135 (registration)Registration of the analyze_document_quality tool in the enhanced tools array, including name, description, and input schema for MCP integration.{ name: 'analyze_document_quality', description: 'Perform comprehensive quality analysis on documentation with AI insights', inputSchema: { type: 'object', properties: { documentPath: { type: 'string', description: 'Path to the document to analyze' }, includeAI: { type: 'boolean', description: 'Include AI-powered analysis', default: true }, analysisTypes: { type: 'array', items: { type: 'string', enum: ['quality', 'duplicate', 'relevance', 'completeness'] }, description: 'Types of analysis to perform', default: ['quality'] } }, required: ['documentPath'] } },
- src/types/enhanced.types.ts:112-116 (schema)Zod TypeScript schema definition for validating inputs to the analyze_document_quality tool.export const AnalyzeDocumentQualitySchema = z.object({ documentPath: z.string(), includeAI: z.boolean().default(true), analysisTypes: z.array(z.enum(['quality', 'duplicate', 'relevance', 'completeness'])).default(['quality']), });
- src/tools/enhanced/index.ts:503-517 (helper)Helper function called by the handler to compute basic file metrics (size, lines, words, last modified) for the quality report.async function generateBasicQualityMetrics(documentPath: string): Promise<string[]> { try { const stats = await fs.stat(documentPath); const content = await fs.readFile(documentPath, 'utf-8'); return [ `File Size: ${Math.round(stats.size / 1024)} KB`, `Lines: ${content.split('\n').length}`, `Words: ${content.split(/\s+/).length}`, `Last Modified: ${stats.mtime.toISOString()}` ]; } catch (error) { return [`Error reading file: ${error}`]; } }
- src/tools/enhanced/index.ts:489-496 (helper)Helper function used by the handler to verify if the target document file exists before analysis.async function checkDocumentExists(documentPath: string): Promise<boolean> { try { await fs.access(documentPath); return true; } catch { return false; } }