UNPKG

@aashari/mcp-server-aws-sso

Version:

Node.js/TypeScript MCP server for AWS Single Sign-On (SSO). Enables AI systems (LLMs) with tools to initiate SSO login (device auth flow), list accounts/roles, and securely execute AWS CLI commands using temporary credentials. Streamlines AI interaction w

123 lines (122 loc) 5.78 kB
#!/usr/bin/env node "use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PACKAGE_NAME = exports.Logger = exports.config = void 0; exports.startServer = startServer; const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js"); const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js"); const logger_util_js_1 = require("./utils/logger.util.js"); Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return logger_util_js_1.Logger; } }); const config_util_js_1 = require("./utils/config.util.js"); Object.defineProperty(exports, "config", { enumerable: true, get: function () { return config_util_js_1.config; } }); const error_util_js_1 = require("./utils/error.util.js"); const constants_util_js_1 = require("./utils/constants.util.js"); const index_js_1 = require("./cli/index.js"); const aws_sso_auth_tool_js_1 = __importDefault(require("./tools/aws.sso.auth.tool.js")); const aws_sso_accounts_tool_js_1 = __importDefault(require("./tools/aws.sso.accounts.tool.js")); const aws_sso_exec_tool_js_1 = __importDefault(require("./tools/aws.sso.exec.tool.js")); /** * MCP Server for AWS SSO * * Provides tools for authentication with AWS SSO and executing AWS CLI commands * with temporary credentials from SSO. */ // Create file-level logger const indexLogger = logger_util_js_1.Logger.forContext('index.ts'); // Log initialization at debug level indexLogger.debug('AWS SSO MCP server module loaded'); let serverInstance = null; let transportInstance = null; /** * Start the MCP server with the specified transport mode * * @param mode The transport mode to use (stdio or sse) * @returns Promise that resolves when the server is started */ async function startServer(mode = 'stdio') { const serverLogger = logger_util_js_1.Logger.forContext('index.ts', 'startServer'); // Load configuration serverLogger.info('Starting MCP server initialization...'); config_util_js_1.config.load(); serverLogger.info('Configuration loaded successfully'); // Enable debug logging if DEBUG is set to true if (config_util_js_1.config.getBoolean('DEBUG')) { serverLogger.debug('Debug mode enabled'); } // Log the DEBUG value to verify configuration loading serverLogger.debug(`DEBUG environment variable: ${process.env.DEBUG}`); serverLogger.debug(`AWS_SSO_START_URL value exists: ${Boolean(process.env.AWS_SSO_START_URL)}`); serverLogger.debug(`Config DEBUG value: ${config_util_js_1.config.get('DEBUG')}`); serverLogger.info(`Initializing AWS SSO MCP server v${constants_util_js_1.VERSION}`); serverInstance = new mcp_js_1.McpServer({ name: constants_util_js_1.PACKAGE_NAME, version: constants_util_js_1.VERSION, }); if (mode === 'stdio') { serverLogger.info('Using STDIO transport for MCP communication'); transportInstance = new stdio_js_1.StdioServerTransport(); } else { throw (0, error_util_js_1.createUnexpectedError)('SSE mode is not supported yet'); } // Register tools serverLogger.info('Registering MCP tools...'); // register authentication tools aws_sso_auth_tool_js_1.default.registerTools(serverInstance); serverLogger.debug('Registered AWS SSO authentication tools'); // register accounts tools aws_sso_accounts_tool_js_1.default.registerTools(serverInstance); serverLogger.debug('Registered AWS SSO accounts tools'); // register exec tools aws_sso_exec_tool_js_1.default.registerTools(serverInstance); serverLogger.debug('Registered AWS SSO exec tools'); serverLogger.info('All tools registered successfully'); try { serverLogger.info(`Connecting to ${mode.toUpperCase()} transport...`); await serverInstance.connect(transportInstance); serverLogger.info('MCP server started successfully and ready to process requests'); return serverInstance; } catch (err) { serverLogger.error(`Failed to start server`, err); process.exit(1); } } /** * Main entry point - this will run when executed directly * Determines whether to run in CLI or server mode based on command-line arguments */ async function main() { const mainLogger = logger_util_js_1.Logger.forContext('index.ts', 'main'); // Load configuration config_util_js_1.config.load(); // Log the DEBUG value to verify configuration loading mainLogger.debug(`DEBUG environment variable: ${process.env.DEBUG}`); mainLogger.debug(`AWS_SSO_START_URL value exists: ${Boolean(process.env.AWS_SSO_START_URL)}`); mainLogger.debug(`Config DEBUG value: ${config_util_js_1.config.get('DEBUG')}`); // Check if arguments are provided (CLI mode) if (process.argv.length > 2) { // CLI mode: Pass arguments to CLI runner mainLogger.info('Starting in CLI mode'); await (0, index_js_1.runCli)(process.argv.slice(2)); mainLogger.info('CLI execution completed'); } else { // MCP Server mode: Start server with default STDIO mainLogger.info('Starting in server mode'); await startServer(); mainLogger.info('Server is now running'); } } // If this file is being executed directly (not imported), run the main function if (require.main === module) { main().catch((err) => { indexLogger.error('Unhandled error in main process', err); process.exit(1); }); } var constants_util_js_2 = require("./utils/constants.util.js"); Object.defineProperty(exports, "PACKAGE_NAME", { enumerable: true, get: function () { return constants_util_js_2.PACKAGE_NAME; } });