Skip to main content
https://api.cdp.coinbase.com/platform/v2/x402/discovery/mcp
The Bazaar MCP server exposes the CDP Bazaar catalog as a Model Context Protocol (MCP) server. AI agents connect to this endpoint and use two built-in tools — search_resources and proxy_tool_call — to discover and invoke paid x402 endpoints. The @x402/mcp client wraps a standard MCP client with automatic payment handling so agents never interact with wallets or signing directly.
The Bazaar MCP server is designed for consuming existing paid endpoints. To build your own MCP server that accepts x402 payments from callers, see the MCP Server guide.

MCP tools

search_resources

Semantic search over the CDP Bazaar index. Returns matching resource descriptions, payment pricing, input/output schemas, and relevance-ordered results — the same data available through Search resources. Arguments:
ArgumentTypeRequiredDescription
querystringNoFree-text search query.

proxy_tool_call

Calls a discovered Bazaar resource by tool name and arguments. The @x402/mcp client intercepts any payment-required response from the server, automatically constructs a payment payload using the configured x402 client, attaches it to the MCP request’s _meta field, and retries. The server then verifies and settles the payment before forwarding the request to the resource server and returning the result. From the agent’s perspective this is a single callTool() call — the @x402/mcp client handles 402 detection, payment creation, and retry internally. Arguments:
ArgumentTypeRequiredDescription
toolNamestringYesThe name of the tool to call, as returned by search_resources.
...argsanyNoAdditional arguments forwarded to the target resource server.

Client setup

Install the required packages:
npm install @x402/mcp @x402/fetch @x402/evm viem @modelcontextprotocol/sdk
Connect an agent to the Bazaar MCP server:
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
import { createX402MCPClient } from "@x402/mcp";
import { x402Client } from "@x402/fetch";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";

// 1. Configure the x402 payment client with a signer
const paymentClient = new x402Client();
const signer = privateKeyToAccount(process.env.EVM_PRIVATE_KEY as `0x${string}`);
registerExactEvmScheme(paymentClient, { signer });

// 2. Connect a standard MCP client to the Bazaar server
const mcpClient = new Client({ name: "my-agent", version: "1.0.0" });
await mcpClient.connect(
  new StreamableHTTPClientTransport(
    new URL("https://api.cdp.coinbase.com/platform/v2/x402/discovery/mcp")
  )
);

// 3. Wrap with automatic payment handling
const client = createX402MCPClient(mcpClient, paymentClient, {
  autoPayment: true,
  onPaymentRequested: async (req) => {
    console.log(`Payment requested: ${req.price} on ${req.network}`);
    return true; // return false to cancel
  },
});

// 4. Search for available tools
const results = await client.callTool("search_resources", {
  query: "weather forecast",
});

// 5. Call a paid tool — payment is handled automatically
const weather = await client.callTool("proxy_tool_call", {
  toolName: "weather_tool",
  city: "San Francisco",
});

Payment flow

When an agent calls proxy_tool_call, the MCP client handles the payment loop automatically:
  1. Agent calls client.callTool("proxy_tool_call", { toolName, ...args }).
  2. @x402/mcp forwards the call to the Bazaar MCP server.
  3. If the target resource server requires payment, the Bazaar MCP server signals payment-required.
  4. @x402/mcp invokes onPaymentRequested (if configured) and, if approved, constructs a payment payload and attaches it to _meta on a retry call.
  5. The Bazaar MCP server calls /v2/x402/verify then /v2/x402/settle on the CDP Facilitator.
  6. After successful settlement, the MCP server forwards the original request to the resource server and returns the response to the agent.