# An agent's first purchase through MCP

Connect an agent to Abazi's MCP server with its credential, find a service, buy it with one tool call and handle a payment, an approval or a denial.

<ShortProductTruth>**One tool call. Every rail.** The agent asks for a service; Abazi quotes it, decides under the owner's mandate, pays on whichever rail and network the mandate allows, and hands back the resource with a receipt.</ShortProductTruth>

## What you end up with [#what-you-end-up-with]

An agent in an MCP client that can buy a paid data service in one call and gets back three things: the data it asked for, a receipt id it can show the owner, and, when it may not buy, a reason code that says what to do next. The agent never holds a wallet key, a card number or its own limits.

## Before you start [#before-you-start]

| You need | Why |
| --- | --- |
| An agent created in the Console (**Agents > New agent**), with its credential | The credential identifies the agent. It carries no spending power on its own. |
| A signed mandate for that agent | Without one, every purchase is denied with <ReasonCode code="MANDATE_MISSING" />. See [Write a mandate](/docs/guides/write-a-mandate). |
| Funds on an allowed network | A capped delegation on Solana, or a funded spending wallet on another network. |

## Steps [#steps]

<Steps>
<Step>

### Connect the agent [#connect-the-agent]

Abazi's MCP server speaks streamable HTTP at `https://api.52-28-238-205.sslip.io/mcp`. The agent sends its credential as a Bearer token on every request. Clients that only start local processes reach it over stdio through the `mcp-remote` bridge. In Claude Code it is one command:

```bash title="Terminal"
claude mcp add --transport http abazi https://api.52-28-238-205.sslip.io/mcp --header "Authorization: Bearer $ABAZI_AGENT_KEY"
```

Clients that take a JSON configuration, such as Cursor, use a URL and a header:

```json title="mcp.json"
{
  "mcpServers": {
    "abazi": {
      "url": "https://api.52-28-238-205.sslip.io/mcp",
      "headers": { "Authorization": "Bearer YOUR_AGENT_KEY" }
    }
  }
}
```

