AttestoMCP.Metadata (AttestoMCP v0.5.2)

Copy Markdown View Source

Builders for OAuth metadata used by HTTP MCP authorization.

MCP HTTP servers that require authorization act as OAuth protected resources. The MCP authorization spec points clients at RFC 9728 protected-resource metadata first, then at RFC 8414 authorization-server metadata. This module builds those documents without coupling the package to any MCP server SDK.

Summary

Functions

Append resource_metadata to a WWW-Authenticate challenge.

Build the authorization-server metadata document by delegating to Attesto.

Build an RFC 9728 protected-resource metadata document.

Build protected-resource metadata from a Plug connection and resource path.

Build the well-known metadata URL for an MCP resource path.

Build the WWW-Authenticate auth-param value for RFC 9728 metadata discovery.

Functions

append_resource_metadata(challenge, url)

@spec append_resource_metadata(String.t(), String.t()) :: String.t()

Append resource_metadata to a WWW-Authenticate challenge.

authorization_server(config, opts \\ [])

@spec authorization_server(
  Attesto.Config.t(),
  keyword()
) :: %{required(String.t()) => term()}

Build the authorization-server metadata document by delegating to Attesto.

protected_resource(opts)

@spec protected_resource(keyword()) :: %{required(String.t()) => term()}

Build an RFC 9728 protected-resource metadata document.

Required options:

  • :resource - the protected resource identifier, usually the canonical MCP server URI such as "https://mcp.example.com/mcp".
  • :authorization_servers - a non-empty list of issuer identifiers.

Common options include :scopes_supported, :bearer_methods_supported, :dpop_signing_alg_values_supported, and :tls_client_certificate_bound_access_tokens.

protected_resource(conn, resource_path, opts \\ [])

@spec protected_resource(Plug.Conn.t(), String.t(), keyword()) :: %{
  required(String.t()) => term()
}

Build protected-resource metadata from a Plug connection and resource path.

resource_path is the path of the MCP endpoint, for example "/mcp" or "/mcp/admin". The resource identifier is the current request origin joined with that path. :authorization_servers defaults to the same origin.

protected_resource_url(base_url, resource_path)

@spec protected_resource_url(String.t(), String.t()) :: String.t()
@spec protected_resource_url(Plug.Conn.t(), String.t()) :: String.t()

Build the well-known metadata URL for an MCP resource path.

iex> AttestoMCP.Metadata.protected_resource_url("https://mcp.example.com", "/mcp")
"https://mcp.example.com/.well-known/oauth-protected-resource/mcp"

A Plug connection can also be passed as the first argument.

resource_metadata_param(url)

@spec resource_metadata_param(String.t()) :: String.t()

Build the WWW-Authenticate auth-param value for RFC 9728 metadata discovery.