# `ExMCP.Authorization.ServerConfig`
[🔗](https://github.com/azmaveth/ex_mcp/blob/v1.0.0/lib/ex_mcp/authorization/server_config.ex#L1)

Centralized configuration management for OAuth 2.1 authorization server settings.

This module provides a unified interface for managing OAuth authorization server
configurations including validation, runtime updates, and environment-based settings.
It supports multiple authorization servers and provides validation for security
requirements (HTTPS enforcement, etc.).

## Configuration Format

The configuration can be specified in multiple ways:

### Application Environment

    config :ex_mcp, ExMCP.Authorization.ServerConfig,
      default_server: :auth_server,
      servers: %{
        auth_server: %{
          introspection_endpoint: "https://auth.example.com/introspect",
          realm: "mcp-server",
          client_id: "mcp-server-id",
          client_secret: "server-secret"
        },
        backup_server: %{
          introspection_endpoint: "https://backup-auth.example.com/introspect",
          realm: "mcp-backup"
        }
      }

### Runtime Configuration

    ExMCP.Authorization.ServerConfig.put_server(:my_server, %{
      introspection_endpoint: "https://new-auth.example.com/introspect",
      realm: "my-realm"
    })

## Usage

    # Get default server config
    {:ok, config} = ExMCP.Authorization.ServerConfig.get_server()

    # Get specific server config
    {:ok, config} = ExMCP.Authorization.ServerConfig.get_server(:backup_server)

    # Validate configuration
    :ok = ExMCP.Authorization.ServerConfig.validate_config(config)

    # List all configured servers
    servers = ExMCP.Authorization.ServerConfig.list_servers()

# `config_error`

```elixir
@type config_error() :: :not_found | :invalid_config | :https_required
```

# `server_config`

```elixir
@type server_config() :: %{
  :introspection_endpoint =&gt; String.t(),
  optional(:realm) =&gt; String.t(),
  optional(:client_id) =&gt; String.t(),
  optional(:client_secret) =&gt; String.t(),
  optional(:timeout) =&gt; pos_integer(),
  optional(:retries) =&gt; non_neg_integer()
}
```

# `server_id`

```elixir
@type server_id() :: atom() | String.t()
```

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `delete_server`

```elixir
@spec delete_server(server_id()) :: :ok
```

Removes a server configuration.

# `get_default_server_id`

```elixir
@spec get_default_server_id() :: server_id()
```

Gets the default server ID.

# `get_server`

```elixir
@spec get_server() :: {:ok, server_config()} | {:error, config_error()}
```

Gets the configuration for the default authorization server.

# `get_server`

```elixir
@spec get_server(server_id()) :: {:ok, server_config()} | {:error, config_error()}
```

Gets the configuration for a specific authorization server.

# `list_servers`

```elixir
@spec list_servers() :: [server_id()]
```

Lists all configured server IDs.

# `put_server`

```elixir
@spec put_server(server_id(), server_config()) :: :ok | {:error, config_error()}
```

Sets the configuration for a specific authorization server.

The configuration is validated before being stored.

# `reload_from_env`

```elixir
@spec reload_from_env() :: :ok
```

Reloads configuration from application environment.

This is useful when configuration has been updated at runtime.

# `set_default_server_id`

```elixir
@spec set_default_server_id(server_id()) :: :ok
```

Sets the default server ID.

# `start_link`

```elixir
@spec start_link(keyword()) :: GenServer.on_start()
```

Starts the ServerConfig GenServer.

# `validate_config`

```elixir
@spec validate_config(server_config()) :: :ok | {:error, config_error()}
```

Validates a server configuration.

## Validation Rules

- `introspection_endpoint` must be a valid HTTPS URL (HTTP allowed for localhost/127.0.0.1)
- `realm` must be a non-empty string if provided
- `timeout` must be a positive integer if provided
- `retries` must be a non-negative integer if provided

---

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