UNPKG

agentic-qe

Version:

Agentic Quality Engineering Fleet System - AI-driven quality management platform

303 lines 18.3 kB
"use strict"; /** * MCP Server for Agentic QE Fleet System * * This module implements the Model Context Protocol server that handles * tool requests and coordinates with the Agentic QE Fleet components. * * @version 1.0.0 * @author Agentic QE Team */ Object.defineProperty(exports, "__esModule", { value: true }); exports.main = exports.createAgenticQEServer = exports.AgenticQEMCPServer = void 0; const index_js_1 = require("@modelcontextprotocol/sdk/server/index.js"); const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js"); const types_js_1 = require("@modelcontextprotocol/sdk/types.js"); const tools_js_1 = require("./tools.js"); const fleet_init_js_1 = require("./handlers/fleet-init.js"); const agent_spawn_js_1 = require("./handlers/agent-spawn.js"); const test_generate_js_1 = require("./handlers/test-generate.js"); const test_execute_js_1 = require("./handlers/test-execute.js"); const quality_analyze_js_1 = require("./handlers/quality-analyze.js"); const predict_defects_js_1 = require("./handlers/predict-defects.js"); const fleet_status_js_1 = require("./handlers/fleet-status.js"); const task_orchestrate_js_1 = require("./handlers/task-orchestrate.js"); const optimize_tests_js_1 = require("./handlers/optimize-tests.js"); const memory_store_js_1 = require("./handlers/memory/memory-store.js"); const memory_retrieve_js_1 = require("./handlers/memory/memory-retrieve.js"); const memory_query_js_1 = require("./handlers/memory/memory-query.js"); const memory_share_js_1 = require("./handlers/memory/memory-share.js"); const memory_backup_js_1 = require("./handlers/memory/memory-backup.js"); const blackboard_post_js_1 = require("./handlers/memory/blackboard-post.js"); const blackboard_read_js_1 = require("./handlers/memory/blackboard-read.js"); const consensus_propose_js_1 = require("./handlers/memory/consensus-propose.js"); const consensus_vote_js_1 = require("./handlers/memory/consensus-vote.js"); const artifact_manifest_js_1 = require("./handlers/memory/artifact-manifest.js"); const workflow_create_js_1 = require("./handlers/coordination/workflow-create.js"); const workflow_execute_js_1 = require("./handlers/coordination/workflow-execute.js"); const workflow_checkpoint_js_1 = require("./handlers/coordination/workflow-checkpoint.js"); const workflow_resume_js_1 = require("./handlers/coordination/workflow-resume.js"); const task_status_js_1 = require("./handlers/coordination/task-status.js"); const event_emit_js_1 = require("./handlers/coordination/event-emit.js"); const event_subscribe_js_1 = require("./handlers/coordination/event-subscribe.js"); const test_generate_enhanced_js_1 = require("./handlers/test/test-generate-enhanced.js"); const test_execute_parallel_js_1 = require("./handlers/test/test-execute-parallel.js"); const test_optimize_sublinear_js_1 = require("./handlers/test/test-optimize-sublinear.js"); const test_report_comprehensive_js_1 = require("./handlers/test/test-report-comprehensive.js"); const test_coverage_detailed_js_1 = require("./handlers/test/test-coverage-detailed.js"); const quality_gate_execute_js_1 = require("./handlers/quality/quality-gate-execute.js"); const quality_validate_metrics_js_1 = require("./handlers/quality/quality-validate-metrics.js"); const quality_risk_assess_js_1 = require("./handlers/quality/quality-risk-assess.js"); const quality_decision_make_js_1 = require("./handlers/quality/quality-decision-make.js"); const quality_policy_check_js_1 = require("./handlers/quality/quality-policy-check.js"); const flaky_test_detect_js_1 = require("./handlers/prediction/flaky-test-detect.js"); const predict_defects_ai_js_1 = require("./handlers/prediction/predict-defects-ai.js"); const regression_risk_analyze_js_1 = require("./handlers/prediction/regression-risk-analyze.js"); const visual_test_regression_js_1 = require("./handlers/prediction/visual-test-regression.js"); const deployment_readiness_check_js_1 = require("./handlers/prediction/deployment-readiness-check.js"); const coverage_analyze_sublinear_handler_js_1 = require("./handlers/analysis/coverage-analyze-sublinear-handler.js"); const coverage_gaps_detect_handler_js_1 = require("./handlers/analysis/coverage-gaps-detect-handler.js"); const performance_benchmark_run_handler_js_1 = require("./handlers/analysis/performance-benchmark-run-handler.js"); const performance_monitor_realtime_handler_js_1 = require("./handlers/analysis/performance-monitor-realtime-handler.js"); const security_scan_comprehensive_handler_js_1 = require("./handlers/analysis/security-scan-comprehensive-handler.js"); const AgentRegistry_js_1 = require("./services/AgentRegistry.js"); const HookExecutor_js_1 = require("./services/HookExecutor.js"); const SwarmMemoryManager_js_1 = require("../core/memory/SwarmMemoryManager.js"); /** * Agentic QE MCP Server * * Handles MCP tool requests and coordinates with QE fleet components. * Integrates with Claude Flow coordination patterns and sublinear-core optimization. */ class AgenticQEMCPServer { constructor() { this.server = new index_js_1.Server({ name: 'agentic-qe-server', version: '1.0.0', description: 'Agentic Quality Engineering Fleet MCP Server' }, { capabilities: { tools: {}, logging: {} } }); // Initialize services this.registry = (0, AgentRegistry_js_1.getAgentRegistry)({ maxAgents: 50, enableMetrics: true }); this.hookExecutor = (0, HookExecutor_js_1.getHookExecutor)({ enabled: true, dryRun: false, timeout: 30000 }); // Initialize shared memory structures for coordination this.memory = new SwarmMemoryManager_js_1.SwarmMemoryManager(); this.memoryStore = new Map(); this.blackboard = new Map(); this.proposals = new Map(); this.handlers = new Map(); this.initializeHandlers(); this.setupRequestHandlers(); } /** * Initialize tool handlers */ initializeHandlers() { // Core fleet management handlers this.handlers.set(tools_js_1.TOOL_NAMES.FLEET_INIT, new fleet_init_js_1.FleetInitHandler(this.registry, this.hookExecutor)); this.handlers.set(tools_js_1.TOOL_NAMES.AGENT_SPAWN, new agent_spawn_js_1.AgentSpawnHandler(this.registry, this.hookExecutor)); this.handlers.set(tools_js_1.TOOL_NAMES.FLEET_STATUS, new fleet_status_js_1.FleetStatusHandler(this.registry, this.hookExecutor)); // Test lifecycle handlers this.handlers.set(tools_js_1.TOOL_NAMES.TEST_GENERATE, new test_generate_js_1.TestGenerateHandler(this.registry, this.hookExecutor)); this.handlers.set(tools_js_1.TOOL_NAMES.TEST_EXECUTE, new test_execute_js_1.TestExecuteHandler(this.registry, this.hookExecutor)); // Quality and analysis handlers this.handlers.set(tools_js_1.TOOL_NAMES.QUALITY_ANALYZE, new quality_analyze_js_1.QualityAnalyzeHandler(this.registry, this.hookExecutor)); this.handlers.set(tools_js_1.TOOL_NAMES.PREDICT_DEFECTS, new predict_defects_js_1.PredictDefectsHandler(this.registry, this.hookExecutor)); // Orchestration and optimization handlers this.handlers.set(tools_js_1.TOOL_NAMES.TASK_ORCHESTRATE, new task_orchestrate_js_1.TaskOrchestrateHandler(this.registry, this.hookExecutor)); this.handlers.set(tools_js_1.TOOL_NAMES.OPTIMIZE_TESTS, new optimize_tests_js_1.OptimizeTestsHandler(this.registry, this.hookExecutor)); // Enhanced test tool handlers this.handlers.set(tools_js_1.TOOL_NAMES.TEST_GENERATE_ENHANCED, new test_generate_enhanced_js_1.TestGenerateEnhancedHandler()); this.handlers.set(tools_js_1.TOOL_NAMES.TEST_EXECUTE_PARALLEL, new test_execute_parallel_js_1.TestExecuteParallelHandler()); this.handlers.set(tools_js_1.TOOL_NAMES.TEST_OPTIMIZE_SUBLINEAR, new test_optimize_sublinear_js_1.TestOptimizeSublinearHandler()); this.handlers.set(tools_js_1.TOOL_NAMES.TEST_REPORT_COMPREHENSIVE, new test_report_comprehensive_js_1.TestReportComprehensiveHandler()); this.handlers.set(tools_js_1.TOOL_NAMES.TEST_COVERAGE_DETAILED, new test_coverage_detailed_js_1.TestCoverageDetailedHandler()); // Memory management handlers - all share the same memoryStore this.handlers.set(tools_js_1.TOOL_NAMES.MEMORY_STORE, new memory_store_js_1.MemoryStoreHandler(this.registry, this.hookExecutor, this.memoryStore)); this.handlers.set(tools_js_1.TOOL_NAMES.MEMORY_RETRIEVE, new memory_retrieve_js_1.MemoryRetrieveHandler(this.registry, this.hookExecutor, this.memoryStore)); this.handlers.set(tools_js_1.TOOL_NAMES.MEMORY_QUERY, new memory_query_js_1.MemoryQueryHandler(this.registry, this.hookExecutor, this.memoryStore)); this.handlers.set(tools_js_1.TOOL_NAMES.MEMORY_SHARE, new memory_share_js_1.MemoryShareHandler(this.registry, this.hookExecutor, this.memoryStore)); this.handlers.set(tools_js_1.TOOL_NAMES.MEMORY_BACKUP, new memory_backup_js_1.MemoryBackupHandler(this.registry, this.hookExecutor, this.memoryStore)); // Blackboard pattern handlers - share the same blackboard this.handlers.set(tools_js_1.TOOL_NAMES.BLACKBOARD_POST, new blackboard_post_js_1.BlackboardPostHandler(this.registry, this.hookExecutor, this.blackboard)); this.handlers.set(tools_js_1.TOOL_NAMES.BLACKBOARD_READ, new blackboard_read_js_1.BlackboardReadHandler(this.registry, this.hookExecutor, this.blackboard)); // Consensus handlers - share the same proposals this.handlers.set(tools_js_1.TOOL_NAMES.CONSENSUS_PROPOSE, new consensus_propose_js_1.ConsensusProposeHandler(this.registry, this.hookExecutor, this.proposals)); this.handlers.set(tools_js_1.TOOL_NAMES.CONSENSUS_VOTE, new consensus_vote_js_1.ConsensusVoteHandler(this.registry, this.hookExecutor, this.proposals)); // Artifact management handlers this.handlers.set(tools_js_1.TOOL_NAMES.ARTIFACT_MANIFEST, new artifact_manifest_js_1.ArtifactManifestHandler(this.registry, this.hookExecutor)); // Coordination handlers (Phase 1) this.handlers.set(tools_js_1.TOOL_NAMES.WORKFLOW_CREATE, new workflow_create_js_1.WorkflowCreateHandler(this.registry, this.hookExecutor)); this.handlers.set(tools_js_1.TOOL_NAMES.WORKFLOW_EXECUTE, new workflow_execute_js_1.WorkflowExecuteHandler(this.registry, this.hookExecutor, this.memory)); this.handlers.set(tools_js_1.TOOL_NAMES.WORKFLOW_CHECKPOINT, new workflow_checkpoint_js_1.WorkflowCheckpointHandler(this.memory)); this.handlers.set(tools_js_1.TOOL_NAMES.WORKFLOW_RESUME, new workflow_resume_js_1.WorkflowResumeHandler(this.memory, this.hookExecutor)); this.handlers.set(tools_js_1.TOOL_NAMES.TASK_STATUS, new task_status_js_1.TaskStatusHandler(this.memory)); this.handlers.set(tools_js_1.TOOL_NAMES.EVENT_EMIT, new event_emit_js_1.EventEmitHandler(this.memory)); this.handlers.set(tools_js_1.TOOL_NAMES.EVENT_SUBSCRIBE, new event_subscribe_js_1.EventSubscribeHandler(this.memory)); // Quality gate handlers this.handlers.set(tools_js_1.TOOL_NAMES.QUALITY_GATE_EXECUTE, new quality_gate_execute_js_1.QualityGateExecuteHandler(this.registry, this.hookExecutor)); this.handlers.set(tools_js_1.TOOL_NAMES.QUALITY_VALIDATE_METRICS, new quality_validate_metrics_js_1.QualityValidateMetricsHandler(this.hookExecutor)); this.handlers.set(tools_js_1.TOOL_NAMES.QUALITY_RISK_ASSESS, new quality_risk_assess_js_1.QualityRiskAssessHandler(this.hookExecutor)); this.handlers.set(tools_js_1.TOOL_NAMES.QUALITY_DECISION_MAKE, new quality_decision_make_js_1.QualityDecisionMakeHandler(this.hookExecutor)); this.handlers.set(tools_js_1.TOOL_NAMES.QUALITY_POLICY_CHECK, new quality_policy_check_js_1.QualityPolicyCheckHandler(this.hookExecutor)); // Prediction and analysis handlers this.handlers.set(tools_js_1.TOOL_NAMES.FLAKY_TEST_DETECT, new flaky_test_detect_js_1.FlakyTestDetectHandler(this.registry, this.hookExecutor)); this.handlers.set(tools_js_1.TOOL_NAMES.PREDICT_DEFECTS_AI, new predict_defects_ai_js_1.PredictDefectsAIHandler(this.registry, this.hookExecutor)); this.handlers.set(tools_js_1.TOOL_NAMES.REGRESSION_RISK_ANALYZE, new regression_risk_analyze_js_1.RegressionRiskAnalyzeHandler(this.registry, this.hookExecutor)); this.handlers.set(tools_js_1.TOOL_NAMES.VISUAL_TEST_REGRESSION, new visual_test_regression_js_1.VisualTestRegressionHandler(this.registry, this.hookExecutor)); this.handlers.set(tools_js_1.TOOL_NAMES.DEPLOYMENT_READINESS_CHECK, new deployment_readiness_check_js_1.DeploymentReadinessCheckHandler(this.registry, this.hookExecutor)); // Analysis handlers this.handlers.set(tools_js_1.TOOL_NAMES.COVERAGE_ANALYZE_SUBLINEAR, new coverage_analyze_sublinear_handler_js_1.CoverageAnalyzeSublinearHandler()); this.handlers.set(tools_js_1.TOOL_NAMES.COVERAGE_GAPS_DETECT, new coverage_gaps_detect_handler_js_1.CoverageGapsDetectHandler()); this.handlers.set(tools_js_1.TOOL_NAMES.PERFORMANCE_BENCHMARK_RUN, new performance_benchmark_run_handler_js_1.PerformanceBenchmarkRunHandler()); this.handlers.set(tools_js_1.TOOL_NAMES.PERFORMANCE_MONITOR_REALTIME, new performance_monitor_realtime_handler_js_1.PerformanceMonitorRealtimeHandler()); this.handlers.set(tools_js_1.TOOL_NAMES.SECURITY_SCAN_COMPREHENSIVE, new security_scan_comprehensive_handler_js_1.SecurityScanComprehensiveHandler()); } /** * Setup MCP request handlers */ setupRequestHandlers() { // Handle tool listing requests this.server.setRequestHandler(types_js_1.ListToolsRequestSchema, async () => { return { tools: tools_js_1.agenticQETools }; }); // Handle tool call requests this.server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params; try { // Validate tool exists if (!this.handlers.has(name)) { throw new types_js_1.McpError(types_js_1.ErrorCode.MethodNotFound, `Unknown tool: ${name}`); } // Get handler and execute const handler = this.handlers.get(name); const result = await handler.handle(args); return { content: [ { type: 'text', text: JSON.stringify(result, null, 2) } ] }; } catch (error) { // Handle known MCP errors if (error instanceof types_js_1.McpError) { throw error; } // Handle unexpected errors this.server.notification({ method: 'notifications/message', params: { level: 'error', logger: 'agentic-qe-server', data: { tool: name, error: error instanceof Error ? error.message : String(error), stack: error instanceof Error ? error.stack : undefined } } }); throw new types_js_1.McpError(types_js_1.ErrorCode.InternalError, `Tool execution failed: ${error instanceof Error ? error.message : String(error)}`); } }); // Handle logging - removed as onNotification doesn't exist in new SDK // this.server.notification('notifications/message', (notification: any) => { // const { level, logger, data } = notification.params; // console.log(`[${level}] ${logger}:`, data); // }); } /** * Start the MCP server */ async start(transport) { const serverTransport = transport || new stdio_js_1.StdioServerTransport(); await this.server.connect(serverTransport); // Log to stderr to not interfere with MCP stdio protocol console.error('Agentic QE MCP Server started successfully'); console.error(`Available tools: ${tools_js_1.agenticQETools.map(t => t.name).join(', ')}`); } /** * Stop the MCP server */ async stop() { // Cleanup all agents await this.registry.clearAll(); await this.server.close(); console.error('Agentic QE MCP Server stopped'); } /** * Get server instance for testing */ getServer() { return this.server; } /** * Get available tools */ getTools() { return tools_js_1.agenticQETools; } /** * Check if tool is supported */ supportsTool(toolName) { return this.handlers.has(toolName); } } exports.AgenticQEMCPServer = AgenticQEMCPServer; /** * Factory function to create and start MCP server */ async function createAgenticQEServer() { const server = new AgenticQEMCPServer(); await server.start(); return server; } exports.createAgenticQEServer = createAgenticQEServer; /** * Main entry point for standalone server execution */ async function main() { try { const server = await createAgenticQEServer(); // Handle graceful shutdown process.on('SIGINT', async () => { console.log('\nReceived SIGINT, shutting down gracefully...'); await server.stop(); process.exit(0); }); process.on('SIGTERM', async () => { console.log('\nReceived SIGTERM, shutting down gracefully...'); await server.stop(); process.exit(0); }); // Keep process alive process.stdin.resume(); } catch (error) { console.error('Failed to start Agentic QE MCP Server:', error); process.exit(1); } } exports.main = main; // Start server if this file is run directly // Note: import.meta requires ES module configuration // if (import.meta.url === `file://${process.argv[1]}`) { // main().catch(console.error); // } //# sourceMappingURL=server.js.map