Set `ABAZI_AGENT_KEY` to your agent credential, and replace `YOUR_AGENT_KEY` with it in JSON configurations: create one in the [Console](https://app.52-28-238-205.sslip.io) under **Agents > New agent** (shown once).

Exact setup for each client is in [Agents and harnesses](/docs/agents): [Claude Code](/docs/agents/claude-code), [Claude Desktop](/docs/agents/claude-desktop), [Cursor](/docs/agents/cursor) and [any MCP client](/docs/agents/any-mcp-client).

The agent now sees six tools. None of them signs, moves funds outside a purchase or changes rules.

<McpToolTable />

</Step>
<Step>

### Find a service [#find-a-service]

The agent calls `search_catalog` with a query. Each result carries a service id, the merchant and its trust tier, the price in base units, the asset and the networks. Searching spends nothing.

```json title="search_catalog result"
{
  "services": [
    {
      "service_id": "svc_...",
      "name": "Weather forecast",
      "merchant": "Forecast Co",
      "tier": "VERIFIED",
      "price_base_units": "50000",
      "asset": "USDC",
      "chains": ["solana:...", "eip155:..."]
    }
  ]
}
```

An agent can also buy from a URL that is not in the Catalog. If the URL answers with a valid x402 402 response, Abazi adds the merchant as UNKNOWN and the unknown-merchant limit applies.

</Step>
<Step>

### Ask to buy [#ask-to-buy]

The agent calls `request_purchase` with the service id (or a URL), a task id and a fresh idempotency key. It does not send a price, an address or a network: Abazi takes those from the Catalog and the mandate.

```json title="request_purchase arguments"
{ "service_id": "svc_...", "task_id": "trip-plan-7", "idempotency_key": "trip-plan-7-forecast-1" }
```

Reusing the same key with the same request returns the same purchase, so a retry after a dropped connection never pays twice. Reusing it with a different request is refused.

</Step>
<Step>

### Read the result [#read-the-result]

The call waits up to 20 seconds by default for the payment to settle, then returns one of three shapes.

<Tabs items={['Paid', 'Waiting for approval', 'Denied']}>
<Tab value="Paid">

```json title="Paid"
{
  "status": "paid",
  "intent_id": "pi_...",
  "decision": "ALLOW",
  "reason_code": "WITHIN_POLICY",
  "receipt_id": "rcpt_...",
  "amount_base_units": "50000",
  "asset": "USDC",
  "network": "solana:...",
  "rail": "x402",
  "merchant": { "name": "Forecast Co", "tier": "VERIFIED" },
  "resource": { "content_type": "application/json", "body": "{\"city\":\"Tbilisi\",\"high_c\":14}" }
}
```

If the payment has not settled within the wait, `status` is `submitted` with a hint to poll after two seconds.

</Tab>
<Tab value="Waiting for approval">

```json title="Waiting for approval"
{
  "status": "awaiting_approval",
  "intent_id": "pi_...",
  "decision": "REQUIRE_APPROVAL",
  "reason_code": "ABOVE_AUTO_THRESHOLD",
  "approval_expires_at": "2026-11-16T10:10:00Z",
  "poll_after_ms": 5000
}
```

The agent does not get the approval link; approvers do. The agent keeps the same intent and polls `get_purchase_status` every `poll_after_ms`. A rejected or expired approval ends as `denied` with <ReasonCode code="APPROVAL_REJECTED" /> or <ReasonCode code="APPROVAL_EXPIRED" />. See [Approve on a phone](/docs/guides/approve-on-a-phone).

</Tab>
<Tab value="Denied">

```json title="Denied, returned as an error result"
{
  "error_code": "POLICY_DENIED",
  "reason_code": "HARD_CAP_EXCEEDED",
  "message": "...",
  "retryable": false,
  "next_action": "Choose a cheaper service or ask the owner to change the mandate. Do not retry this purchase.",
  "intent_id": "pi_..."
}
```

A denial is final for that purchase. The agent should follow `next_action` and never retry with a new idempotency key.

</Tab>
</Tabs>

</Step>
<Step>

### Show the receipt [#show-the-receipt]

The agent calls `get_receipt` with the receipt id. It gets the signed receipt and a public verification link that anyone can open without an account. See [Verify a receipt](/docs/guides/verify-a-receipt).

</Step>
</Steps>

<Screenshot id="developers-mcp" />

## What the agent should do with each outcome [#what-the-agent-should-do-with-each-outcome]

| Outcome | Agent action |
| --- | --- |
| `paid` | Use the resource; keep the receipt id. |
| `submitted` | Poll `get_purchase_status` after the suggested delay. |
| `awaiting_approval` | Poll with the same intent; tell the user a person is deciding. |
| Denied, `retryable: true` | Wait and try later, for example after <ReasonCode code="KILL_SWITCH_ACTIVE" /> is lifted. |
| Denied, `retryable: false` | Stop and report the reason code and next action. |

Every code and its next action is in the [reason code reference](/docs/api/errors-and-reason-codes).

## Failure cases [#failure-cases]

| Situation | Result |
| --- | --- |
| The credential is wrong, rotated or revoked | Denied with <ReasonCode code="AGENT_CREDENTIAL_INVALID" />. |
| The budget left is too small | Denied with <ReasonCode code="BUDGET_EXCEEDED" />; `get_spending_status` shows what is left. |
| No allowed network is funded | Denied with <ReasonCode code="NO_FUNDED_CHAIN" />, with the candidate networks in the error. |
| The merchant's 402 asks for a different payout address | Denied with <ReasonCode code="PAYTO_MISMATCH" />. |

## Next steps [#next-steps]

<Cards>
  <Card title="Agents and harnesses" href="/docs/agents" description="Connect Claude Code, Claude Desktop, Cursor, an SDK or a local model." />
  <Card title="MCP tools" href="/docs/mcp" description="Look up every tool's inputs and outputs." />
  <Card title="Write a mandate" href="/docs/guides/write-a-mandate" description="Set the limits this agent buys under and sign them with a passkey." />
  <Card title="Payment lifecycle" href="/docs/architecture/payment-lifecycle" description="See what Abazi does between the call and the result." />
</Cards>

