#!/usr/bin/env node /** * Final Validation Test * Verify the updated MCP-TOOLS-REFERENCE.md is accurate and complete */ import fs from 'fs'; import { ConfigManager } from './src/config/ConfigManager.js'; import { AuthManager } from './src/auth/AuthManager.js'; import { ApiClient } from './src/proxy/ApiClient.js'; import { ToolGenerator } from './src/tools/ToolGenerator.js'; async function finalValidationTest() { try { console.log('๐Ÿงช Final Validation Test for MCP-TOOLS-REFERENCE.md\n'); // Initialize components const config = new ConfigManager(); const authManager = new AuthManager(null, config.getAll(true)); const apiClient = new ApiClient(config.getAll(), authManager); const toolGenerator = new ToolGenerator(apiClient); // Generate all tools console.log('๐Ÿ“‹ Generating all tools from ToolGenerator...'); const allTools = toolGenerator.generateAllTools(); console.log(`โœ… Generated ${allTools.length} tools from ToolGenerator`); // Create unique tools map const uniqueTools = new Map(); allTools.forEach(tool => { if (!uniqueTools.has(tool.name)) { uniqueTools.set(tool.name, tool); } }); console.log(`๐Ÿ“Š Unique tools: ${uniqueTools.size}`); console.log(`๐Ÿ“Š Duplicates: ${allTools.length - uniqueTools.size}`); // Read the documentation file console.log('\n๐Ÿ“– Reading MCP-TOOLS-REFERENCE.md...'); const docContent = fs.readFileSync('MCP-TOOLS-REFERENCE.md', 'utf8'); // Extract tool names from documentation const toolNameRegex = /### `([^`]+)`/g; const docToolNames = []; let match; while ((match = toolNameRegex.exec(docContent)) !== null) { docToolNames.push(match[1]); } console.log(`๐Ÿ“„ Tools documented: ${docToolNames.length}`); // Cross-validation console.log('\n๐Ÿ” Cross-validation between ToolGenerator and Documentation...'); const generatedToolNames = Array.from(uniqueTools.keys()).sort(); const documentedToolNames = [...new Set(docToolNames)].sort(); // Remove duplicates and sort console.log(`๐Ÿ“Š Generated tools: ${generatedToolNames.length}`); console.log(`๐Ÿ“Š Documented tools: ${documentedToolNames.length}`); // Find missing tools in documentation const missingInDoc = generatedToolNames.filter(name => !documentedToolNames.includes(name)); const extraInDoc = documentedToolNames.filter(name => !generatedToolNames.includes(name)); if (missingInDoc.length > 0) { console.log(`\nโš ๏ธ Tools missing from documentation (${missingInDoc.length}):`); missingInDoc.slice(0, 10).forEach(name => console.log(` - ${name}`)); if (missingInDoc.length > 10) { console.log(` ... and ${missingInDoc.length - 10} more`); } } if (extraInDoc.length > 0) { console.log(`\nโš ๏ธ Extra tools in documentation (${extraInDoc.length}):`); extraInDoc.slice(0, 10).forEach(name => console.log(` - ${name}`)); if (extraInDoc.length > 10) { console.log(` ... and ${extraInDoc.length - 10} more`); } } // Test specific tools console.log('\n๐Ÿงช Testing specific tool implementations...'); const testTools = [ 'public_create_login', 'provider_get_emrpatientsList', 'provider_create_startCall', 'patient_get_frontendpatientDashboard' ]; let testsPassed = 0; for (const toolName of testTools) { const tool = toolGenerator.getTool(toolName); if (tool && tool.execute) { console.log(`โœ… ${toolName}: Found and executable`); testsPassed++; } else { console.log(`โŒ ${toolName}: Missing or not executable`); } } // Validate documentation structure console.log('\n๐Ÿ“‹ Validating documentation structure...'); const hasOverview = docContent.includes('## ๐Ÿ“Š Overview'); const hasDistribution = docContent.includes('## ๐Ÿ“‹ Tool Distribution by Authentication Type'); const hasPublicSection = docContent.includes('## ๐ŸŒ Public Tools'); const hasProviderSection = docContent.includes('## ๐Ÿฅ Provider Tools'); const hasUsageGuidelines = docContent.includes('## ๐Ÿ“š Usage Guidelines'); const hasSecurityNotes = docContent.includes('## ๐Ÿ”’ Security Notes'); console.log(`โœ… Overview section: ${hasOverview ? 'Present' : 'Missing'}`); console.log(`โœ… Distribution table: ${hasDistribution ? 'Present' : 'Missing'}`); console.log(`โœ… Public tools section: ${hasPublicSection ? 'Present' : 'Missing'}`); console.log(`โœ… Provider tools section: ${hasProviderSection ? 'Present' : 'Missing'}`); console.log(`โœ… Usage guidelines: ${hasUsageGuidelines ? 'Present' : 'Missing'}`); console.log(`โœ… Security notes: ${hasSecurityNotes ? 'Present' : 'Missing'}`); // Calculate accuracy const accuracy = documentedToolNames.length === generatedToolNames.length && missingInDoc.length === 0 && extraInDoc.length === 0; console.log('\n๐Ÿ“Š Final Results:'); console.log(`๐ŸŽฏ Documentation Accuracy: ${accuracy ? '100%' : 'Needs improvement'}`); console.log(`๐Ÿงช Tool Tests Passed: ${testsPassed}/${testTools.length}`); console.log(`๐Ÿ“„ Total Tools Documented: ${documentedToolNames.length}`); console.log(`๐Ÿ”ง Total Tools Generated: ${generatedToolNames.length}`); console.log(`๐Ÿ“Š Coverage: ${((documentedToolNames.length / generatedToolNames.length) * 100).toFixed(1)}%`); // Summary by auth type console.log('\n๐Ÿ“‹ Tools by Authentication Type:'); const authTypes = ['public', 'provider', 'patient', 'partner', 'affiliate', 'network']; authTypes.forEach(authType => { const authTools = generatedToolNames.filter(name => name.startsWith(authType + '_')); const authPercentage = ((authTools.length / generatedToolNames.length) * 100).toFixed(1); console.log(` ${authType.toUpperCase()}: ${authTools.length} tools (${authPercentage}%)`); }); if (accuracy && testsPassed === testTools.length) { console.log('\n๐ŸŽ‰ All validation tests passed! MCP-TOOLS-REFERENCE.md is accurate and complete.'); return true; } else { console.log('\nโš ๏ธ Some validation issues found. Please review the results above.'); return false; } } catch (error) { console.error('โŒ Validation test failed:', error.message); console.error('๐Ÿ“‹ Stack:', error.stack); return false; } } // Run the validation test finalValidationTest().then(success => { if (success) { console.log('\nโœ… Final validation completed successfully!'); process.exit(0); } else { console.log('\nโŒ Final validation failed!'); process.exit(1); } });