UNPKG

nascoder-terminal-browser-mcp

Version:

๐ŸŒ Ultimate Standalone Terminal Browser & Web Scraper MCP - Browse any website, extract content & links directly in terminal with zero file pollution. 100% standalone with smart fallbacks. Enhanced by optional terminal browsers (lynx/w3m). Perfect for doc

163 lines (136 loc) โ€ข 4.51 kB
#!/usr/bin/env node /** * Test Suite for NasCoder Terminal Browser MCP */ import { spawn } from 'child_process'; import { fileURLToPath } from 'url'; import { dirname, join } from 'path'; const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); console.log('๐Ÿงช Testing NasCoder Terminal Browser MCP...\n'); // Test environment console.log('1๏ธโƒฃ Testing environment...'); // Check Node.js version const nodeVersion = process.version; const majorVersion = parseInt(nodeVersion.slice(1).split('.')[0]); if (majorVersion >= 18) { console.log(`โœ… Node.js version ${nodeVersion} is supported`); } else { console.log(`โŒ Node.js version ${nodeVersion} is not supported (requires 18+)`); process.exit(1); } // Test basic imports console.log('\n2๏ธโƒฃ Testing imports...'); try { // Test if we can import the main dependencies await import('@modelcontextprotocol/sdk/server/index.js'); await import('node-fetch'); await import('cheerio'); await import('html-to-text'); await import('winston'); console.log('โœ… All dependencies imported successfully'); } catch (error) { console.log(`โŒ Import test failed: ${error.message}`); process.exit(1); } // Test terminal browser availability console.log('\n3๏ธโƒฃ Testing terminal browser availability...'); const browsers = ['lynx', 'w3m', 'links', 'elinks']; const availableBrowsers = []; for (const browser of browsers) { try { await new Promise((resolve, reject) => { const process = spawn('which', [browser]); process.on('close', (code) => { if (code === 0) { availableBrowsers.push(browser); resolve(); } else { reject(); } }); }); } catch (error) { // Browser not available } } if (availableBrowsers.length > 0) { console.log(`โœ… Available browsers: ${availableBrowsers.join(', ')}`); } else { console.log('โš ๏ธ No terminal browsers found - will use fetch+html-to-text fallback'); } // Test MCP server startup console.log('\n4๏ธโƒฃ Testing MCP server startup...'); try { const serverProcess = spawn('node', [join(__dirname, 'index.js')], { stdio: ['pipe', 'pipe', 'pipe'] }); let output = ''; let hasStarted = false; serverProcess.stdout.on('data', (data) => { output += data.toString(); if (output.includes('NasCoder Terminal Browser MCP server started')) { hasStarted = true; } }); serverProcess.stderr.on('data', (data) => { output += data.toString(); }); // Send a test message to the server setTimeout(() => { serverProcess.stdin.write(JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/list" }) + '\n'); }, 1000); // Wait for response await new Promise((resolve) => { setTimeout(() => { serverProcess.kill(); resolve(); }, 3000); }); if (hasStarted || output.includes('tools')) { console.log('โœ… MCP server startup test passed'); } else { console.log('โŒ MCP server startup test failed'); console.log('Output:', output); } } catch (error) { console.log(`โŒ MCP server test failed: ${error.message}`); } // Test basic functionality console.log('\n5๏ธโƒฃ Testing basic functionality...'); try { // Test URL validation const testUrl = 'https://example.com'; if (testUrl.startsWith('http://') || testUrl.startsWith('https://')) { console.log('โœ… URL validation works'); } else { console.log('โŒ URL validation failed'); } // Test HTML to text conversion const htmlToTextModule = await import('html-to-text'); const { htmlToText } = htmlToTextModule; const testHtml = '<h1>Test</h1><p>This is a test.</p>'; const text = htmlToText(testHtml); if (text.toLowerCase().includes('test') && text.includes('This is a test')) { console.log('โœ… HTML to text conversion works'); } else { console.log('โŒ HTML to text conversion failed'); console.log('Converted text:', JSON.stringify(text)); } } catch (error) { console.log(`โŒ Basic functionality test failed: ${error.message}`); } console.log('\n๐ŸŽ‰ Test suite completed!\n'); console.log('๐Ÿ“‹ Summary:'); console.log('- Environment: Checked'); console.log('- Dependencies: Imported'); console.log('- Terminal browsers: Detected'); console.log('- MCP server: Tested'); console.log('- Basic functions: Verified'); console.log('\n๐Ÿš€ NasCoder Terminal Browser MCP is ready to use!'); // Exit with success process.exit(0);