AshAi.Mcp.OAuth.Registration (ash_ai v1.5.6)

Copy Markdown View Source

Obtains a client ID from an authorization server.

Follows the spec's priority order: a pre-registered client, then a Client ID Metadata Document when the server supports them, then a client registered earlier through Dynamic Client Registration, then a new registration. With none of these available it returns {:error, :client_registration_required}, and the application has to ask for client credentials and supply them through :pre_registered.

Pre-registered credentials and dynamic registrations both belong to one MCP server. A server that names another server's authorization server can't use the credentials configured for that server, and gets a registration of its own, so the authorization server asks the user for consent instead of reusing a grant made for the other server.

Summary

Functions

The Client ID Metadata Document to serve at :client_metadata_url.

Registers a new client for server through Dynamic Client Registration (RFC 7591) and stores it.

Finds the client client_id that server used with issuer again, for example when exchanging an authorization code or refreshing a token.

Selects or registers a client for the MCP server server (its canonical resource URI) and the authorization server described by metadata (validated authorization server metadata).

Functions

client_metadata_document(opts)

@spec client_metadata_document(keyword()) :: map()

The Client ID Metadata Document to serve at :client_metadata_url.

Uses :client_metadata_url (required), :client_name, :redirect_uris (or :redirect_uri), :client_uri, and :logo_uri. The client is public and authenticates with PKCE alone.

register(server, metadata, redirect_uri, opts)

@spec register(String.t(), map(), String.t(), keyword()) ::
  {:ok, AshAi.Mcp.OAuth.Client.t()} | {:error, term()}

Registers a new client for server through Dynamic Client Registration (RFC 7591) and stores it.

resolve_client(server, issuer, client_id, opts)

@spec resolve_client(String.t(), String.t(), String.t(), keyword()) ::
  {:ok, AshAi.Mcp.OAuth.Client.t()} | {:error, :unknown_client}

Finds the client client_id that server used with issuer again, for example when exchanging an authorization code or refreshing a token.

select_client(server, metadata, redirect_uri, opts)

@spec select_client(String.t(), map(), String.t(), keyword()) ::
  {:ok, AshAi.Mcp.OAuth.Client.t()} | {:error, term()}

Selects or registers a client for the MCP server server (its canonical resource URI) and the authorization server described by metadata (validated authorization server metadata).