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
119 lines (99 loc) • 3.21 kB
JavaScript
/**
* AI-Debug MCP Global Command - Original with Recovery
*
* Uses the original server with all 346+ tools, but adds automatic restart
* when it crashes. This gives you stability AND all the tools.
*/
const { spawn } = require('child_process');
const path = require('path');
const AI_DEBUG_ROOT = path.dirname(__dirname);
let serverProcess = null;
let restartCount = 0;
const MAX_RESTARTS = 5;
function startServer() {
if (serverProcess) {
try {
serverProcess.kill();
} catch (e) {
// Process already dead
}
}
console.error(`🚀 Starting AI-Debug server (attempt ${restartCount + 1}/${MAX_RESTARTS})...`);
const serverPath = path.join(AI_DEBUG_ROOT, 'dist', 'server.js');
serverProcess = spawn('node', [serverPath], {
stdio: ['pipe', 'pipe', 'pipe'],
detached: false
});
// Forward stdin/stdout for MCP communication
process.stdin.pipe(serverProcess.stdin);
serverProcess.stdout.pipe(process.stdout);
// Handle server crashes
serverProcess.on('exit', (code, signal) => {
if (!process.exitRequested && restartCount < MAX_RESTARTS) {
console.error(`⚠️ AI-Debug server crashed (${code}/${signal}), restarting...`);
restartCount++;
setTimeout(() => startServer(), 1000);
} else if (restartCount >= MAX_RESTARTS) {
console.error(`❌ AI-Debug server crashed ${MAX_RESTARTS} times, giving up`);
process.exit(1);
}
});
serverProcess.on('error', (error) => {
console.error('❌ Failed to start AI-Debug server:', error.message);
if (restartCount < MAX_RESTARTS) {
restartCount++;
setTimeout(() => startServer(), 1000);
} else {
process.exit(1);
}
});
// Log stderr but don't crash on warnings
serverProcess.stderr.on('data', (data) => {
const message = data.toString();
if (message.includes('CRITICAL') || message.includes('ERROR')) {
console.error('AI-Debug:', message.trim());
}
// Ignore other stderr to reduce noise
});
}
// Handle CLI usage
if (process.argv.includes('--help') || process.argv.includes('-h')) {
console.log(`
AI-Debug MCP Server (Original with Auto-Recovery)
A comprehensive debugging platform with 346+ tools and automatic crash recovery.
Usage:
ai-debug-mcp Start MCP server (stdio mode)
ai-debug-mcp --help Show this help message
Features:
- 346+ debugging tools
- Automatic crash recovery
- Complete framework support
- All original functionality
- Restart protection
This command uses the original server with all tools but adds stability through auto-restart.
`);
process.exit(0);
}
if (process.argv.includes('--version') || process.argv.includes('-v')) {
console.log('ai-debug-mcp v2.23.0 (original with recovery)');
process.exit(0);
}
// Handle graceful shutdown
process.exitRequested = false;
process.on('SIGINT', () => {
process.exitRequested = true;
if (serverProcess) {
serverProcess.kill('SIGINT');
}
process.exit(0);
});
process.on('SIGTERM', () => {
process.exitRequested = true;
if (serverProcess) {
serverProcess.kill('SIGTERM');
}
process.exit(0);
});
// Start the server
startServer();