ExMCP.Authorization.AuthorizationServerMetadata (ex_mcp v0.9.2)
View SourceOAuth 2.1 Authorization Server Metadata Discovery (RFC 8414).
This module implements the authorization server metadata discovery mechanism as specified in RFC 8414. It provides the /.well-known/oauth-authorization-server endpoint that returns authorization server capabilities and configuration.
Example
# Generate metadata from application configuration
metadata = AuthorizationServerMetadata.build_metadata()
# Metadata includes required fields like issuer, endpoints, and capabilities
%{
"issuer" => "https://auth.example.com",
"authorization_endpoint" => "https://auth.example.com/authorize",
"token_endpoint" => "https://auth.example.com/token",
"scopes_supported" => ["mcp:read", "mcp:write"],
"response_types_supported" => ["code"],
"grant_types_supported" => ["authorization_code"]
}
Summary
Functions
Builds the authorization server metadata from application configuration.
Validates that the authorization server metadata configuration is complete.
Types
Functions
@spec build_metadata() :: metadata()
Builds the authorization server metadata from application configuration.
Returns a map containing the authorization server metadata as specified in RFC 8414. The metadata includes both required and optional fields based on the application's OAuth configuration.
Required Fields (RFC 8414)
issuer: The authorization server issuer identifierauthorization_endpoint: URL of the authorization endpointtoken_endpoint: URL of the token endpoint
Optional Fields
jwks_uri: URL of the JWK Set documentscopes_supported: List of supported OAuth 2.0 scopesresponse_types_supported: List of supported response typesgrant_types_supported: List of supported grant typescode_challenge_methods_supported: List of supported PKCE methodsintrospection_endpoint: URL of the token introspection endpointrevocation_endpoint: URL of the token revocation endpoint
Examples
iex> AuthorizationServerMetadata.build_metadata()
%{
"issuer" => "https://auth.example.com",
"authorization_endpoint" => "https://auth.example.com/authorize",
"token_endpoint" => "https://auth.example.com/token",
"scopes_supported" => ["mcp:read", "mcp:write"],
"response_types_supported" => ["code"],
"grant_types_supported" => ["authorization_code"]
}
@spec validate_config() :: :ok | {:error, term()}
Validates that the authorization server metadata configuration is complete.
Checks that all required fields are present in the application configuration and returns :ok if valid, or {:error, reason} if configuration is missing or invalid.
Examples
iex> AuthorizationServerMetadata.validate_config()
:ok
iex> AuthorizationServerMetadata.validate_config()
{:error, {:missing_required_field, :issuer}}