What You Will Build

By the end of this tutorial you will have an MCP-enabled AI client (Claude Desktop, Cursor, or Windsurf) that can fetch paid APIs over x402 without any human in the loop. You will ask the agent something like "fetch the latest article from this paid endpoint and summarize it," and the agent will:

  1. Call call_x402_endpoint with the URL.
  2. The MCP server fetches the URL.
  3. The endpoint returns 402 Payment Required with payment instructions.
  4. The MCP server pays the fee from the agent's MoltPe wallet (subject to spending policies).
  5. The server retries the request with the payment proof.
  6. The endpoint returns the content.
  7. The agent receives the content and continues with the user's request.

Total round-trip is typically under one second. The agent has no awareness of the payment handshake; it just gets the data it asked for.

Prerequisites

If you have not used MCP before, the MCP payment tools guide covers the fundamentals before you start this tutorial.

Step 1: Create the Wallet

Go to moltpe.com/dashboard and sign up. Create a new agent wallet on Polygon PoS or Base. Set conservative spending policies for the tutorial:

These are tight enough that no test mistake can cost more than a coffee, but loose enough to call most x402 endpoints in the wild (typical fees are $0.01 to $0.50). The full setup walk-through is in our wallet setup guide.

Fund the wallet with $1-2 of USDC. The dashboard shows the address and chain; copy carefully. Once funded, generate an API key under API Keys and copy it somewhere safe.

Step 2: Install the MCP Server

Edit your client's MCP configuration. The location varies:

Add this block:

{
  "mcpServers": {
    "moltpe": {
      "command": "npx",
      "args": ["-y", "@moltpe/mcp-server"],
      "env": {
        "MOLTPE_API_KEY": "your-api-key-from-step-1"
      }
    }
  }
}

Restart the client completely (quit and relaunch, do not just reload the window). MCP servers are loaded at startup.

Once the client restarts, open a new conversation. The MoltPe tools should appear in the tool palette: send_payment, check_balance, list_transactions, agent_info, and call_x402_endpoint. If they don't, check the client's MCP log (each client exposes one) for connection errors.

Step 3: Call a Paid Endpoint

Open a new conversation and ask the agent to fetch an x402-paid URL. For testing, use any public x402 demo endpoint, or your own. A typical prompt:

Fetch this URL and tell me what it returns: https://api.example.com/x402-demo/article/42

The agent will recognize that this is a fetch task and call call_x402_endpoint with the URL. Behind the scenes:

  1. MCP server fetches the URL with a regular HTTP GET.
  2. Endpoint returns 402 Payment Required with a JSON body specifying chain, amount, and recipient.
  3. MCP server submits a payment request to MoltPe.
  4. MoltPe's policy engine validates the amount against your wallet's per-transaction cap and daily limit.
  5. If approved, MoltPe signs and broadcasts the USDC transfer (sub-second on Polygon PoS).
  6. MCP server retries the original request with the payment proof in a header.
  7. Endpoint validates the payment and returns the article.
  8. MCP server returns the article body to the agent.

The agent never sees any of the intermediate steps. From its perspective, it called a tool and got back content. The full protocol details are in our x402 complete guide.

Step 4: Verify the Audit Trail

Open the MoltPe dashboard and check the wallet's transaction history. You should see one new entry with:

The on-chain hash is the proof that policy enforcement is verifiable and not just claimed. Click it; you can independently confirm on the block explorer that no transaction from your wallet ever exceeded the configured caps.

Extending the Pattern

Once the basic flow works, three extensions are obvious:

Multi-source research. Ask the agent to fetch five different paid sources and synthesize. The MCP server pays each fee independently and the agent gets back five response bodies. Total cost is the sum of fees; total wall time is roughly the slowest single fetch (since the MCP server runs them in parallel).

Selling your own x402 endpoint. The reverse direction. Run an x402 server (open-source implementations exist for Express, FastAPI, Fastify) that charges agents to call your API. Receive USDC into a MoltPe wallet. This is the simplest possible business model for AI-native APIs.

Agent-to-agent commerce. One agent calls another agent's x402 endpoint as part of a multi-agent workflow. The whole transaction graph is on-chain auditable. Each agent has its own wallet, its own policies, and its own audit trail. This pattern is what early agent-to-agent marketplaces are built on.

For more on the broader autonomous-agent payment landscape, read our AI agent economy guide.