@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
66 lines • 2.67 kB
JavaScript
import { AuthenticationClient, ManagementClient } from 'auth0';
import { packageVersion } from './package.js';
/**
* Generates a standardized User-Agent string for API requests.
*
* This function constructs a User-Agent header value that identifies the application
* making requests to Auth0 APIs. The format follows standard conventions:
* "application-name/version (runtime/runtime-version)"
*
* @returns {string} Formatted User-Agent string containing the application name,
* version, and Node.js runtime version
* @example
* // Example usage in headers for an API request
* const headers = {
* 'Content-Type': 'application/json',
* 'User-Agent': getUserAgent()
* };
* // Could produce: "auth0-mcp-server/1.2.3 (node.js/16.14.0)"
*/
function getUserAgent() {
return `auth0-mcp-server/${packageVersion} (node.js/${process.version.replace('v', '')})`;
}
/**
* Creates and configures an Auth0 Management API client for making API calls.
*
* This function initializes a ManagementClient with proper authentication,
* retry logic (10 retries), and user agent information. The client provides
* methods for interacting with all Management API endpoints to manage resources
* in your Auth0 tenant.
*
* @param {Auth0Config} config - Configuration object containing:
* - domain: The Auth0 domain name (e.g., 'your-tenant.auth0.com')
* - token: A valid Auth0 Management API access token with appropriate scopes
* @returns {Promise<ManagementClient>} A configured Auth0 Management API client
* ready to make authenticated requests to the Auth0 Management API.
*/
export const getManagementClient = async (config, additionalHeaders) => {
return new ManagementClient({
domain: config.domain,
token: config.token,
retry: { maxRetries: 10, enabled: true },
headers: {
...(additionalHeaders ?? {}),
'User-agent': getUserAgent(),
},
});
};
/**
* Creates and configures an Auth0 Authentication API client.
*
* @param {string} domain - The Auth0 domain (e.g., 'your-tenant.auth0.com')
* @param {string} [clientId] - Optional client ID for authentication operations
* @param {string} [clientSecret] - Optional client secret for server-to-server operations
* @returns {Promise<AuthenticationClient>} Configured Auth0 Authentication API client
*/
export const getAuthenticationClient = async (domain, clientId, clientSecret) => {
return new AuthenticationClient({
domain,
headers: {
'User-agent': getUserAgent(),
},
clientId,
clientSecret,
});
};
//# sourceMappingURL=auth0-client.js.map