UNPKG

remcode

Version:

Turn your AI assistant into a codebase expert. Intelligent code analysis, semantic search, and software engineering guidance through MCP integration.

102 lines (101 loc) โ€ข 5.38 kB
"use strict"; /** * MCP Inspector Command * * Command to start MCP-compatible SSE server for MCP Inspector integration */ var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.inspectorCommand = inspectorCommand; const chalk_1 = __importDefault(require("chalk")); const child_process_1 = require("child_process"); const logger_1 = require("../utils/logger"); const logger = (0, logger_1.getLogger)('Inspector-Command'); function inspectorCommand(program) { program .command('inspector') .description('Start MCP Server with MCP Inspector compatible SSE transport') .option('--no-browser', 'Don\'t automatically open browser') .option('--port <port>', 'MCP server port', '3008') .action(async (options) => { console.log(chalk_1.default.cyan('๐Ÿงช Starting MCP-Compatible Server for Inspector Integration...\n')); console.log(chalk_1.default.yellow('๐Ÿ“‹ MCP Inspector Setup Instructions:')); console.log(' 1. Run this command to start the MCP server'); console.log(' 2. Open MCP Inspector: npx @modelcontextprotocol/inspector'); console.log(' 3. Select "SSE" transport type'); console.log(` 4. Enter server URL: http://localhost:${options.port || '3008'}/sse`); console.log(' 5. Click "Connect" to establish connection'); console.log(''); try { const port = options.port || '3008'; console.log(chalk_1.default.green(`๐Ÿš€ Starting MCP Server on port ${port}...`)); console.log(chalk_1.default.gray(' JSON-RPC 2.0 over SSE protocol enabled')); console.log(''); // Start the MCP server with MCP-compatible SSE const serverProcess = (0, child_process_1.spawn)('node', [ 'bin/remcode.js', 'serve', '--port', port, '--skip-token-collection' ], { stdio: 'inherit', cwd: process.cwd() }); // Give server time to start setTimeout(() => { console.log(''); console.log(chalk_1.default.green('โœ… MCP-Compatible SSE Server Running!')); console.log(''); console.log(chalk_1.default.cyan('๐Ÿ”— MCP Inspector Connection:')); console.log(chalk_1.default.white(` Transport: SSE`)); console.log(chalk_1.default.white(` Server URL: http://localhost:${port}/sse`)); console.log(''); console.log(chalk_1.default.cyan('๐Ÿ›  Available Endpoints:')); console.log(chalk_1.default.white(` ๐Ÿ“Š Health Check: http://localhost:${port}/health`)); console.log(chalk_1.default.white(` ๐Ÿ“‹ MCP Spec: http://localhost:${port}/mcp/spec`)); console.log(chalk_1.default.white(` ๐Ÿ”Œ SSE Connection: http://localhost:${port}/sse`)); console.log(chalk_1.default.white(` ๐Ÿ“จ MCP Messages: http://localhost:${port}/messages`)); console.log(''); console.log(chalk_1.default.yellow('๐Ÿงช MCP Inspector Usage:')); console.log(chalk_1.default.gray(' 1. npx @modelcontextprotocol/inspector')); console.log(chalk_1.default.gray(' 2. Transport: SSE')); console.log(chalk_1.default.gray(` 3. URL: http://localhost:${port}/sse`)); console.log(chalk_1.default.gray(' 4. Connect and test tools!')); console.log(''); console.log(chalk_1.default.green('๐ŸŽฏ No STDIO Bridge Required - Direct JSON-RPC 2.0 over SSE!')); console.log(chalk_1.default.yellow('Press Ctrl+C to stop the server')); }, 2000); // Handle process events serverProcess.on('error', (error) => { console.error(chalk_1.default.red('โŒ Failed to start MCP Server:'), error.message); process.exit(1); }); serverProcess.on('close', (code) => { if (code === 0) { console.log(chalk_1.default.green('\nโœ… MCP Server stopped successfully')); } else { console.log(chalk_1.default.yellow(`\nโš  MCP Server exited with code ${code}`)); } }); // Handle graceful shutdown process.on('SIGINT', () => { console.log(chalk_1.default.yellow('\n๐Ÿ›‘ Shutting down MCP Server...')); serverProcess.kill('SIGINT'); }); process.on('SIGTERM', () => { serverProcess.kill('SIGTERM'); }); } catch (error) { console.error(chalk_1.default.red('โŒ Error starting MCP Server:'), error instanceof Error ? error.message : String(error)); console.log(''); console.log(chalk_1.default.yellow('๐Ÿ’ก Manual start option:')); console.log(chalk_1.default.gray(' node bin/remcode.js serve --port 3008')); console.log(chalk_1.default.gray(' Then connect to: http://localhost:3008/sse/connect')); process.exit(1); } }); }