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
JavaScript
/**
* 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);