# MCP for agents

How an agent connects to Abazi over MCP, the six tools it can call, and how it handles results and errors.

<ShortProductTruth>**One tool call. Every rail.** An agent in any MCP client buys with `request_purchase`. None of the six tools signs, moves funds or changes rules; the agent's credential only identifies it.</ShortProductTruth>

## Connect [#connect]

Abazi's MCP server speaks streamable HTTP at `https://api.52-28-238-205.sslip.io/mcp`, stateless, with JSON responses. The agent sends its credential in an `Authorization: Bearer agk_test_...` header on every request. Clients that only start local processes connect over stdio through the `mcp-remote` bridge. The same credential works for the REST API. An owner creates it in the Console; it is shown once and stored only as a hash.

Setup for each client, with copy-paste configuration and a first purchase, is in [Agents and harnesses](/docs/agents):

| Client | Connect |
| --- | --- |
| [Claude Code](/docs/agents/claude-code) | `claude mcp add --transport http abazi https://api.52-28-238-205.sslip.io/mcp --header "Authorization: Bearer $ABAZI_AGENT_KEY"` |
| [Claude Desktop](/docs/agents/claude-desktop) | `npx -y mcp-remote https://api.52-28-238-205.sslip.io/mcp --header "Authorization:Bearer ${ABAZI_AGENT_KEY}"` in `claude_desktop_config.json` |
| [Cursor](/docs/agents/cursor) | `"url": "https://api.52-28-238-205.sslip.io/mcp"` and an `Authorization` header in `mcp.json` |
| [Any MCP client](/docs/agents/any-mcp-client) | Streamable HTTP to `https://api.52-28-238-205.sslip.io/mcp` with a Bearer header |
| [JSON-RPC](/docs/agents/json-rpc) | Plain JSON-RPC 2.0 POSTs to `https://api.52-28-238-205.sslip.io/mcp`, no MCP client |
| [Local model on Tether QVAC](/docs/agents/local-model-qvac) | A model on your machine chooses the tools; the agent program holds the credential |

## Without an MCP client [#without-an-mcp-client]

The endpoint also answers plain JSON-RPC 2.0 POST requests, with no session and no MCP library: `tools/list` and `tools/call` with the same Bearer header. A script or a non-MCP agent framework calls the same six tools this way. See [JSON-RPC](/docs/agents/json-rpc).

## The tools [#the-tools]

Each tool has its own page with its input, its result, the reason codes an agent meets most and the matching REST operation.

<McpToolTable />

## What `request_purchase` returns [#what-request_purchase-returns]

| `status` | Meaning | What the agent does next |
| --- | --- | --- |
| `paid` | The payment confirmed. The result carries the resource, the amount, the network and a `receipt_id`. | Use the resource. Keep the receipt id. |
| `submitted` | The payment was sent and is waiting for confirmation on its network. | Call `get_purchase_status`, waiting `poll_after_ms` between calls. |
| `awaiting_approval` | The purchase crossed a threshold and waits for a person. | Poll `get_purchase_status`. The approval link expires after <Limit name="approvalTtl" />. |
| `free` | The resource needed no payment. | Use the resource. |

Payment and delivery are tracked separately: `get_purchase_status` returns a `payment_status` and a `fulfillment_status`, because paid does not always mean delivered.

## Rules for agents [#rules-for-agents]

- Use a **new `idempotency_key` per purchase**. Reusing a key with the same request returns the first result instead of buying twice, so a retry after a timeout is safe. Reusing it with a different request is refused with `IDEMPOTENCY_CONFLICT`.
- Name what to buy by `service_id` from `search_catalog`, or by `url` for a merchant not in the catalog. Never by price or address: Abazi prices the purchase itself.
- `purpose` (up to 500 characters) is shown to the approver and screened by Shield. It is not copied into the public receipt.
- Never retry a denial. Follow its `next_action`.

## Errors [#errors]

Business failures come back as an error result whose text is JSON:

```json title="MCP business error"
{ "error_code": "POLICY_DENIED", "reason_code": "BUDGET_EXCEEDED", "message": "...", "retryable": false, "next_action": "Call get_spending_status.", "intent_id": "pi_..." }
```

A wrong, rotated or revoked credential returns <ReasonCode code="AGENT_CREDENTIAL_INVALID" /> on every tool call. Malformed arguments use the protocol's own errors. Every `reason_code`, with its `next_action`, is in the [reason code reference](/docs/api/errors-and-reason-codes).

## Example [#example]

```json title="request_purchase arguments"
{
  "service_id": "svc_...",
  "task_id": "weekly-report-42",
  "idempotency_key": "weekly-report-42-forecast",
  "purpose": "Weather forecast for the logistics summary"
}
```

```json title="Result"
{
  "status": "paid",
  "intent_id": "pi_...",
  "decision": "ALLOW",
  "reason_code": "WITHIN_POLICY",
  "receipt_id": "rcpt_...",
  "amount_base_units": "50000",
  "asset": "USDC",
  "network": "solana:...",
  "rail": "x402",
  "resource": { "content_type": "application/json", "body": "..." }
}
```

## Next steps [#next-steps]

<Cards>
  <Card title="Agents and harnesses" href="/docs/agents" description="Connect Claude Code, Claude Desktop, Cursor, your own agent or a local model." />
  <Card title="An agent's first purchase" href="/docs/guides/first-purchase-mcp" description="Walk through a purchase from the first tool call to the receipt." />
  <Card title="Reason codes" href="/docs/api/errors-and-reason-codes" description="Handle every denial and approval request correctly." />
  <Card title="REST API" href="/docs/api" description="The same operations over HTTP." />
</Cards>

