UNPKG

jay-code

Version:

Streamlined AI CLI orchestration engine with mathematical rigor and enterprise-grade reliability

121 lines (103 loc) • 3.92 kB
/** * Simple MCP command implementation for Node.js compatibility */ import { Command } from 'commander'; import http from 'http'; function printSuccess(message: string) { console.log(`āœ… ${message}`); } function printError(message: string) { console.error(`āŒ Error: ${message}`); } // Check if MCP server is running async function checkMCPStatus(host: string, port: number): Promise<boolean> { return new Promise((resolve) => { const options = { hostname: host, port: port, path: '/health', method: 'GET', timeout: 2000, }; const req = http.request(options, (res) => { resolve(res.statusCode === 200 || res.statusCode === 404); }); req.on('error', () => { resolve(false); }); req.on('timeout', () => { req.destroy(); resolve(false); }); req.end(); }); } export function createMCPCommand() { const mcpCmd = new Command('mcp').description('Manage MCP server and tools').action(() => { printSuccess('MCP Server Management'); console.log('\n🌐 Available MCP commands:'); console.log(' • mcp start - Start the MCP server'); console.log(' • mcp status - Show MCP server status'); console.log(' • mcp tools - List available MCP tools'); console.log(' • mcp stop - Stop the MCP server'); console.log('\nšŸ’” Use "mcp start --port 3001" to use a different port'); }); mcpCmd .command('start') .description('Start the MCP server') .option('--port <port>', 'Port for MCP server', '3000') .option('--host <host>', 'Host for MCP server', 'localhost') .option('--transport <transport>', 'Transport type (stdio, http)', 'http') .action(async (options) => { // This is handled by the actual MCP implementation console.log('Starting MCP server...'); console.log('(This command is handled by the MCP module)'); }); mcpCmd .command('status') .description('Show MCP server status') .option('--port <port>', 'Port to check', '3000') .option('--host <host>', 'Host to check', 'localhost') .action(async (options) => { printSuccess('MCP Server Status:'); const host = options.host || 'localhost'; const port = parseInt(options.port) || 3000; // Check if server is actually running const isRunning = await checkMCPStatus(host, port); if (isRunning) { console.log('🟢 Status: Running'); console.log(`šŸ“ Address: ${host}:${port}`); console.log('šŸ” Authentication: Disabled'); console.log('šŸ”§ Tools: System, Health, Tools'); console.log('šŸ“” Transport: http'); console.log('\nšŸ’” Use "mcp tools" to see available tools'); } else { console.log('🟔 Status: Not running (use "mcp start" to start)'); console.log(`šŸ“ Checked address: ${host}:${port}`); console.log('šŸ” Authentication: Disabled'); console.log('šŸ”§ Tools: System, Health, Tools (when running)'); } }); mcpCmd .command('tools') .description('List available MCP tools') .action(() => { printSuccess('Available MCP Tools:'); console.log('\nšŸ“Š System Tools:'); console.log(' • system/info - Get system information'); console.log(' • system/health - Get system health status'); console.log('\nšŸ”§ Tool Management:'); console.log(' • tools/list - List all available tools'); console.log(' • tools/schema - Get schema for a specific tool'); console.log('\nšŸ’” Note: Additional tools available when orchestrator is running'); }); mcpCmd .command('stop') .description('Stop the MCP server') .action(() => { printSuccess('Stopping MCP server...'); console.log('šŸ›‘ MCP server stop requested'); console.log('šŸ’” Use Ctrl+C in the terminal running "mcp start" to stop'); }); return mcpCmd; }