Clears expired authorization states for cleanup.
User context
Optionalprovider: IMetadataProviderNumber of states cleared
Completes an OAuth authorization flow by exchanging the code for tokens.
Called by the OAuth callback handler after user consent.
The state parameter from the callback
The authorization code
User context
Completion result
Gets a valid access token for an OAuth-protected connection.
If valid tokens exist, returns the access token. If tokens are expired but refresh token is valid, refreshes and returns. If no valid tokens, throws OAuthAuthorizationRequiredError with authorization URL.
MCP Server Connection ID
MCP Server ID
OAuth configuration from MCP Server
MJAPI public URL for callbacks
User context
Valid access token
Gets the OAuth connection status.
MCP Server Connection ID
OAuth configuration
User context
Connection status
Handles an OAuth callback error.
The state parameter
OAuth error code
Error description
User context
Initiates an OAuth authorization flow.
Creates authorization URL with PKCE and stores state in database. The user should be redirected to the returned URL to complete consent.
MCP Server Connection ID
MCP Server ID
OAuth configuration
MJAPI public URL for callbacks
User context
Optionaloptions: { frontendCallbackUrl?: string; frontendReturnUrl?: string }Additional options
OptionalfrontendCallbackUrl?: stringURL to use as redirect_uri (frontend handles the callback)
OptionalfrontendReturnUrl?: stringURL to redirect to after OAuth completion
Authorization initiation result with URL
Marks a connection as requiring re-authorization.
Clears stored tokens and returns a message for the user.
MCP Server Connection ID
Reason for re-authorization
User context
Validates OAuth configuration for an MCP server.
OAuth configuration to validate
User context
Validation result
Main orchestrator for OAuth 2.1 flows in MCP connections.
Coordinates all OAuth operations including:
Example