UNPKG

@auth0/auth0-mcp-server

Version:

Auth0 Model Context Protocol (MCP) Server (Beta) — A secure and extendable implementation of an MCP server that provides AI assistants with controlled access to the Auth0 Management API through natural language. This project is in beta and not intended fo

97 lines • 3.33 kB
import chalk from 'chalk'; import { keychain } from '../utils/keychain.js'; import { cliOutput } from '../utils/terminal.js'; import { log } from '../utils/logger.js'; /** * Formats a date for display in user-friendly format * @param timestamp - The timestamp to format * @returns A formatted date string */ const formatDate = (timestamp) => { return new Date(timestamp).toLocaleString(); }; /** * Creates a message for when no active session is found * @returns A formatted message string */ const createNoSessionMessage = () => { return [ `\n${chalk.yellow('!')} No active authentication session found.\n`, `Run ${chalk.cyan('npx @auth0/auth0-mcp-server init')} to authenticate.\n`, ].join(''); }; /** * Creates a header for the session information display * @param domain - The authenticated domain * @returns A formatted header string */ const createSessionHeader = (domain) => { return [ `\n${chalk.green('✓')} Active authentication session:\n`, `${chalk.bold('Domain:')} ${domain}\n`, ].join(''); }; /** * Creates a message about token expiration status * @param expiresAt - The timestamp when the token expires * @returns A formatted expiration message */ const createExpirationMessage = (expiresAt) => { const now = Date.now(); const expiresIn = expiresAt - now; if (expiresIn > 0) { const hoursRemaining = Math.floor(expiresIn / (1000 * 60 * 60)); return `${chalk.bold('Token expires:')} in ${hoursRemaining} hours (${formatDate(expiresAt)})\n`; } else { return `${chalk.bold('Token status:')} ${chalk.red('Expired')} on ${formatDate(expiresAt)}\n`; } }; /** * Creates a footer with logout instructions * @returns A formatted instruction string */ const createLogoutInstructions = () => { return `\nTo use different credentials, run ${chalk.cyan('npx @auth0/auth0-mcp-server logout')}\n`; }; /** * Creates an error message when session info can't be retrieved * @returns A formatted error message */ const createErrorMessage = () => { return `\n${chalk.red('✗')} Failed to retrieve session information.\n`; }; /** * Displays information about the current authentication session * * @param {SessionOptions} _options - Command options from commander (unused) * @returns A promise that resolves when the display is complete */ async function session(_options) { try { log('Retrieving session information'); // Get session data from keychain const token = await keychain.getToken(); const domain = await keychain.getDomain(); const expiresAt = await keychain.getTokenExpiresAt(); // Handle case where no session exists if (!token || !domain) { cliOutput(createNoSessionMessage()); return; } // Display session information cliOutput(createSessionHeader(domain)); // Add expiration information if available if (expiresAt) { cliOutput(createExpirationMessage(expiresAt)); } // Add logout instructions cliOutput(createLogoutInstructions()); } catch (error) { log('Error retrieving session information:', error); cliOutput(createErrorMessage()); } } export default session; //# sourceMappingURL=session.js.map