UNPKG

ai-debug-local-mcp

Version:

🎯 ENHANCED AI GUIDANCE v4.1.2: Dramatically improved tool descriptions help AI users choose the right tools instead of 'close enough' options. Ultra-fast keyboard automation (10x speed), universal recording, multi-ecosystem debugging support, and compreh

111 lines (95 loc) 3.03 kB
#!/usr/bin/env node /** * AI-Debug MCP Fixed Wrapper - Filters non-JSON output * * This wrapper ensures only valid JSON-RPC messages go to stdout * All other output (status messages, etc.) goes to stderr */ const { spawn } = require('child_process'); const path = require('path'); const readline = require('readline'); // Find the server path function findServerPath() { const possiblePaths = [ path.join(__dirname, '../dist/server.js'), path.join(__dirname, '../dist/production-mcp.js'), path.join(process.cwd(), 'dist/server.js') ]; const fs = require('fs'); for (const serverPath of possiblePaths) { if (fs.existsSync(serverPath)) { return serverPath; } } // Try to find it via npm global try { const { execSync } = require('child_process'); const npmRoot = execSync('npm root -g', { encoding: 'utf8' }).trim(); const globalPath = path.join(npmRoot, 'ai-debug-local-mcp/dist/server.js'); if (fs.existsSync(globalPath)) { return globalPath; } } catch (e) { // Ignore } return null; } // Main execution async function main() { const serverPath = findServerPath(); if (!serverPath) { console.error('❌ AI-Debug server not found. Please ensure ai-debug-local-mcp is installed.'); process.exit(1); } // Start server with custom stdio handling const serverProcess = spawn('node', [serverPath], { stdio: ['inherit', 'pipe', 'inherit'] // stdin: inherit, stdout: pipe, stderr: inherit }); // Create readline interface for parsing stdout line by line const rl = readline.createInterface({ input: serverProcess.stdout, crlfDelay: Infinity }); // Filter stdout - only pass through valid JSON rl.on('line', (line) => { // Skip empty lines if (!line.trim()) return; // Check if line starts with JSON object or array const trimmed = line.trim(); if (trimmed.startsWith('{') || trimmed.startsWith('[')) { try { // Verify it's valid JSON JSON.parse(trimmed); // It's valid JSON, pass it through to stdout console.log(trimmed); } catch (e) { // Not valid JSON, redirect to stderr console.error(`[AI-Debug Status] ${line}`); } } else { // Non-JSON output, redirect to stderr console.error(`[AI-Debug Status] ${line}`); } }); // Handle process events serverProcess.on('error', (error) => { console.error('❌ Error starting server:', error.message); process.exit(1); }); serverProcess.on('exit', (code, signal) => { if (code !== null) { process.exit(code); } else if (signal) { console.error(`Server terminated by signal: ${signal}`); process.exit(1); } }); // Pass through signals process.on('SIGINT', () => serverProcess.kill('SIGINT')); process.on('SIGTERM', () => serverProcess.kill('SIGTERM')); } // Run main().catch((error) => { console.error('Failed to start AI-Debug server:', error); process.exit(1); });