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

77 lines (73 loc) 3.25 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const logger_util_js_1 = require("../utils/logger.util.js"); const error_util_js_1 = require("../utils/error.util.js"); const formatter_util_js_1 = require("../utils/formatter.util.js"); const aws_sso_types_js_1 = require("./aws.sso.types.js"); const aws_sso_accounts_controller_js_1 = __importDefault(require("../controllers/aws.sso.accounts.controller.js")); /** * AWS SSO Accounts Tool Module * * Provides MCP tools for listing and exploring AWS accounts and roles * available through AWS SSO. These tools enable AI models to discover and * access AWS resources with temporary credentials. */ // Create a module logger const toolLogger = logger_util_js_1.Logger.forContext('tools/aws.sso.accounts.tool.ts'); // Log module initialization toolLogger.debug('AWS SSO accounts tool module initialized'); /** * Handles the AWS SSO list accounts tool * Lists all available AWS accounts and their roles * @returns MCP response with accounts and roles */ async function handleListAccounts() { const listAccountsLogger = logger_util_js_1.Logger.forContext('tools/aws.sso.accounts.tool.ts', 'handleListAccounts'); listAccountsLogger.debug('Handling list accounts request'); try { // Call controller with no arguments const response = await aws_sso_accounts_controller_js_1.default.listAccounts(); return { content: [ { type: 'text', text: (0, formatter_util_js_1.truncateForAI)(response.content, response.rawResponsePath), }, ], }; } catch (error) { listAccountsLogger.error('List accounts failed', error); return (0, error_util_js_1.formatErrorForMcpTool)(error); } } /** * Register AWS SSO accounts tools with the MCP server * @param server MCP server instance */ function registerTools(server) { const registerLogger = logger_util_js_1.Logger.forContext('tools/aws.sso.accounts.tool.ts', 'registerTools'); registerLogger.debug('Registering AWS SSO accounts tools'); const LIST_ACCOUNTS_DESCRIPTION = `List all AWS accounts and roles accessible through AWS SSO. Provides essential information needed for \`aws_sso_exec_command\`: - Fetches all accessible accounts with IDs, names, and emails - Retrieves all available roles for each account - Handles pagination internally - Caches account and role information Prerequisites: - MUST first authenticate using \`aws_sso_login\` - AWS SSO must be configured with a start URL and region Returns: Account list with IDs, names, roles, and session status`; // Register the AWS SSO list accounts tool using modern registerTool API server.registerTool('aws_sso_ls_accounts', { title: 'AWS SSO List Accounts', description: LIST_ACCOUNTS_DESCRIPTION, inputSchema: aws_sso_types_js_1.ListAccountsArgsSchema, }, handleListAccounts); registerLogger.debug('AWS SSO accounts tools registered'); } // Export the register function exports.default = { registerTools };