ExMCP.Authorization.ErrorHandler (ex_mcp v0.9.2)

View Source

Handles authorization-related errors and triggers appropriate OAuth flows.

This module implements the MCP specification requirements for handling 401 Unauthorized and 403 Forbidden responses, automatically initiating OAuth flows when needed.

Summary

Functions

Handles HTTP authorization errors according to MCP specification.

Processes an OAuth error response according to RFC 6749.

Functions

handle_auth_error(status, headers, body, state)

@spec handle_auth_error(integer(), list(), binary(), map()) ::
  {:error, atom() | {atom(), any()}} | {:retry, map()}

Handles HTTP authorization errors according to MCP specification.

  • 401 Unauthorized: Token is invalid or required
  • 403 Forbidden: Insufficient permissions

Returns {:error, reason} or {:retry, auth_params} to trigger OAuth flow.

handle_oauth_error(response)

@spec handle_oauth_error(map()) :: {:error, {atom(), String.t()}}

Processes an OAuth error response according to RFC 6749.