Prerequisites:
MCP endpoint:
Web3 wallet with at least 2 USDC on Base or Monad to sign HTTP 402 payment requests.
A client that sends JSON-RPC requests (
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
Step 1. Initialize the MCP Connection and Inspect Available Tools
These calls are free and do not require payment.ask_fortytwo_prime.
Step 2. Send a tools/call Request
Server Response
If no active session exists, the server responds withHTTP 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
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 networkclient— Payee addressmaxAmount— Max amountvalidBefore— 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-idheader — save this for subsequent callspayment-responseheader — payment confirmation withtxHash- JSON-RPC
resultwith tool output
Step 5. Use x-session-id for Subsequent Calls
| Header | Purpose |
|---|---|
x-session-id | Ties calls to one paid session |
x-idempotency-key | Prevents duplicate payments on retries |
jsonrpc.id | Identifies a single request/response pair |
Step 6. Session Expiry and Re-payment
When session ends, the server responds with:| Response | Meaning |
|---|---|
402 Payment Required | Submit a new payment signature and open a new session |
410 Gone | Session expired — start a new payment cycle. Unused credits from previous session get refunded. |
Integration Checklist
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.
Automatic closure may occur with a small delay, typically up to tens of seconds.
Fund Release
After session closure, the release process starts automatically:- The service finalizes the actual amount spent.
- A release transaction is sent on-chain.
- The spent portion goes to the service; unused remainder returns to the client’s wallet.
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. 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:| Data | Purpose |
|---|---|
x-session-id | Current payment session identifier |
payment-response(especially transaction / txHash) | Payment confirmation and settle proof after successful session opening |
payment-signature(at least network + client + nonce) | Required for support and refund flows |
Supported Payment Networks
USDC payments are currently accepted on two networks:| Network | Chain ID |
|---|---|
| Base | eip155:8453 |
| Monad | eip155:143 |
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
| Code | Meaning | Action |
|---|---|---|
402 | Payment required | Sign a new payment and repeat the tools/call request |
410 | Session expired | Open a new session, start a new payment cycle |
4xx (other) | Request or signature issue | Verify network, signature validity window, and JSON-RPC format |
5xx | Temporary server/upstream error | Wait and retry. If persistent, contact support on Discord with your txHash |