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

240 lines • 9.58 kB
/** * Universal MCP Workflow Orchestrator * * Transforms AI-Debug into the central hub for Claude Code sub-agent workflows. * Automatically detects available MCP servers and orchestrates intelligent workflows. */ /** * Universal MCP Orchestrator * The brain that coordinates all MCP workflows for Claude Code */ export class UniversalMCPOrchestrator { availableServers = new Map(); workflows = new Map(); activeSessions = new Map(); /** * Auto-discover all available MCP servers in Claude Code environment */ async discoverMCPServers() { // This would integrate with Claude Code's MCP server registry const detectedServers = [ { name: 'ai-debug-local', capabilities: ['runtime-debugging', 'performance-analysis', 'screenshot-capture', 'accessibility-testing'], tools: [], // Would be populated from actual server category: 'runtime-debugging', description: 'Runtime debugging and performance analysis' }, { name: 'serena', capabilities: ['static-analysis', 'code-search', 'refactoring', 'symbol-analysis'], tools: [], category: 'static-analysis', description: 'Static code analysis and refactoring' }, { name: 'context7', capabilities: ['documentation-search', 'library-analysis', 'api-reference'], tools: [], category: 'productivity', description: 'Documentation and library context' } // Auto-detect any other MCP servers available to Claude Code ]; // Cache discovered servers detectedServers.forEach(server => { this.availableServers.set(server.name, server); }); return detectedServers; } /** * Intelligently determine workflow based on user intent */ async planWorkflow(intent, availableServers) { const workflow = []; switch (intent.type) { case 'debug-fix': workflow.push({ phase: 'discovery', server: 'ai-debug-local', tools: ['inject_debugging', 'take_screenshot', 'get_console_logs'], handoffData: {}, parallelExecution: false }, { phase: 'analysis', server: 'ai-debug-local', tools: ['run_audit', 'analyze_with_ai'], handoffData: {}, parallelExecution: true }, { phase: 'code-analysis', server: 'serena', tools: ['find_symbol', 'search_for_pattern'], handoffData: { findings: true, screenshots: true }, parallelExecution: false, condition: 'has_code_issues' }, { phase: 'documentation', server: 'context7', tools: ['get-library-docs'], handoffData: { dependencies: true }, parallelExecution: true, condition: 'needs_api_docs' }, { phase: 'validation', server: 'ai-debug-local', tools: ['take_screenshot', 'run_audit'], handoffData: { fixes_applied: true }, parallelExecution: false }); break; case 'performance-optimize': workflow.push({ phase: 'baseline', server: 'ai-debug-local', tools: ['performance_baseline', 'analyze_bundles'], handoffData: {}, parallelExecution: false }, { phase: 'code-optimization', server: 'serena', tools: ['search_for_pattern', 'find_referencing_symbols'], handoffData: { performance_metrics: true }, parallelExecution: false }, { phase: 'validation', server: 'ai-debug-local', tools: ['performance_validate', 'run_audit'], handoffData: { optimizations_applied: true }, parallelExecution: false }); break; case 'refactor-safely': workflow.push({ phase: 'pre-refactor-capture', server: 'ai-debug-local', tools: ['enable_tdd_mode', 'take_screenshot', 'capture_refactoring_baseline'], handoffData: {}, parallelExecution: true }, { phase: 'refactoring', server: 'serena', tools: ['find_symbol', 'replace_symbol_body', 'insert_after_symbol'], handoffData: { baseline_captured: true, tests_enabled: true }, parallelExecution: false }, { phase: 'validation', server: 'ai-debug-local', tools: ['run_tests_with_coverage', 'validate_after_refactoring'], handoffData: { refactoring_complete: true }, parallelExecution: false }); break; default: // Custom workflow - use AI to plan return this.generateCustomWorkflow(intent, availableServers); } return workflow; } /** * Generate custom workflow using AI analysis */ async generateCustomWorkflow(intent, servers) { // This would use AI to analyze the intent and available tools // to create an optimal workflow automatically return []; } /** * Execute workflow with intelligent handoffs */ async executeWorkflow(sessionId, workflow) { const session = this.activeSessions.get(sessionId); if (!session) { throw new Error(`Session ${sessionId} not found`); } const results = []; for (const step of workflow) { // Check conditions if (step.condition && !this.evaluateCondition(step.condition, session)) { continue; } // Prepare handoff data const handoffData = this.prepareHandoffData(step, session); // Execute step const result = await this.executeWorkflowStep(step, handoffData, session); results.push(result); // Update session with results this.updateSessionWithResults(session, step, result); // Record handoff session.handoffHistory.push({ timestamp: Date.now(), fromServer: session.currentPhase ? this.getCurrentServer(session) : 'orchestrator', toServer: step.server, phase: step.phase, dataExported: handoffData, success: result.success || false }); session.currentPhase = step.phase; } return { workflowComplete: true, totalSteps: workflow.length, results, session: session }; } /** * Universal export format for any MCP server combination */ generateUniversalExport(sessionId, targetServers) { const session = this.activeSessions.get(sessionId); if (!session) { throw new Error(`Session ${sessionId} not found`); } return { meta: { exported_at: new Date().toISOString(), orchestrator_version: '1.0.0', session_id: sessionId, workflow_type: session.workflowType, total_phases: session.handoffHistory.length, target_servers: targetServers }, workflow_context: session.context, phase_results: session.sessionData, handoff_history: session.handoffHistory, server_recommendations: this.generateServerRecommendations(session, targetServers), next_suggested_actions: this.generateNextActions(session, targetServers) }; } // Helper methods evaluateCondition(condition, session) { // Implement condition evaluation logic return true; } prepareHandoffData(step, session) { // Prepare data for handoff based on step requirements return {}; } async executeWorkflowStep(step, handoffData, session) { // Execute the actual workflow step using the appropriate MCP server return { success: true }; } updateSessionWithResults(session, step, result) { // Update session state with step results } getCurrentServer(session) { // Get current server based on session state return 'ai-debug-local'; } generateServerRecommendations(session, targetServers) { // Generate recommendations for next servers to use return {}; } generateNextActions(session, targetServers) { // Generate suggested next actions return {}; } } export const universalOrchestrator = new UniversalMCPOrchestrator(); //# sourceMappingURL=universal-mcp-orchestrator.js.map