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
158 lines • 7.86 kB
JavaScript
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import { CallToolRequestSchema, ListToolsRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
// Core services
import { APIKeyManager } from './api-key-manager.js';
import { CloudAIService } from './cloud-ai-service.js';
import { LocalDebugEngine } from './local-debug-engine.js';
import { AuditEngine } from './audit-engine.js';
import { VersionChecker } from './version-checker.js';
import { BackendDebugEngine } from './backend-debug-engine.js';
import { FlutterQuantumDebugger } from './flutter-quantum-debugger.js';
import { NextJSDebugEngineEnhanced } from './nextjs-debug-engine-enhanced-modular.js';
import { MetaFrameworkDebugEngine } from './meta-framework-debug-engine-modular.js';
import { SmartTestMaintenance } from './smart-test-maintenance.js';
// Handler Registry
import { HandlerRegistry } from './handlers/handler-registry.js';
// Import all handlers
import { CoreHandler } from './handlers/core-handler.js';
import { MaintenanceHandler } from './handlers/maintenance-handler.js';
import { InteractionHandler } from './handlers/interaction-handler.js';
import { AuditHandler } from './handlers/audit-handler.js';
import { AnalysisHandler } from './handlers/analysis-handler.js';
import { FlutterHandler } from './handlers/flutter-handler.js';
import { NextJSHandler } from './handlers/nextjs-handler.js';
import { HydrationHandler } from './handlers/hydration-handler.js';
import { BundleHandler } from './handlers/bundle-handler.js';
import { RouteHandler } from './handlers/route-handler.js';
import { ProblemHandler } from './handlers/problem-handler.js';
import { MetaFrameworkHandler } from './handlers/meta-framework-handler.js';
import { PhoenixHandler } from './handlers/phoenix-handler.js';
import { EvolutionHandler } from './handlers/evolution-handler.js';
import { ElixirHandler } from './handlers/elixir-handler.js';
import { EctoHandler } from './handlers/ecto-handler.js';
import { LiveViewAdvancedHandler } from './handlers/liveview-advanced-handler.js';
import { PhoenixAdvancedHandler } from './handlers/phoenix-advanced-handler.js';
/**
* AI Debug Local MCP Server - Refactored with proper handler delegation
*/
export class AIDebugLocalMCPServer {
server;
sessions = new Map();
handlerRegistry;
// Core services
apiKeyManager;
cloudAI;
localEngine;
auditEngine;
versionChecker;
backendEngine;
quantumDebugger;
constructor() {
this.server = new Server({
name: 'ai-debug-local',
version: '2.2.0',
});
// Initialize core services
this.versionChecker = new VersionChecker();
this.apiKeyManager = new APIKeyManager();
this.cloudAI = new CloudAIService();
this.localEngine = new LocalDebugEngine();
this.auditEngine = new AuditEngine();
this.backendEngine = new BackendDebugEngine();
this.quantumDebugger = new FlutterQuantumDebugger();
// Initialize handler registry
this.handlerRegistry = new HandlerRegistry();
// Register all handlers
this.registerHandlers();
// Setup MCP request handlers
this.setupMCPHandlers();
}
registerHandlers() {
// Core handler (inject_debugging, monitor_realtime, close_session, get_subscription_info)
this.handlerRegistry.registerHandler(new CoreHandler(this.localEngine, this.apiKeyManager, this.cloudAI));
// Fault injection handler - TODO: FaultInjectionEngine needs refactoring to not require page in constructor
// this.handlerRegistry.registerHandler(new FaultHandler(this.faultEngine));
// Maintenance handler
this.handlerRegistry.registerHandler(new MaintenanceHandler(new SmartTestMaintenance()));
// Interaction handler (simulate_user_action, take_screenshot)
this.handlerRegistry.registerHandler(new InteractionHandler(this.localEngine));
// Audit handler (run_audit, mock_network)
this.handlerRegistry.registerHandler(new AuditHandler(this.auditEngine, this.localEngine));
// Analysis handler (analyze_with_ai, get_debug_report)
this.handlerRegistry.registerHandler(new AnalysisHandler(this.cloudAI, this.localEngine, this.apiKeyManager));
// Flutter handler (all flutter_* tools)
this.handlerRegistry.registerHandler(new FlutterHandler(this.localEngine, this.quantumDebugger));
// NextJS handler (all nextjs_* tools)
this.handlerRegistry.registerHandler(new NextJSHandler(this.localEngine, new NextJSDebugEngineEnhanced()));
// Hydration handler
this.handlerRegistry.registerHandler(new HydrationHandler(this.localEngine));
// Bundle handler
this.handlerRegistry.registerHandler(new BundleHandler(this.localEngine));
// Route handler
this.handlerRegistry.registerHandler(new RouteHandler(this.localEngine));
// Problem handler
this.handlerRegistry.registerHandler(new ProblemHandler(this.localEngine));
// Meta-framework handler
this.handlerRegistry.registerHandler(new MetaFrameworkHandler(new MetaFrameworkDebugEngine()));
// Phoenix handler
this.handlerRegistry.registerHandler(new PhoenixHandler(this.localEngine));
// Evolution handler
this.handlerRegistry.registerHandler(new EvolutionHandler());
// Elixir handler
this.handlerRegistry.registerHandler(new ElixirHandler());
// Ecto handler
this.handlerRegistry.registerHandler(new EctoHandler());
// LiveView Advanced handler
this.handlerRegistry.registerHandler(new LiveViewAdvancedHandler());
// Phoenix Advanced handler
this.handlerRegistry.registerHandler(new PhoenixAdvancedHandler());
}
setupMCPHandlers() {
// Handle list tools request
this.server.setRequestHandler(ListToolsRequestSchema, async () => {
return {
tools: this.handlerRegistry.getAllTools()
};
});
// Handle tool calls - delegate to handler registry
this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
try {
return await this.handlerRegistry.handleTool(request.params.name, request.params.arguments, this.sessions);
}
catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
return {
content: [{
type: 'text',
text: `❌ **Error**: ${errorMessage}`
}]
};
}
});
}
async run() {
const transport = new StdioServerTransport();
await this.server.connect(transport);
console.log('🔬 AI Debug Local MCP Server ready!');
console.log('🎯 Revolutionary local debugging activated');
console.log('');
if (this.apiKeyManager.hasValidKey()) {
console.log('🔑 Premium features available with your API key');
}
else {
console.log('💡 Free tier active - get API key for AI features');
console.log('🔗 Upgrade: https://ai-debug.com/pricing');
}
console.log('');
console.log(`📊 ${this.handlerRegistry.getHandlerCount()} handlers registered`);
console.log(`🛠️ ${this.handlerRegistry.getToolCount()} tools available`);
}
}
// Auto-start if this file is run directly
if (import.meta.url === `file://${process.argv[1]}`) {
const server = new AIDebugLocalMCPServer();
server.run().catch(console.error);
}
//# sourceMappingURL=server-refactored.js.map