Validated protocol context for one inbound MCP message.
The context separates transport/protocol metadata from application params.
Legacy messages remain valid without modern metadata; a message that uses
either required modern field must provide the complete modern _meta
object.
Summary
Functions
Builds a JSON-RPC error response for a context-validation failure.
Extracts context from a JSON-RPC request or notification.
Returns the HTTP status required for context-validation errors.
Verifies that a modern request declared every capability an operation needs.
Validates that a method belongs to the selected protocol revision.
Validates an extracted context against an explicitly configured server mode.
Types
@type context_error() :: ExMCP.Protocol.Meta.validation_error() | {:unsupported_protocol_version, String.t()} | {:protocol_mode_mismatch, ExMCP.Types.protocol_mode(), :legacy | :modern} | {:method_not_available, String.t(), String.t()}
@type t() :: %ExMCP.Server.RequestContext{ client_capabilities: map() | nil, client_info: map() | nil, delivery_semantics: :at_least_once | :single_use | nil, endpoint: String.t() | nil, era: :legacy | :modern | :unknown, input_responses: map() | nil, log_level: String.t() | nil, meta: map(), method: String.t(), mrtr_jti: String.t() | nil, mrtr_round: non_neg_integer() | nil, notification_target: pid() | nil, principal_id: String.t() | nil, progress_token: ExMCP.Types.progress_token() | nil, protocol_version: String.t() | nil, request?: boolean(), request_id: ExMCP.Types.request_id() | nil, request_state: term(), sealed_request_state: String.t() | nil, tenant_id: String.t() | nil, trace_context: map() }
Functions
@spec error_response( context_error(), ExMCP.Types.request_id() | nil, ExMCP.Types.protocol_mode() | nil ) :: map()
Builds a JSON-RPC error response for a context-validation failure.
@spec from_message(map()) :: {:ok, t()} | {:error, context_error()}
Extracts context from a JSON-RPC request or notification.
@spec http_status(context_error()) :: 400
Returns the HTTP status required for context-validation errors.
@spec require_client_capabilities(t(), map()) :: :ok | {:error, ExMCP.Error.ProtocolError.t()}
Verifies that a modern request declared every capability an operation needs.
Empty capability objects require presence of that capability. Nested maps require the corresponding nested keys. On failure, the returned protocol error can be returned directly as a handler error reason.
@spec validate_method(t()) :: :ok | {:error, context_error()}
Validates that a method belongs to the selected protocol revision.
@spec validate_protocol_mode(t(), ExMCP.Types.protocol_mode() | nil) :: :ok | {:error, context_error()}
Validates an extracted context against an explicitly configured server mode.