@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
89 lines • 3.68 kB
JavaScript
import chalk from 'chalk';
import { log, logError } from '../utils/logger.js';
import { cliOutput } from '../utils/terminal.js';
import { keychain, KeychainItem } from '../utils/keychain.js';
import { revokeRefreshToken } from '../auth/device-auth-flow.js';
/**
* Maps technical keychain item names to user-friendly descriptions
* @param item - The keychain item key
* @returns A user-friendly description of the item
*/
const getItemDescription = (item) => {
const descriptions = {
[KeychainItem.TOKEN]: 'access token',
[KeychainItem.REFRESH_TOKEN]: 'refresh token',
[KeychainItem.DOMAIN]: 'domain information',
[KeychainItem.TOKEN_EXPIRES_AT]: 'token expiration',
};
return descriptions[item] ?? item;
};
/**
* Creates a formatted message for successful token removal
* @param successfulItems - Array of successfully removed items
* @returns A formatted success message
*/
const createSuccessMessage = (successfulItems) => {
if (successfulItems.length === 0)
return '';
const tokenNames = successfulItems.map((result) => getItemDescription(result.item));
return `${chalk.green('✓')} Successfully removed ${tokenNames.join(', ')} from your system keychain.\n`;
};
/**
* Creates a formatted message for items that failed to be removed
* @param failedItems - Array of items that failed to be removed
* @returns A formatted error message
*/
const createErrorMessage = (failedItems) => {
if (failedItems.length === 0)
return '';
const errorLines = failedItems.map((result) => `${chalk.red('✗')} ${getItemDescription(result.item)}: ${result.error?.message ?? 'Unknown error'}`);
return [
`${chalk.yellow('!')} Some credentials could not be removed and may require manual cleanup:`,
...errorLines,
`\n${chalk.blue('i')} To manually remove credentials, use your system's keychain manager and search for 'auth0-mcp'.`,
].join('\n');
};
/**
* Categorizes deletion results into successful and failed operations
* @param results - Array of keychain operation results
* @returns Object containing arrays of successful and failed operations
*/
const categorizeResults = (results) => {
return {
successful: results.filter((result) => result.success),
failed: results.filter((result) => !result.success),
};
};
/**
* Removes all Auth0 MCP related tokens from the system keychain
*
* @param {LogoutOptions} _options - Command options from commander (unused)
* @returns A promise that resolves when logout is complete
*/
async function logout(_options) {
try {
log('Removing Auth0 tokens from keychain');
cliOutput(`\n${chalk.blue('i')} Clearing authentication data...\n`);
log('Revoke refresh token if present');
await revokeRefreshToken();
// Delete all items from the keychain
const deletionResults = await keychain.clearAll();
const { successful, failed } = categorizeResults(deletionResults);
if (successful.length > 0) {
cliOutput(createSuccessMessage(successful));
}
else if (deletionResults.length === failed.length) {
cliOutput(`${chalk.yellow('!')} No Auth0 MCP authentication data was found in your system keychain.\n`);
}
if (failed.length > 0) {
cliOutput(createErrorMessage(failed));
}
}
catch (error) {
logError('Error during logout:', error);
cliOutput(`\n${chalk.red('✗')} Failed to clear authentication data. ${error instanceof Error ? error.message : ''}\n`);
process.exit(1);
}
}
export default logout;
//# sourceMappingURL=logout.js.map