analyze_document_quality
Assess document quality using AI insights to identify issues like duplication, relevance, and completeness. Input a document path to generate targeted analysis.
Instructions
Perform comprehensive quality analysis on documentation with AI insights
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| analysisTypes | No | Types of analysis to perform | |
| documentPath | Yes | Path to the document to analyze | |
| includeAI | No | Include AI-powered analysis |
Implementation Reference
- src/tools/enhanced/index.ts:319-374 (handler)Main handler function that implements the core logic of the analyze_document_quality tool. Handles document validation, AI-powered analysis for specified types (quality, duplicate, completeness, relevance), basic metrics generation, and compiles a comprehensive quality report with scores, insights, 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/types/enhanced.types.ts:112-116 (schema)Zod input schema for the analyze_document_quality tool, defining validation for documentPath (required), includeAI (boolean, default true), and analysisTypes (array of specific analysis enums, default ['quality']).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:108-135 (registration)MCPTool registration definition including the tool name, description, and inputSchema matching the Zod schema, used in registerEnhancedTools to define the tool for the system.{ 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/tools/enhanced/index.ts:503-517 (helper)Helper function called by the handler to generate basic file-based quality metrics: size, line count, word count, and last modified timestamp.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 in 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; } }