#!/usr/bin/env node /** * MCP Test Validation Script * * This script validates that the MCP test scripts are properly structured * without requiring the actual MCP server to be running. */ const fs = require('fs'); const path = require('path'); console.log('šŸ” Validating MCP Test Scripts\n'); console.log('='.repeat(70) + '\n'); const testsDir = __dirname; const testFiles = [ 'mcp-demo.js', 'mcp-simple-test.js' ]; const docFiles = [ 'MCP_TESTS.md', 'QUICKSTART.md' ]; let allValid = true; // Check test files console.log('šŸ“ Checking test script files:\n'); for (const file of testFiles) { const filePath = path.join(testsDir, file); try { // Check if file exists if (!fs.existsSync(filePath)) { console.log(` āŒ ${file} - NOT FOUND`); allValid = false; continue; } // Check if file is readable const content = fs.readFileSync(filePath, 'utf8'); // Check file size const stats = fs.statSync(filePath); // Check for key components const checks = { 'Has shebang': content.startsWith('#!/usr/bin/env node'), 'Has exports': content.includes('module.exports'), 'Has main function': content.includes('async function') || content.includes('function'), 'Has MCP references': content.includes('MCP') || content.includes('mcp'), 'Proper size': stats.size > 1000 }; const allChecksPassed = Object.values(checks).every(v => v); if (allChecksPassed) { console.log(` āœ… ${file} - VALID (${Math.round(stats.size / 1024)}KB)`); } else { console.log(` āš ļø ${file} - WARNINGS:`); for (const [check, passed] of Object.entries(checks)) { if (!passed) { console.log(` - ${check}: FAILED`); } } } // Try to parse as JavaScript require(filePath); } catch (error) { console.log(` āŒ ${file} - ERROR: ${error.message}`); allValid = false; } } // Check documentation files console.log('\nšŸ“š Checking documentation files:\n'); for (const file of docFiles) { const filePath = path.join(testsDir, file); try { if (!fs.existsSync(filePath)) { console.log(` āŒ ${file} - NOT FOUND`); allValid = false; continue; } const content = fs.readFileSync(filePath, 'utf8'); const stats = fs.statSync(filePath); const checks = { 'Has headers': content.includes('#'), 'Has code blocks': content.includes('```'), 'Mentions MCP': content.toLowerCase().includes('mcp'), 'Has usage examples': content.includes('Usage') || content.includes('usage'), 'Proper size': stats.size > 500 }; const allChecksPassed = Object.values(checks).every(v => v); if (allChecksPassed) { console.log(` āœ… ${file} - VALID (${Math.round(stats.size / 1024)}KB)`); } else { console.log(` āš ļø ${file} - WARNINGS:`); for (const [check, passed] of Object.entries(checks)) { if (!passed) { console.log(` - ${check}: FAILED`); } } } } catch (error) { console.log(` āŒ ${file} - ERROR: ${error.message}`); allValid = false; } } // Check for executable permissions console.log('\nšŸ” Checking file permissions:\n'); for (const file of testFiles) { const filePath = path.join(testsDir, file); try { fs.accessSync(filePath, fs.constants.X_OK); console.log(` āœ… ${file} - EXECUTABLE`); } catch (error) { console.log(` āš ļø ${file} - NOT EXECUTABLE (run: chmod +x ${file})`); } } // Check for required dependencies console.log('\nšŸ“¦ Checking dependencies:\n'); const requiredModules = [ '@modelcontextprotocol/sdk', 'readline', 'child_process', 'path', 'fs' ]; for (const module of requiredModules) { try { // Built-in modules don't need to be installed if (['readline', 'child_process', 'path', 'fs', 'os'].includes(module)) { console.log(` āœ… ${module} - BUILT-IN`); continue; } // Try to resolve the module require.resolve(module); console.log(` āœ… ${module} - INSTALLED`); } catch (error) { console.log(` āš ļø ${module} - NOT FOUND (run: npm install ${module})`); } } // Summary console.log('\n' + '='.repeat(70)); if (allValid) { console.log('\nāœ… All validation checks passed!\n'); console.log('Next steps:'); console.log(' 1. Build MCP server: cargo build --release -p ruvector-cli --bin ruvector-mcp'); console.log(' 2. Run tests: node tests/mcp-simple-test.js\n'); process.exit(0); } else { console.log('\nāš ļø Some validation checks failed. Please review the output above.\n'); process.exit(1); }