@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
89 lines (81 loc) • 3.67 kB
JavaScript
"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 aws_sso_accounts_controller_js_1 = __importDefault(require("../controllers/aws.sso.accounts.controller.js"));
const zod_1 = require("zod");
/**
* 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
* @param _args Tool arguments (none required)
* @param _extra Extra request handler information
* @returns MCP response with accounts and roles
*/
async function handleListAccounts(_args, _extra) {
const listAccountsLogger = logger_util_js_1.Logger.forContext('tools/aws.sso.accounts.tool.ts', 'handleListAccounts');
listAccountsLogger.debug('Handling list accounts request');
try {
const response = await aws_sso_accounts_controller_js_1.default.listAccounts();
return {
content: [
{
type: 'text',
text: response.content,
},
],
metadata: response.metadata,
};
}
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');
// Define schema for the list_accounts tool
const ListAccountsArgs = zod_1.z.object({
// No parameters - always list all accounts with all roles
});
// Register the AWS SSO list accounts tool
server.tool('list_accounts', `List all AWS accounts and roles available via SSO.
PURPOSE: Provides a comprehensive view of all AWS accounts you have access to via SSO,
along with the roles available in each account.
WHEN TO USE:
- After authenticating with AWS SSO
- When you need to see all available accounts and roles in one view
- To get an overview of your AWS SSO access permissions
WHEN NOT TO USE:
- Before authenticating with AWS SSO
NOTES:
- Results are cached to avoid rate limits with the AWS SSO API
- This tool automatically retrieves all roles for all accounts in a single call
RETURNS: Markdown output with a detailed list of all accounts and the roles available in each account.
EXAMPLES:
- List all accounts and roles: {}
ERRORS:
- Authentication required: You must login first using login
- Rate limiting: If you have a large number of accounts, the AWS API may return rate limit errors`, ListAccountsArgs.shape, handleListAccounts);
registerLogger.debug('AWS SSO accounts tools registered');
}
// Export the register function
exports.default = { registerTools };