McpOAuth
MCP authorization (OAuth 2.1) discovery and client registration, per the MCP authorization spec:
Protected Resource Metadata (RFC 9728) from the 401 challenge's
resource_metadata, else the well-known URIs of the server URL;Authorization Server Metadata (RFC 8414, then OpenID Connect discovery); PKCE
S256support is required;Dynamic Client Registration (RFC 7591) as a public client with a loopback redirect (RFC 8252), unless a client id is supplied.
Then run McpOAuthRegistration.flow with OAuthClient and keep the tokens in a TokenStore behind McpOAuthTokens.
Functions
Link copied to clipboard
suspend fun discover(serverUrl: String, resourceMetadataUrl: String? = null, scope: String? = null, redirect: LoopbackRedirect, clientName: String = "AI Elements", clientId: String? = null): McpOAuthRegistration