import { CallToolRequestSchema, ErrorCode, McpError, } from "@modelcontextprotocol/sdk/types.js"; import { XrayKnowledgeSkillBase } from "./shared/knowledge-skill-base.js"; import * as fs from "fs"; import { frameworkLogger } from "../core/framework-logger.js"; import { AGENT_REGISTRY, getActiveAgents } from "../agents/registry.js"; interface CapabilitiesMap { agents: { [key: string]: string }; skills: { [key: string]: string }; commands: { [key: string]: string }; reporting: { [key: string]: string }; } class FrameworkHelpServer extends XrayKnowledgeSkillBase { constructor() { super("xray/framework-help", "3.1.0"); this.tools = [ { name: "xray_get_capabilities", description: "Get comprehensive list of all 0xRay framework capabilities, commands, and available tools", inputSchema: { type: "object", properties: { category: { type: "string", enum: ["all", "agents", "skills", "commands", "reporting"], description: "Filter capabilities by category", default: "all", }, format: { type: "string", enum: ["summary", "detailed", "commands"], description: "Output format", default: "summary", }, }, required: [], }, }, { name: "xray_get_commands", description: "Get list of available 0xRay commands and their usage", inputSchema: { type: "object", properties: { type: { type: "string", enum: [ "agent-commands", "system-commands", "reporting-commands", ], description: "Type of commands to list", default: "agent-commands", }, }, required: [], }, }, { name: "xray_explain_capability", description: "Get detailed explanation of a specific 0xRay capability", inputSchema: { type: "object", properties: { capability: { type: "string", description: "Name of the capability to explain", }, }, required: ["capability"], }, }, ]; this.handlers = { "xray_get_capabilities": async (args) => this.handleGetCapabilities(args as Record | undefined), "xray_get_commands": async (args) => this.handleGetCommands(args as Record | undefined), "xray_explain_capability": async (args) => this.handleExplainCapability(args as Record | undefined), }; this.setupToolHandlers(); } override setupToolHandlers(): void { this.setupListToolsHandler(); this.server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params; const handler = this.handlers[name]; if (!handler) { throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${name}`); } try { return await handler(args); } catch (error) { if (error instanceof McpError) { throw error; } frameworkLogger.log("mcps/framework-help", "tool-call", "error", { tool: name, error: String(error) }); throw new McpError( ErrorCode.InternalError, `Tool "${name}" execution failed: ${error instanceof Error ? error.message : String(error)}`, ); } }); } private getActiveAgentEntries() { return Object.values(AGENT_REGISTRY).filter((e: { status: string }) => e.status === "active"); } private handleGetCapabilities(args: Record | undefined) { const category = (args?.category as string) || "all"; const format = (args?.format as string) || "summary"; const agentEntries = this.getActiveAgentEntries(); const capabilities = { agents: Object.fromEntries( agentEntries.map((e) => [e.name, e.description]), ), skills: { "project-analysis": "Codebase analysis and metrics", "testing-strategy": "Test planning and execution", "code-review": "Code quality assessment", "security-audit": "Security vulnerability scanning", "performance-optimization": "Performance analysis and optimization", "refactoring-strategies": "Code improvement techniques", "ui-ux-design": "User interface and experience design", "documentation-generation": "Technical documentation creation", }, commands: { "framework-reporting-system": "Generate comprehensive framework reports", "complexity-analyzer": "Analyze code complexity and delegation decisions", "codex-injector": "Apply development codex rules and standards", }, reporting: { "activity-logs": "Real-time framework activity monitoring", "performance-metrics": "System performance and resource usage", "error-tracking": "Comprehensive error detection and reporting", "test-coverage": "Automated testing coverage analysis", }, }; let result = ""; if (format === "commands") { result = this.generateCommandList(capabilities); } else if (category === "all") { result = this.generateFullCapabilities(capabilities, format); } else { result = this.generateCategoryCapabilities( capabilities, category, format, ); } return { content: [ { type: "text", text: result, }, ], }; } private handleGetCommands(args: Record | undefined) { const type = (args?.type as string) || "agent-commands"; let commands = ""; switch (type) { case "agent-commands": commands = ` **Agent Commands Available:** ${this.getActiveAgentEntries().map((e: { name: string; description: string }) => `@${e.name} - ${e.description}`).join("\n")} **Usage Examples:** - "@enforcer analyze this code for violations" - "@architect design a scalable solution for X" - "@orchestrator coordinate testing for this feature" - "@seo-consultant review the website for SEO improvements" - "@growth-strategist analyze the marketing strategy" `.trim(); break; case "system-commands": commands = ` **System Commands Available:** framework-reporting-system - Generate comprehensive reports complexity-analyzer - Analyze code complexity codex-injector - Apply development standards **Usage Examples:** - Use framework-reporting-system to generate activity reports - Use complexity-analyzer to understand delegation decisions - Use codex-injector for automated code quality enforcement `.trim(); break; case "reporting-commands": commands = ` **Reporting Commands Available:** Activity Logs - Real-time framework monitoring Performance Metrics - Resource usage analysis Error Tracking - Comprehensive error detection Test Coverage - Automated testing analysis **Usage Examples:** - Check logs/framework/activity.log for framework activity - Run performance benchmarks for system metrics - Monitor error rates through automated tracking `.trim(); break; default: commands = `Error: Unknown command type "${type}". Valid types: agent-commands, system-commands, reporting-commands`; break; } return { content: [ { type: "text", text: commands, }, ], }; } private handleExplainCapability(args: Record | undefined) { const capability = args?.capability as string | undefined; if (!capability) { throw new McpError( ErrorCode.InvalidParams, "capability parameter is required", ); } const explanations: { [key: string]: string } = { enforcer: ` **Enforcer Agent** Automatically validates code against the Universal Development Codex (60 mandatory terms). Prevents common errors, enforces coding standards, and ensures production-ready code. **Capabilities:** - Type safety validation (no any/unknown types) - Architecture compliance checking - Error prevention (90% runtime error reduction) - Code quality enforcement **Usage:** @enforcer analyze this code for violations `.trim(), orchestrator: ` **Orchestrator Agent** Coordinates multiple AI agents for complex development tasks. Automatically delegates work based on complexity analysis (6 metrics). **Capabilities:** - Multi-agent task coordination - Complexity-based delegation (25-95 score range) - Conflict resolution (majority vote, expert priority) - Enterprise workflow management **Usage:** @orchestrator coordinate testing for this feature `.trim(), "framework-reporting-system": ` **Framework Reporting System** Generates comprehensive reports on framework activity and performance. **Capabilities:** - Activity log analysis - Performance metrics reporting - Error tracking and summaries - Test coverage analysis **Usage:** framework-reporting-system generate-report `.trim(), skills: ` **Skills System (23 Skills)** Lazy-loaded capabilities with on-demand MCP server activation. **Available Skills:** - project-analysis: Codebase metrics and analysis - testing-strategy: Test planning and execution - code-review: Quality assessment - security-audit: Vulnerability scanning - performance-optimization: Performance tuning - refactoring-strategies: Code improvement techniques - ui-ux-design: Interface design - documentation-generation: Technical docs **Benefits:** 0 baseline processes, 90% resource reduction `.trim(), }; const explanation = explanations[capability] || `**${capability}** No detailed explanation available. This capability provides specialized functionality within the 0xRay framework. Use @enforcer or check the framework documentation for more details.`; return { content: [ { type: "text", text: explanation, }, ], }; } private generateCommandList(capabilities: CapabilitiesMap): string { return ` **0xRay Framework Commands:** **Agent Commands:** ${Object.entries(capabilities.agents) .map(([name, desc]) => `- @${name}: ${desc}`) .join("\n")} **System Commands:** ${Object.entries(capabilities.commands) .map(([name, desc]) => `- ${name}: ${desc}`) .join("\n")} **Skills (23 available):** ${Object.entries(capabilities.skills) .map(([name, desc]) => `- ${name}: ${desc}`) .join("\n")} **Reporting:** ${Object.entries(capabilities.reporting) .map(([name, desc]) => `- ${name}: ${desc}`) .join("\n")} **Quick Start:** 1. Use @enforcer for code quality validation 2. Use @orchestrator for complex task coordination 3. Use skills for specialized capabilities 4. Check framework-reporting-system for activity reports `.trim(); } private generateFullCapabilities(capabilities: CapabilitiesMap, format: string): string { if (format === "detailed") { return ` **0xRay Framework - Complete Capabilities Overview** **${Object.keys(capabilities.agents).length} Specialized Agents:** ${Object.entries(capabilities.agents) .map(([name, desc]) => `- **${name}**: ${desc}`) .join("\n")} **23 Skills (Lazy Loading):** ${Object.entries(capabilities.skills) .map(([name, desc]) => `- **${name}**: ${desc}`) .join("\n")} **System Commands:** ${Object.entries(capabilities.commands) .map(([name, desc]) => `- **${name}**: ${desc}`) .join("\n")} **Reporting & Monitoring:** ${Object.entries(capabilities.reporting) .map(([name, desc]) => `- **${name}**: ${desc}`) .join("\n")} **Key Features:** - 99.6% error prevention through codex compliance - 90% resource reduction (0 baseline processes) - Enterprise-grade multi-agent orchestration - Systematic code quality enforcement - Real-time activity monitoring and reporting **Getting Started:** 1. Use @enforcer to validate code quality 2. Use @orchestrator for complex development tasks 3. Access skills for specialized capabilities 4. Check framework-reporting-system for comprehensive reports `.trim(); } else { return ` **0xRay Framework Capabilities:** **${this.getActiveAgentEntries().length} Agents:** ${this.getActiveAgentEntries().map((e: { name: string }) => e.name).join(", ")} **23 Skills:** project-analysis, testing-strategy, code-review, security-audit, performance-optimization, refactoring-strategies, ui-ux-design, documentation-generation, and more **System Tools:** framework-reporting-system, complexity-analyzer, codex-injector **Reporting:** Activity logs, performance metrics, error tracking, test coverage **Enterprise Features:** 99.6% error prevention, 90% resource optimization, multi-agent orchestration `.trim(); } } private generateCategoryCapabilities( capabilities: CapabilitiesMap, category: string, format: string, ): string { const categoryData = capabilities[category as keyof CapabilitiesMap]; if (!categoryData) { return `Category "${category}" not found. Available categories: agents, skills, commands, reporting`; } const items = Object.entries(categoryData); return ` **0xRay ${category.charAt(0).toUpperCase() + category.slice(1)}:** ${items.map(([name, desc]) => `- **${name}**: ${desc}`).join("\n")} **Total:** ${items.length} ${category} `.trim(); } } // Auto-start if this file is run directly - conditional server initialization for development/testing if (import.meta.url === `file://${fs.realpathSync(process.argv[1]!)}`) { const server = new FrameworkHelpServer(); server.run().catch((error) => frameworkLogger.log("mcps/framework-help", "run", "error", { error: String(error) })); } export { FrameworkHelpServer };