paid_mcp_session.
Give the agent a paid session
mcp.ClientSession, so it plugs into any agent framework that accepts one; payments are invisible to the framework. Tool discovery works as usual. If a price is outside the spend controls, nothing is signed and the session raises SpendLimitExceededError. Every parameter: Pay from Python.
Develop with "testnet" and free TestNet ALGO, then switch to "mainnet". The session uses AlgoNode’s public algod unless you pass algod_url.
What the agent pays for
With
identity=True (the default) the session proves the agent’s address on every request, so a server can honour a pass the agent bought, a subscription, a bulk discount or a per-caller price. The proof moves no funds and reveals nothing else. With identity=False the agent stays anonymous and pays the standard price.
Set limits
An agent that can pay needs limits it cannot talk itself out of. No single control bounds total spend, so combine them:1
Use a dedicated budget wallet
Give the agent its own account and fund it with only what it may spend in a period. The balance is the hard limit on total spend. Top it up on a schedule rather than holding a large balance.
2
Keep spend controls on, and tight
Set the cap to the most you would pay for any single call, for example
spend_controls={"max_amount_per_payment": "$0.05"}. A $ cap is 1,000,000 base units per dollar for ALGO too, so $1 means 1 ALGO whatever its market price. Never pass spend_controls=False to an autonomous agent. All options.3
Pin the network
Pass the network explicitly. The session registers the payment scheme for that network only, and refuses an offer for a network other than its algod’s.
4
Allow only the assets you hold
The default allow-list is ALGO and USDC (MainNet and TestNet). Add another ASA only with its own cap, in base units.
5
Protect the key
Inject it from a secret store at start-up. Keep it out of prompts, tool arguments, logs and the agent’s memory. If the agent’s context could leak it, treat it as compromised and rotate it.
6
Watch the wallet
Payments are public on chain. Alert on the budget wallet’s balance and on unexpected recipients.
Check a price before paying
x402 has no price list. The price of a call is in the402 response to that call, and with PaymentGate it can depend on the arguments and the caller. MCP’s tools/list returns no prices; a vendor may mention them in tool descriptions, but the 402 is authoritative.
With paid_mcp_session the agent never sees the price, only the result, and the spend cap is its upper bound. That is the right setup for most agents. When an agent must decide per call (to compare vendors, or to ask a person), read the challenge without paying. For a PaymentGate server on Streamable HTTP (stateless, the default), one plain HTTP request is enough, without the MCP initialize handshake:
/messages/?session_id=... endpoint, so you would have to speak SSE at the HTTP level; unless you need per-call approval, rely on spend controls.
For an HTTP API, send the request with a client that does not pay:
"asset": "31566704", "amount": "50000" on MainNet means 0.05 USDC (6 decimals). accepts can hold several offers, for example one per network; a client pays one. Every field: HTTP 402 reference. To filter offers automatically with the official Python client, use a payment policy.
Agents in JavaScript
x402-avm-js has no MCP session wrapper. A Node agent that calls x402 HTTP APIs uses decodePaymentRequired and payForRequirement with spend controls; see Pay from Node.js.