# `AshAi.Mcp.OAuth.Registration`
[🔗](https://github.com/ash-project/ash_ai/blob/v1.5.6/lib/ash_ai/mcp/oauth/registration.ex#L6)

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.

# `client_metadata_document`

```elixir
@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`

```elixir
@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`

```elixir
@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`

```elixir
@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).

---

*Consult [api-reference.md](api-reference.md) for complete listing*
