MCP.OAuth2.Discovery (fnord v0.9.40)

View Source

OAuth2 server discovery and automatic configuration. Implements RFC 8414 Authorization Server Metadata discovery.

Summary

Functions

Discover OAuth2 configuration and set up authentication automatically.

Functions

discover_and_setup(base_url, opts \\ [])

@spec discover_and_setup(
  String.t(),
  keyword()
) :: {:ok, map()} | {:error, term()}

Discover OAuth2 configuration and set up authentication automatically.

Parameters

  • base_url: The MCP server's base URL
  • opts: Configuration options
    • :client_id - Use an existing client_id and skip dynamic registration
    • :client_secret - Client secret (optional)
    • :scope - List of scopes to request; if omitted, fnord prefers mcp:access when the server advertises it and otherwise falls back to the server's supported scopes
    • :redirect_port - Port to use for the loopback redirect URI; if present, the discovered config carries it forward and dynamic registration uses it for exact callback matching

Returns

  • {:ok, oauth_config} - Ready-to-use OAuth configuration map
  • {:error, reason} - Discovery or setup failed

OAuth Config Structure

%{

"discovery_url" => String.t(),
"client_id" => String.t(),
"client_secret" => String.t() | nil,
"scopes" => [String.t()]

}