Skip to main content
Some MCP servers require payment for tool calls, returning error code -32042 (Payment Required). wrapMcpClient() wraps a standard MCP Client to handle these payments automatically — detect the challenge, check budget, create credentials, and retry the call.
This is for outgoing payments to third-party MCP servers. It is separate from @boltzpay/mcp, which is BoltzPay’s own MCP server that exposes tools to Claude Desktop.

Setup

How It Works

  1. The wrapper calls the MCP server normally.
  2. If the server returns -32042, the wrapper extracts the payment challenge.
  3. Before creating credentials, the wrapper checks the configured budget limits.
  4. If budget allows, it signs the payment using the configured MPP wallet method.
  5. The call is retried with the payment credential attached.
  6. On success, spending is recorded and the receipt is returned.

Response Format

If no payment was required, receipt is undefined.

Budget Enforcement

Budget checks happen before credential creation, not after. If the payment amount would exceed any configured limit, a BudgetExceededError is thrown and the MCP call fails without making a payment.

Events

MCP payments emit a dedicated event:
Each payment is also recorded in payment history with transport: "mcp":

Requirements

  • At least one MPP wallet must be configured (tempo or stripe-mpp). wrapMcpClient() throws ConfigurationError if no MPP wallet is available.
  • The MCP client must implement callTool() (standard @modelcontextprotocol/sdk Client).
  • Budget is optional but recommended for autonomous agents.

Security

  • The wrapper filters _meta fields using an allowlist. Only the payment receipt key (org.paymentauth/receipt) is passed through. All other _meta fields from the MCP server response are stripped.
  • Payment amounts are validated as non-negative integers before processing.

Next Steps