Skip to main content
MCP Fortytwo Prime Installing to Client JSON-RPC x402Escrow Payments
Prerequisites:
MCP endpoint: POST https://mcp.fortytwo.network/mcp.
Web3 wallet with at least 2 USDC on Base or Monad to sign HTTP 402 payment requests.
A client that sends JSON-RPC requests (initialize, tools/list, tools/call)

User Journey: MCP + x402Escrow Payments

Implementation reference on GitHub


Step 1. Initialize the MCP Connection and Inspect Available Tools

These calls are free and do not require payment.
The tool exposed by the server is ask_fortytwo_prime.
In conversation with an AI agent, phrases like “Ask Fortytwo” and “Ask Fortytwo Prime” refer to calling this tool.

Step 2. Send a tools/call Request

Server Response

If no active session exists, the server responds with HTTP 402 and a payment-required header.

Payments are Handled with x402Escrow Protocol

What is x402Escrow


Open-sourced on GitHub


Step 3. Build Payment from payment-required

The payment-required header contains base64(JSON) with payment options.
JSON
Several accepts[] options can be listed, each with unique network details (eip155:8453 for Base, eip155:143 for Monad). Choose one of the accepts[] options, sign the payment with your wallet, and construct a payment-signature (base64-encoded JSON) containing:
  • network — Selected network
  • client — Payee address
  • maxAmount — Max amount
  • validBefore — Signature validity window
  • Cryptographic signature
JSON

Step 4. Repeat the tools/call and Now Include payment-signature

Server Response

On success, the server verifies the signature, settles payment on-chain, and opens a billing session. The response includes:
  • x-session-id header — save this for subsequent calls
  • payment-response header — payment confirmation with txHash
  • JSON-RPC result with tool output

Step 5. Use x-session-id for Subsequent Calls

Step 6. Session Expiry and Re-payment

When session ends, the server responds with:

Integration Checklist

1
Treat HTTP 402 Payment Required as the first-payment step.
2
Save x-session-id after successful payment.
3
Send x-idempotency-key on every tools/call.
4
On HTTP 410 or repeated HTTP 402, start a new payment cycle.

How Sessions Work: Lifetime and Closure

After the first successful payment, a billing session is created and identified: x-session-id. Each tools/call reserves budget first that gets locked in a x402Escrow contract. With each request, the contract charges the actual cost of inference, and releases unused reserve back to the available session balance. Session closure conditions:
  • If there is no activity for 10 minutes.
  • Session hits a hard cap of 60 minutes from session opening.
  • Session budget is exhausted.
  • Connection is dropped mid-response.
  • An upstream error occurs on a newly opened session.
If a session is close to expiry, new calls may be rejected to avoid starting operations that cannot be completed.
Automatic closure may occur with a small delay, typically up to tens of seconds.

Fund Release

After session closure, the release process starts automatically:
  1. The service finalizes the actual amount spent.
  2. A release transaction is sent on-chain.
  3. The spent portion goes to the service; unused remainder returns to the client’s wallet.
This typically takes a few seconds to a couple of minutes. Network congestion may cause longer delays.

If Release Does Not Happen

A fallback is available via on-chain refund: refundAfterTimeout(escrowId).
Funds always return to the original client address regardless of who calls it.
This refund is only available after the escrow’s refundAt deadline (typically ~90 minutes, exact timing depends on on-chain configuration).
How to get escrowId: from the settle transaction’s Deposited event, or via support on Discord.

What to Store Client-Side

Minimum data worth storing:

Supported Payment Networks

USDC payments are currently accepted on two networks: The accepts[].network and accepts[].asset fields in the payment response indicate which network and token address to use.

Token Usage

The actual cost is calculated from input and output tokens.
tools/call responses include usage data:
JSON

Error Reference