UNPKG

safe-commander-mcp

Version:

A secure MCP server for executing whitelisted development commands with comprehensive security controls and resource limits

49 lines (48 loc) 2.33 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.startMCPServer = startMCPServer; const index_js_1 = require("@modelcontextprotocol/sdk/server/index.js"); const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js"); const config_loader_1 = require("../config/config-loader"); const startup_validator_1 = require("../config/startup-validator"); const shutdown_handler_1 = require("../utils/shutdown-handler"); const request_handlers_1 = require("./request-handlers"); const logger_1 = require("../utils/logger"); // Direct require for package.json in CommonJS - fix path for compiled output const packageJson = require('../../../package.json'); /** * Start the MCP server with full initialization * This is the main entry point for the server startup process */ async function startMCPServer() { try { // Initialize configuration and validation (0, logger_1.log)('info', 'Initializing Safe Commander MCP server...'); // Validate critical configuration first (0, config_loader_1.validateCriticalConfig)(); // Load configuration and setup shutdown handlers (0, config_loader_1.loadConfig)(); (0, shutdown_handler_1.setupGracefulShutdown)(); // Run comprehensive startup validation (0, startup_validator_1.validateStartupConfiguration)(); // Create the MCP server const server = new index_js_1.Server({ name: packageJson.name, version: packageJson.version }, { capabilities: { tools: {} } }); // Setup request handlers (0, request_handlers_1.setupRequestHandlers)(server); // Start the server (0, logger_1.log)('info', 'Starting MCP server...', { name: packageJson.name, version: packageJson.version, nodeVersion: process.version, platform: process.platform }); const transport = new stdio_js_1.StdioServerTransport(); await server.connect(transport); (0, logger_1.log)('info', 'MCP server started successfully and ready to accept requests'); } catch (error) { const errorMessage = error instanceof Error ? error.message : 'Unknown startup error'; (0, logger_1.log)('error', 'Failed to start MCP server', { error: errorMessage }); throw error; } }