> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cloud.coinbase.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Bazaar MCP Server

> Model Context Protocol server for AI agents to discover and call paid x402 endpoints.

```
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)](https://modelcontextprotocol.io) 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`](https://github.com/x402-foundation/x402/tree/main/typescript/packages/mcp) client wraps a standard MCP client with automatic payment handling so agents never interact with wallets or signing directly.

<Note>
  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](/x402/mcp-server).
</Note>

## 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](/api-reference/v2/rest-api/x402-facilitator/search-resources).

**Arguments:**

| Argument | Type   | Required | Description             |
| -------- | ------ | -------- | ----------------------- |
| `query`  | string | No       | Free-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:**

| Argument   | Type   | Required | Description                                                      |
| ---------- | ------ | -------- | ---------------------------------------------------------------- |
| `toolName` | string | Yes      | The name of the tool to call, as returned by `search_resources`. |
| `...args`  | any    | No       | Additional arguments forwarded to the target resource server.    |

## Client setup

Install the required packages:

```bash theme={null}
npm install @x402/mcp @x402/fetch @x402/evm viem @modelcontextprotocol/sdk
```

Connect an agent to the Bazaar MCP server:

```typescript theme={null}
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.

## Related

* [Search resources](/api-reference/v2/rest-api/x402-facilitator/search-resources) — REST alternative to `search_resources`
* [Browse the catalog](/api-reference/v2/rest-api/x402-facilitator/browse-the-catalog) — paginated catalog of all Bazaar resources
* [MCP Server guide](/x402/mcp-server) — build your own x402-enabled MCP server
* [Bazaar overview](/x402/bazaar)
* [`@x402/mcp` package](https://github.com/x402-foundation/x402/tree/main/typescript/packages/mcp)
