MAILGENT
Mailgent Index

How to call x402-ready MCP tools
with your AI agent.

You don't need an API key, an account on each provider, or a human to approve a charge. Your agent provisions a wallet, queries the index, and pays per call in USDC. Here's how to wire it up — including spend controls and how it slots into your framework.

The old way to give an agent a new tool was a ritual: sign up for the provider, generate an API key, store it as a secret, handle rotation, watch the rate limits, and hope the free tier covers you. Every new tool repeated the whole dance, and every key was one more thing to leak.

With x402-ready tools, the agent itself is the account. It holds a wallet, discovers tools from the index, and pays the exact price of each call as it makes it. No keys, no signups, no human in the loop — and you cap exactly how much it can spend. This guide shows the wiring end to end.

1. Give your agent a wallet

Provision a wallet your agent controls — bring a Base-compatible wallet, or use an embedded wallet created at signup. Fund it with USDC. This is the agent's spending account, and it's the only credential it needs to call any x402-ready tool in the index.

Because the wallet is the credential, there's nothing per-provider to manage: no keys to issue, store, or rotate, and no accounts to create on each tool you call.

2. Query the index for the right tool

Ask Mailgent Index what's available for the capability you need. You get back tools with their descriptions, per-call prices, and payment endpoints — structured so your agent can pick programmatically. Filter by category, by framework compatibility, and by price.

Every tool carries its price up front, so your agent can choose the cheapest option that meets the bar before it ever makes a call. Price, capability, and endpoint all arrive in the same query result.

3. Call and pay automatically

Call the tool's endpoint. It answers with an HTTP 402 challenge stating the price, the asset (USDC), and the network (Base). Your x402 client signs a payment for that exact amount, retries the request with the payment attached, and gets the result. The entire exchange happens inside the request — no checkout, no invoice, no human approval — and takes about two seconds.

Wrap your fetch once with an x402 client backed by the agent's wallet, and every paid call just works.

agent.ts
import { withX402 } from "@mailgent/sdk";

// Wrap fetch with an x402 client backed by the agent's wallet.
const pay = withX402({ wallet: agentWallet, maxPerCall: "0.10" });

// Call any x402-ready tool — payment is handled on the 402 automatically.
const res = await pay("https://api.example.com/mcp/web_search", {
  method: "POST",
  body: JSON.stringify({ query: "latest USDC supply on Base" }),
});
const data = await res.json();

4. Set spend controls

Two limits keep an autonomous agent from overspending. The per-call cap (maxPerCall) makes the client refuse any tool whose 402 asks for more than you allow, so a mispriced or malicious endpoint can't drain the wallet on a single call. And the wallet balance itself is a hard ceiling — the agent can only ever spend what you've funded.

For long-running agents, fund the wallet in small increments and top it up as needed, so the maximum exposure at any moment is bounded by what's currently in it.

5. Works with your framework

x402 is just HTTP, so it slots into any agent stack — LangChain, CrewAI, AutoGen, the OpenAI Agents SDK, Claude, Cursor, LangGraph, and more. The tool becomes a callable your agent invokes like any other; payment is a property of the call, not a separate integration or plugin.

That means adopting a paid tool is the same amount of work as adopting a free one: point at the endpoint and call it. The only difference is the 402, which your x402 client answers for you.

Why this beats API keys

API keys are long-lived secrets: they have to be issued, stored, scoped, rotated, and revoked, and any leak is a standing liability. A per-call payment is the opposite — it authorizes exactly one call, for a known amount, and leaves a signed receipt. There's no secret to steal and no quota to negotiate.

For an autonomous agent that may discover and use dozens of tools it was never pre-configured for, paying per call is the only model that scales: it can adopt a tool the instant it finds it, without a human provisioning access first.

FAQ

Do I need an API key for each tool?

No. The agent's wallet is its credential. It pays per call, so there's nothing to sign up for, store, or rotate per provider.

How do I stop my agent overspending?

Set a per-call cap on the x402 client and fund the wallet with a bounded balance. The client refuses any challenge above your cap, and the agent can only ever spend what's in the wallet.

What does a call cost?

Whatever the tool's listing says — prices start at $0.01 and commonly run $0.01–$0.10 per call. The price is in the index before you call and in the 402 challenge at call time, so your agent always knows the cost before paying.

How fast is a paid call?

About two seconds, dominated by Base settlement time. The payment happens inside the request, so there's no separate checkout step that blocks your agent.

Which networks are supported?

Settlement is in USDC on Base today, chosen for low fees and fast finality. More networks are on the roadmap.

Do I get a record of what my agent spent?

Yes. Every paid call returns a signed receipt linked to the on-chain transaction, so you have a verifiable, itemized record of every tool your agent paid for.

Browse Mailgent Index.

Find x402-ready tools your agent can call and pay for.

Last updated: 2026-05-27