MPP.Client.MCP (mpp v0.16.0)

Copy Markdown View Source

Payment-aware MCP client orchestration.

Wraps a JSON-RPC send function: if the response is payment-required (-32042 or payment-required result metadata), selects a challenge through MPP.Client.SelectionPolicy, asks on_payment_required for approval, pays via MPP.Client.MultiProvider, and retries the original request once with the credential attached.

Approval runs after challenge selection and before payment — matching refs/mppx/src/mcp/client/McpClient.ts. A declined approval neither pays nor retries.

client = MPP.Client.MCP.new(provider: my_provider)
MPP.Client.MCP.call(client, request, &MyTransport.send/1)

API Functions

FunctionArityDescriptionParam Kinds
call4Send a JSON-RPC request, paying and retrying once if payment is required.client: value, request: value, send_fun: value, opts: value
new1Build a payment-aware MCP client from provider and policy options.opts: value

Summary

Functions

Send request through send_fun, paying and retrying once on payment required.

Build a payment-aware MCP client.

Types

approval()

@type approval() :: (MPP.Challenge.t() -> boolean())

t()

@type t() :: %MPP.Client.MCP{
  on_payment_required: approval() | nil,
  provider: MPP.Client.MultiProvider.t(),
  selection: MPP.Client.SelectionPolicy.t()
}

Functions

call(client, request, send_fun, opts \\ [])

@spec call(t(), map(), (map() -> term()), keyword()) ::
  {:ok, map()} | {:error, term()}

Send request through send_fun, paying and retrying once on payment required.

send_fun receives the JSON-RPC request map and must return a JSON-RPC response map. Per-call :on_payment_required overrides the client hook; pass nil to bypass it (mppx onPaymentRequired: null).

new(opts)

@spec new(keyword()) :: t()

Build a payment-aware MCP client.

Options

  • :provider — required. An MPP.Client.MultiProvider, a {module, config} tuple, or a provider module
  • :selectionMPP.Client.SelectionPolicy.t(). Defaults to :server_order, or {:accept_payment, entries} when :accept_payment is set
  • :accept_payment — preference entries used as the default ranking policy
  • :on_payment_required(MPP.Challenge.t() -> boolean()) invoked after challenge selection and before payment. Omitted or nil auto-approves.