Class McpOAuthDiscovery

java.lang.Object
com.tnsai.mcp.auth.McpOAuthDiscovery

public class McpOAuthDiscovery extends Object
RFC 8414 OAuth Authorization Server Metadata discovery.

Discovers OAuth metadata from a server URL by checking the well-known OAuth authorization server metadata endpoint. This enables MCP clients to automatically configure OAuth authentication without manual endpoint setup.

Usage:


 OAuthMetadata metadata = McpOAuthDiscovery.discover("https://mcp.example.com");
 String authEndpoint = metadata.authorizationEndpoint();
 String tokenEndpoint = metadata.tokenEndpoint();
 
See Also:
  • Constructor Details

    • McpOAuthDiscovery

      public McpOAuthDiscovery()
  • Method Details

    • discover

      public static McpOAuthDiscovery.OAuthMetadata discover(String serverUrl) throws IOException
      Discovers OAuth metadata from a server URL.

      Checks .well-known/oauth-authorization-server on the given server URL and parses the returned JSON metadata document.

      Parameters:
      serverUrl - the base URL of the MCP server
      Returns:
      the discovered OAuth metadata
      Throws:
      IOException - if the discovery request fails or the response is invalid