ExMCP.Transport.SecurityError (ex_mcp v0.10.0)

View Source

Standardized security error handling across transports.

This module provides consistent error formatting and handling for security violations across all MCP transports.

Summary

Functions

Formats a security error for a specific transport.

Creates a new security error.

Checks if an error is a security-related error.

Converts a security error to a standard Elixir error tuple.

Types

error_type()

@type error_type() ::
  :token_passthrough_blocked
  | :consent_required
  | :consent_denied
  | :consent_error
  | :security_violation

t()

@type t() :: %ExMCP.Transport.SecurityError{
  details: map(),
  message: String.t(),
  timestamp: DateTime.t(),
  type: atom()
}

Functions

format_for_transport(error, arg2)

@spec format_for_transport(t(), atom()) :: term()

Formats a security error for a specific transport.

Different transports may need different error formats:

  • HTTP: Status codes and JSON responses
  • Stdio: JSON-RPC error format
  • BEAM: Elixir error tuples

new(type, message, details \\ %{})

@spec new(error_type(), String.t(), map()) :: t()

Creates a new security error.

Parameters

  • type - The type of security violation
  • message - Human-readable error message
  • details - Additional context about the error

Examples

error = SecurityError.new(:consent_required,
  "User consent required",
  %{url: "https://api.example.com", user_id: "user123"}
)

security_error?(arg1)

@spec security_error?(term()) :: boolean()

Checks if an error is a security-related error.

to_error_tuple(error)

@spec to_error_tuple(t()) :: {:error, term()}

Converts a security error to a standard Elixir error tuple.