MPP.Client.Transport.MCP (mpp v0.16.0)

Copy Markdown View Source

JSON-RPC implementation of MPP.Client.Transport for MCP.

Operates on JSON-RPC request/response maps. Automatic pay-and-retry lives in MPP.Client.MCP; this transport only detects, parses, and attaches.

Wire format

Detection and parsing accept a full JSON-RPC envelope, a bare error object, or a result/_meta fragment — the same shapes MPP.Mcp client helpers already unwrap.

API Functions

FunctionArityDescriptionParam Kinds
set_credential2Attach a credential at params._meta["org.paymentauth/credential"].request: value, credential: value
get_challenges1Parse Payment challenges from a JSON-RPC payment-required message.response: value
payment_required?1Return true if the JSON-RPC message signals payment required.response: value

Summary

Functions

Parse Payment challenges from a JSON-RPC payment-required message.

Return true if the JSON-RPC message signals payment required.

Attach a credential at params._meta["org.paymentauth/credential"].

Functions

get_challenges(response)

@spec get_challenges(term()) :: {:ok, [MPP.Challenge.t()]} | {:error, term()}
@spec get_challenges(term()) :: {:error, :malformed_envelope}

Parse Payment challenges from a JSON-RPC payment-required message.

Parameters

  • response - JSON-RPC response envelope, error object, or result fragment (value)

Returns

{:ok, [challenge]} on success, {:error, reason} otherwise (tagged_tuple)

Errors

  • :malformed_envelope
  • :no_challenges
  • :invalid_challenge
# descripex:contract
%{
  params: %{
    response: %{
      description: "JSON-RPC response envelope, error object, or result fragment",
      kind: :value
    }
  },
  errors: [:malformed_envelope, :no_challenges, :invalid_challenge],
  returns: %{
    type: :tagged_tuple,
    description: "`{:ok, [challenge]}` on success, `{:error, reason}` otherwise"
  }
}

payment_required?(response)

@spec payment_required?(term()) :: boolean()
@spec payment_required?(term()) :: false

Return true if the JSON-RPC message signals payment required.

Parameters

  • response - JSON-RPC response envelope, error object, or result fragment (value)

Returns

true when the error code is -32042 or payment-required metadata is present (boolean)

# descripex:contract
%{
  params: %{
    response: %{
      description: "JSON-RPC response envelope, error object, or result fragment",
      kind: :value
    }
  },
  returns: %{
    type: :boolean,
    description: "true when the error code is -32042 or payment-required metadata is present"
  }
}

set_credential(request, credential)

@spec set_credential(map(), MPP.Credential.t()) :: map()

Attach a credential at params._meta["org.paymentauth/credential"].

Parameters

  • request - JSON-RPC request envelope or MCP tool-params map (value)
  • credential - MPP.Credential struct (value)

Returns

Request with the credential in _meta (map)

# descripex:contract
%{
  params: %{
    request: %{
      description: "JSON-RPC request envelope or MCP tool-params map",
      kind: :value
    },
    credential: %{description: "MPP.Credential struct", kind: :value}
  },
  returns: %{type: :map, description: "Request with the credential in `_meta`"}
}