jay-code
Version:
Streamlined AI CLI orchestration engine with mathematical rigor and enterprise-grade reliability
121 lines (103 loc) ⢠3.92 kB
text/typescript
/**
* 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;
}