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

# Quickstart: protect a payment tool

> Register an MCP server, hold large payments for a person's approval, approve in the dashboard, retry with the Python or TypeScript helper, and verify the record offline.

You will route an agent's calls to a payment tool through the gateway, hold any payment above a limit for a person to approve, and check the record offline. About 20 minutes.

> [!NOTE]
>
> Approval holds for MCP tool calls are a **Preview** and are not available on every workspace. The switch is per workspace and off by default. The signed approval record is a **Preview**: we have not yet observed it with a real approval in production, and the helpers below do not read or verify it. See [Approvals for held tool calls](https://docs.tracelane.dev/integrations/approvals.md) for the full behaviour.

## What you need

* A workspace where you are an owner or admin.
* An MCP server reachable over HTTPS that exposes a payment tool. The examples use `release_payment` with the arguments `amount`, `currency` and `beneficiary`.
* A Tracelane API key with the **MCP** scope (Settings → Keys → Agent keys). A key made before that scope existed does not have it.

## Step 1 — Turn on action control

Sign in as an owner or admin and open **Settings → Workspace**. Under **Action control (preview)**, tick **Turn on action control** and confirm. Only owners and admins can change it, and the change is recorded in the change log.

It applies to this workspace only. It usually takes effect within 15 minutes, and the first agent call after a quiet period may still use the old setting. Until it is on, the policy and actions pages answer that action control is off.

## Step 2 — Register the MCP server

Open **Agents & tools → MCP servers** and choose **Add server**. Fill in:

| Field | Example | Notes |
| - | - | - |
| Server name | `Payments tool server` | |
| Endpoint slug | `payments` | Lowercase letters, digits and `-`, up to 48 characters. It becomes your gateway endpoint. |
| Upstream URL | `https://mcp.example.com/mcp` | Must be `https`. Addresses that resolve to private networks are refused. |
| Transport | **Streamable HTTP** (`streamable_http` in the API) | Protected tools need this one. |
| Upstream authentication | **Stored credential** (`gateway_held`) | The gateway stores your upstream token encrypted and adds it to each call. **No credential** (`none`) and **Client supplies credential** (`passthrough`) also exist. |

The same call is `POST /v1/mcp-servers`. It needs an owner or admin credential: a tenant API key cannot register a server.

```bash theme={"system"}
curl -X POST https://gateway.tracelane.dev/v1/mcp-servers \
  -H "Authorization: Bearer $OWNER_CREDENTIAL" \
  -H "Content-Type: application/json" \
  -d '{
    "slug": "payments",
    "name": "Payments tool server",
    "url": "https://mcp.example.com/mcp",
    "transport": "streamable_http",
    "auth_mode": "gateway_held",
    "credential_kind": "bearer",
    "credential": "<your upstream token>"
  }'
```

The page then shows **Gateway endpoint: `/v1/mcp/payments`**. A workspace can register up to 20 servers.

## Step 3 — Apply the Payments template

Open **Rules**, choose **Start from a template**, then **Payments**, and set:

| Field | Example |
| - | - |
| Tool server | the server from Step 2 |
| Tool name | `release_payment` |
| Currency the tool pays in | `USD`. Any currency in the gateway's ISO 4217 catalogue can be chosen; your workspace's home currency is selected first. |
| Hold payments above | `5000`, in the number format your workspace uses (for example `5,000` or `5.000`) |
| Approval window (minutes) | `60` |
| The tool's amount is in | `Smallest unit of USD` (an amount of 1500 is 15 dollars), or whole units if that is what your tool takes. There is no default; you must choose. |
| Approved beneficiaries | `acme-ltd` and `globex`, one per line |
| Argument names | only if your tool names `amount`, `currency` or `beneficiary` differently |

Choose **Publish policy** and confirm. The policy has four rules, first match wins:

1. A payment up to the limit to an approved beneficiary is **allowed**.
2. A payment above the limit to an approved beneficiary is **held for approval** of that exact payment.
3. A payment to any other beneficiary is **denied**.
4. Anything else is **denied**, so a call no rule describes is never a surprise.

The tool's `amount` is read as a whole number in the unit you chose, and `currency` must be the code you chose (here `USD`); a call in any other currency is refused, not converted or guessed at.

## Step 4 — Point the MCP client at the gateway

Use `https://gateway.tracelane.dev/v1/mcp/payments` as the server URL, with your MCP-scoped key as the bearer token:

```bash theme={"system"}
KEY=$(uuidgen)   # one per payment; reuse it on the retry in Step 7

curl -X POST https://gateway.tracelane.dev/v1/mcp/payments \
  -H "Authorization: Bearer $TRACELANE_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -H "Idempotency-Key: $KEY" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "tools/call",
    "params": {
      "name": "release_payment",
      "arguments": { "amount": 750000, "currency": "USD", "beneficiary": "acme-ltd" }
    }
  }'
```

The gateway passes `initialize`, `tools/list`, `tools/call` and the other standard MCP methods through. If your server needs a session, send `initialize` first and pass its `mcp-session-id` header on later calls, as any MCP client does.

## Step 5 — Send an Idempotency-Key

A protected tool requires an `Idempotency-Key` header on every `tools/call`, as in Step 4. Without one the gateway answers `400 idempotency_key_required`.

* It must be a UUID. Anything else, or a repeated header, is refused with `400 invalid_idempotency_key`, and the answer names the header.
* Make one per logical payment, not per attempt, and reuse it on the retry after approval with the same arguments. Once a call has run under a key, a different body under that key is refused as `idempotency_mismatch`.
* Send the header once. Repeated headers are refused.

## Step 6 — See the hold, then approve

The call in Step 4 is 750000 cents, 7,500 dollars, above the 5,000 dollar limit. The gateway detects it and holds it. The agent gets `409`, not the tool result:

```json theme={"system"}
{ "error": "approval_required", "approval_id": "<uuid>", "expires_at": "<time>" }
```

If your workspace has Slack or email alerts set up, approvers are notified; the message names the tool, the server, the rule and the expiry, but not the arguments.

An owner or admin opens **Approvals**. The queue lists pending requests; choose **Approve** or **Deny**, with an optional note. **Approving needs a recent sign-in.** If yours is too old the gateway refuses with `reauth_required`: sign in again and retry. A tenant API key cannot approve.

## Step 7 — Retry with the SDK helper

The helpers wait for the decision and retry the identical call once. They do not decide anything: a retry that has no approval is held again by the gateway. Create the `Idempotency-Key` outside the retried function so both attempts carry it.

```python theme={"system"}
import os
import uuid
import httpx
from tracelane.approvals import with_approval

GATEWAY = "https://gateway.tracelane.dev"
API_KEY = os.environ["TRACELANE_API_KEY"]

async def release_payment(amount: int, beneficiary: str):
    key = str(uuid.uuid4())  # one key per payment; the retry reuses it

    async def call():
        async with httpx.AsyncClient(timeout=125) as http:  # a protected tool call may run up to 120 s
            return await http.post(
                f"{GATEWAY}/v1/mcp/payments",
                headers={
                    "Authorization": f"Bearer {API_KEY}",
                    "Accept": "application/json, text/event-stream",
                    "Idempotency-Key": key,
                },
                json={"jsonrpc": "2.0", "id": 1, "method": "tools/call",
                      "params": {"name": "release_payment",
                                 "arguments": {"amount": amount, "currency": "USD",
                                               "beneficiary": beneficiary}}},
            )

    return await with_approval(call, base_url=GATEWAY, api_key=API_KEY)()
```

```ts theme={"system"}
import { withApproval } from "@tracelanedev/sdk/approvals";
import { randomUUID } from "node:crypto";

const GATEWAY = "https://gateway.tracelane.dev";
const API_KEY = process.env.TRACELANE_API_KEY!;

export async function releasePayment(amount: number, beneficiary: string) {
	const key = randomUUID(); // one key per payment; the retry reuses it
	const call = async () => {
		const res = await fetch(`${GATEWAY}/v1/mcp/payments`, {
			method: "POST",
			headers: {
				Authorization: `Bearer ${API_KEY}`,
				"Content-Type": "application/json",
				Accept: "application/json, text/event-stream",
				"Idempotency-Key": key,
			},
			body: JSON.stringify({
				jsonrpc: "2.0",
				id: 1,
				method: "tools/call",
				params: { name: "release_payment", arguments: { amount, currency: "USD", beneficiary } },
			}),
		});
		return res.json(); // the helper reads the parsed body
	};
	return withApproval(call, { baseUrl: GATEWAY, apiKey: API_KEY })();
}
```

If the decision is denied, expired or times out, the helper returns a short message saying the action was not performed and should not be retried. For LangGraph, see [Approvals for held tool calls](https://docs.tracelane.dev/integrations/approvals.md#langgraph-python).

## Step 8 — Export and verify offline

Approval decisions on the default path are written to the workspace's hash-chained ledger. Export a range that covers your test and replay it on your own machine with the open-source verifier. There is no pre-built binary yet, so build it from source:

```bash theme={"system"}
git clone https://github.com/tracelane/tracelane.git
cd tracelane
cargo build --release -p tracelane-audit

./target/release/tracelane-audit verify \
  --workspace <your-workspace-uuid> \
  --from 2026-11-21T00:00:00Z \
  --to   2026-11-22T00:00:00Z \
  --read-key $TRACELANE_AUDIT_READ_KEY \
  --tenant-pubkey <workspace-ed25519-pubkey>
```

Or verify a file you exported yourself: `tracelane-audit verify --file ./audit-range.ndjson --tenant-pubkey <pubkey>`. Get the public key from **Evidence → Signing key** or `GET /v1/audit/pubkey`, never from the export you are checking. Only exit code `0` is a pass; `3` means the chain is consistent but no public anchor covers it yet, which is normal for a new workspace. Details: [Verifier CLI](https://docs.tracelane.dev/audit/verifier-cli.md) and [Audit ledger](https://docs.tracelane.dev/audit-ledger.md).

## Limits

Protected tools need the `streamable_http` transport and an `Idempotency-Key`; one retry after approval, and only before the approval's `expires_at`; the Payments template takes one currency per tool and never converts between currencies; 20 servers per workspace; holds and the signed approval record are a Preview.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.