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

105 lines (104 loc) 4.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.formatAuthRequired = formatAuthRequired; exports.formatCommandOutput = formatCommandOutput; exports.formatExecResult = formatExecResult; const logger_util_js_1 = require("../utils/logger.util.js"); const formatter_util_js_1 = require("../utils/formatter.util.js"); /** * Format authentication required message * * Creates a standardized message indicating AWS SSO authentication is required * before command execution can proceed. * * @returns {string} Formatted authentication required message in markdown */ function formatAuthRequired() { const methodLogger = logger_util_js_1.Logger.forContext('controllers/aws.sso.exec.formatter.ts', 'formatAuthRequired'); methodLogger.debug('Formatting auth required message'); const lines = [ (0, formatter_util_js_1.formatHeading)('Authentication Required', 1), '', 'You need to authenticate with AWS SSO first.', '', 'Please use the `login` command to authenticate.', '', ]; return lines.join('\n'); } /** * Format command execution output * * Creates a detailed Markdown representation of command execution results, * including the command that was run, exit code, and standard output/error streams. * * @param {string} command - Command that was executed * @param {string} stdout - Standard output from the command * @param {string} stderr - Standard error from the command * @param {number} exitCode - Exit code from the command * @returns {string} Formatted command execution output in markdown */ function formatCommandOutput(command, stdout, stderr, exitCode) { const methodLogger = logger_util_js_1.Logger.forContext('controllers/aws.sso.exec.formatter.ts', 'formatCommandOutput'); methodLogger.debug('Formatting command output', { commandLength: command.length, stdoutLength: stdout.length, stderrLength: stderr.length, exitCode, }); const lines = [ (0, formatter_util_js_1.formatHeading)('AWS CLI Command Execution', 1), '', `Command: \`${command}\``, '', (0, formatter_util_js_1.formatHeading)(`Result: ${exitCode === 0 ? 'Success' : 'Failed'} (Exit Code: ${exitCode})`, 2), '', ]; // Format standard output if present if (stdout.trim()) { lines.push((0, formatter_util_js_1.formatHeading)('Standard Output (stdout)', 3)); lines.push(''); lines.push((0, formatter_util_js_1.formatCodeBlock)(stdout)); lines.push(''); } // Format standard error if present if (stderr.trim()) { lines.push((0, formatter_util_js_1.formatHeading)('Standard Error (stderr)', 3)); lines.push(''); lines.push((0, formatter_util_js_1.formatCodeBlock)(stderr)); lines.push(''); } // Add footer separator if both stdout and stderr are present if (stdout.trim() && stderr.trim()) { lines.push((0, formatter_util_js_1.formatSeparator)()); lines.push(''); } // Add contextual information for errors if (exitCode !== 0) { lines.push((0, formatter_util_js_1.formatHeading)('Execution Failed', 3)); lines.push(''); lines.push('The AWS CLI command returned a non-zero exit code, indicating an error.'); // Include common error resolution tips lines.push(''); lines.push((0, formatter_util_js_1.formatHeading)('Troubleshooting Tips', 4)); lines.push(''); lines.push((0, formatter_util_js_1.formatBulletList)({ 'Check credentials': 'Verify AWS SSO credentials are valid.', 'Check permissions': 'Ensure the role has permissions for this command.', 'Check command syntax': 'Verify AWS CLI command syntax is correct.', 'Check region': 'Verify the AWS region is valid and accessible.', })); lines.push(''); } return lines.join('\n'); } /** * Format command execution result into markdown * * @param command The command that was executed * @param result The result of the command execution * @returns Formatted output as Markdown */ function formatExecResult(command, result) { return formatCommandOutput(command, result.stdout, result.stderr, result.exitCode); }