Skip to main content
This guide shows how to bridge x402-enabled APIs to MCP tools so AI clients can call and pay for them through natural-language prompts. It builds on the server from Build a pay-per-call API.

What you’ll build

An MCP server that wraps x402-paid endpoints as tools. The AI client types a natural-language prompt, each tool call triggers a paid x402 request, and settlement is visible on Stablescan. The user never sees a wallet prompt.

Demo

Both tx values are visible on https://stablescan.xyz.
Agent wallet funding: The MCP server signs payments with a seed phrase you control. Fund that wallet with USDT0 on mainnet before starting the server. A balance of at least $0.10 covers several paid calls; $1.00 is plenty for extended testing. Top up as needed using a standard USDT0 transfer to the wallet’s address.

Overview

MCP Server:
User (via AI client):

Prerequisites

  • A running x402 server (see Build a pay-per-call API).
  • An MCP-compatible AI client (Claude Desktop, Claude Code, etc.).

Step 1: Create the MCP server

The MCP server acts as a bridge between AI clients and x402-enabled APIs. Each tool makes a paid request using the x402 client SDK and returns the result.
Each tool handler calls fetchWithPayment, which handles the full x402 payment cycle automatically. The AI client only sees the tool name, description, and parameters.

Step 2: Configure your AI client

Add the MCP server to your AI client’s configuration. Claude Desktop (claude_desktop_config.json):
Claude Code:
After configuration, restart your AI client. The tools should appear in the available tool list.
The seed phrase in the MCP configuration controls real funds. Store it securely using your OS keychain or a secrets manager rather than in plain-text config files.

Step 3: Type the prompt and use it

Once configured, the AI client can call paid APIs through the user’s prompt: User: “Pull financials for ACME Corp and assess their credit risk.”
  1. Client calls get_company_financials("ACME"): $0.01 paid via x402. Returns revenue, debt ratio, cash flow, etc.
  2. Client calls assess_credit_risk(financials): $0.05 paid via x402. Returns risk score, rating, key factors.
  3. Client responds: “ACME Corp has a credit risk score of 72 (moderate). Revenue is stable but debt-to-equity ratio is elevated at 1.8x…”
Individual tools also work on their own:
  • “Pull financials for ACME Corp” calls get_company_financials ($0.01).
  • “Assess credit risk for this data” calls assess_credit_risk ($0.05).
  • “How much USDT0 do I have left?” calls check_balance.
The user does not interact with wallets, signatures, or payment flows. The MCP server handles payment for each tool call transparently.

Spending controls

To prevent unexpected spending, consider adding controls to the MCP server.
These limits run server-side. The AI client cannot modify or bypass them.

Build a pay-per-call API

Set up the x402 server this MCP server bridges.

x402 concept

Review the settlement protocol behind these payments.

Develop with AI

Wire Stable’s Docs and Runtime MCP servers into the same AI client.
Last modified on April 23, 2026