# Example: a cash-or-points agent

An agent that answers "cash or points?" for a hotel stay. In Claude with no code, in one file on the Claude API, or with any model through MCP.

A traveller asks: _Hyatt Place Chicago Downtown The Loop, 2 nights from 15 January: cash or points?_ The agent finds the hotel, reads the price in cash and in points from the chain’s own booking system, and answers with the break-even: the stay is worth paying in points if a point is worth less to you than so many cents.

It needs two of the [MCP server](https://directrate.dev/docs/mcp.md)’s sixteen tools:

| Tool     | What it answers                                                                                   |
| -------- | ------------------------------------------------------------------------------------------------- |
| `hotels` | The chain’s code for a hotel named in words: “Hyatt Place Chicago Downtown The Loop” is `CHIZP`   |
| `award`  | The stay in points, the cash price of the same stay, and the cents per point the points would buy |

There are three ways to run it, from no code at all to your own stack. Both files on this page are also [on GitHub](https://github.com/directrate/hotel-rates-mcp/tree/main/examples/cash-or-points), with a `package.json` to install what they need.

## In Claude, with no code

Add directrate as a connector once:

```text
Customize → Connectors → + Add → Add custom connector
Name:  directrate
URL:   https://api.directrate.dev/mcp
→ Continue → keep the two options Claude marks "Detected"
  (Sign in now, Register automatically)
→ Add → Connect → sign in to directrate → choose the API key it may use → Allow
```

Then, in a chat, open the **+** menu, switch the directrate connector on, and ask the question in your own words. Claude asks permission the first time it uses a tool. There is no key to paste: the sign-in gives the connector a key of its own on your account, which you can revoke in the [dashboard](https://directrate.dev/dashboard/keys).

Claude decides which tools to call. When we asked the question above on 24 November 2026 it called `hotels`, `shop` and `award`, which cost 3 credits.

## On the Claude API, in one file

Anthropic’s [MCP connector](https://platform.claude.com/docs/en/agents-and-tools/mcp-connector) calls the MCP server on Claude’s side, so the agent has no tool loop: one request returns the tool calls, what they returned, and the answer.

You need a directrate key (free in the [dashboard](https://directrate.dev/dashboard/keys)) and a Claude API key from the [Anthropic Console](https://console.anthropic.com). In an empty folder:

```sh
npm init -y && npm pkg set type=module
npm install @anthropic-ai/sdk && npm install -D tsx
```

Save this as `agent.ts`:

```ts
/**
 * Cash or points? A hotel question answered by Claude, with directrate's MCP server as its tools.
 *
 *   export ANTHROPIC_API_KEY=...     # https://console.anthropic.com
 *   export DIRECTRATE_API_KEY=...    # https://directrate.dev/dashboard/keys (the Free plan is enough)
 *   npx tsx agent.ts "Hyatt Place Chicago Downtown The Loop, 2 nights from 15 January"
 *
 * There is no tool loop in this file. Anthropic's MCP connector calls https://api.directrate.dev/mcp
 * itself, with your directrate key as the bearer token, and the whole exchange comes back in one
 * response: the tool calls Claude made, what they returned, and the answer.
 */
import Anthropic from "@anthropic-ai/sdk";

const question = process.argv.slice(2).join(" ") || "Hyatt Place Chicago Downtown The Loop, 2 nights from 15 January";
const directrateKey = process.env.DIRECTRATE_API_KEY;
if (!directrateKey) {
  console.error("Set DIRECTRATE_API_KEY. A key is free at https://directrate.dev/dashboard/keys");
  process.exit(1);
}

const SYSTEM = `You answer one question for a traveller: is this hotel stay better paid in cash or in points?

Your tools read live prices from the hotel chain's own booking system.
- If you were not given the chain's hotel code, find it with \`hotels\`: one search by the hotel's name and city.
- Then call \`award\` once for the stay. It returns the price in points, the cash price of the same stay and the cents per point (cpp) that the points would buy.

Answer in at most six short lines: the hotel and the dates, the cash price (and the member rate when it is lower), the price in points, the cents per point, and the verdict as a break-even, for example "use points if you value a point at less than 1.4 cents". The traveller knows what a point is worth to them and you do not, so do not judge with a valuation of your own unless they gave one.

If the stay cannot be booked with points, or a tool fails, say so plainly and give the cash price if you have it. End with the number of credits the calls cost.`;

const client = new Anthropic(); // reads ANTHROPIC_API_KEY

const messages: Anthropic.Beta.BetaMessageParam[] = [
  // today's date goes with the question, so "15 January" means the next one
  { role: "user", content: `Today is ${new Date().toISOString().slice(0, 10)}.\n\n${question}` },
];

/** One request. Claude calls the tools on Anthropic's side, so this resolves with the finished turn. */
const ask = () =>
  client.beta.messages.create({
    model: "claude-opus-5-5",
    max_tokens: 16000,
    output_config: { effort: "medium" },
    system: SYSTEM,
    messages,
    mcp_servers: [{ type: "url", url: "https://api.directrate.dev/mcp", name: "directrate", authorization_token: directrateKey }],
    // two of the server's sixteen tools are all this question needs; the rest stay out of the prompt
    tools: [{
      type: "mcp_toolset",
      mcp_server_name: "directrate",
      default_config: { enabled: false },
      configs: { hotels: { enabled: true }, award: { enabled: true } },
    }],
    betas: ["mcp-client-2025-11-20", "server-side-fallback-2026-07-01"],
    // if Claude declines the request, the API retries it on a fallback model inside the same call
    fallbacks: "default",
  });

let response: Anthropic.Beta.BetaMessage;
for (let turn = 0; ; turn++) {
  try {
    response = await ask();
  } catch (e) {
    // most specific first: what the person can fix themselves, then everything else
    if (e instanceof Anthropic.AuthenticationError) console.error("Claude did not accept the API key. Check ANTHROPIC_API_KEY.");
    else if (e instanceof Anthropic.RateLimitError) console.error("Claude's rate limit was reached. Try again in a minute.");
    else if (e instanceof Anthropic.APIError) console.error(`Claude API error ${e.status}: ${e.message}`);
    else console.error(e instanceof Error && /authentication method/i.test(e.message) ? "Set ANTHROPIC_API_KEY (https://console.anthropic.com)." : e);
    process.exit(1);
  }

  // what happened, in order: each tool call, the first line of what it returned, then the answer
  for (const block of response.content) {
    if (block.type === "mcp_tool_use") {
      console.log(`→ ${block.name}(${JSON.stringify(block.input)})`);
    } else if (block.type === "mcp_tool_result") {
      const text = typeof block.content === "string" ? block.content : block.content.map((c) => c.text).join("\n");
      console.log(`  ${block.is_error ? "failed: " : ""}${text.split("\n")[0]}`);
    } else if (block.type === "text") {
      console.log(`\n${block.text}`);
    }
  }

  // a long run of tool calls can pause; sending the turn back lets the server carry on where it stopped
  if (response.stop_reason !== "pause_turn" || turn >= 4) break;
  messages.push({ role: "assistant", content: response.content });
}

if (response.stop_reason === "refusal") {
  console.error(`\nThe request was declined (${response.stop_details?.category ?? "no category"}).`);
  process.exit(1);
}
const u = response.usage;
console.log(`\n[${response.model} · ${u.input_tokens} tokens in, ${u.output_tokens} out]`);
```

Run it:

```sh
export DIRECTRATE_API_KEY=dr_live_...
export ANTHROPIC_API_KEY=sk-ant-...
npx tsx agent.ts "Hyatt Place Chicago Downtown The Loop, 2 nights from 15 January"
```

It prints each tool call as Claude made it, the first line of what the server answered, then Claude’s answer. Three things in the file are worth a second look:

- **The connector block.** `mcp_servers` names the server and carries your directrate key as `authorization_token`; Anthropic sends it as the bearer token when it calls us. It is your key, your credits and your quota, so use a key made for this and revoke it when you are done.
- **Two tools, not sixteen.** `default_config: { enabled: false }` with two entries in `configs` keeps the other fourteen tool descriptions out of the prompt.
- **A break-even, not a verdict.** The prompt asks for “use points if you value a point at less than 1.4 cents”, because what a point is worth is the traveller’s call and not the model’s.

This file is new. It is checked against the types of `@anthropic-ai/sdk` 1.13.0, and the two tool calls it leads to are the ones `tools.ts` below makes against the live server. If it does not run for you, write to <hello@directrate.dev>.

## With another model or framework

Nothing above is specific to Claude. directrate is a standard MCP server over Streamable HTTP: any MCP client connects with a key from the [dashboard](https://directrate.dev/dashboard/keys) as a bearer token, lists the tools to hand to its model, and runs the calls the model asks for. This file makes the agent’s two calls with the MCP TypeScript SDK and no model at all (`npm install @modelcontextprotocol/sdk`, save as `tools.ts`, `npx tsx tools.ts`):

```ts
/**
 * The same two tools without a model: for an agent built on another model or framework.
 *
 *   export DIRECTRATE_API_KEY=...    # https://directrate.dev/dashboard/keys
 *   npx tsx tools.ts
 *
 * directrate is a standard MCP server (Streamable HTTP). Any MCP client connects with the key as a
 * bearer token, lists the tools to hand to its model, and runs the calls the model asks for.
 */
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";

const key = process.env.DIRECTRATE_API_KEY;
if (!key) {
  console.error("Set DIRECTRATE_API_KEY. A key is free at https://directrate.dev/dashboard/keys");
  process.exit(1);
}

const transport = new StreamableHTTPClientTransport(new URL("https://api.directrate.dev/mcp"), {
  requestInit: { headers: { Authorization: `Bearer ${key}` } },
});
const client = new Client({ name: "cash-or-points", version: "0.1.0" });
await client.connect(transport);

// what you would hand to your model as its tools: name, description and JSON schema of each
const { tools } = await client.listTools();
console.log(`${tools.length} tools: ${tools.map((t) => t.name).join(", ")}\n`);

// the two calls the agent makes: find the hotel's code, then price the stay in points and in cash
const found = await client.callTool({ name: "hotels", arguments: { chain: "hyatt", q: "Hyatt Place Chicago Downtown The Loop", limit: 3 } });
const hotel = (found.structuredContent as { hotels: { code: string; name: string }[] }).hotels[0]!;
console.log(`hotels → ${hotel.code} ${hotel.name}`);

const stay = await client.callTool({ name: "award", arguments: { chain: "hyatt", hotel_code: hotel.code, checkin: "2027-01-15", los: 2 } });
const a = stay.structuredContent as { lowest_points: number | null; cpp: number | null; cash_comparison: { lowest_cash: number | null; currency: string } | null; credits_charged: number };
console.log(`award  → ${a.lowest_points} points a night, ${a.cash_comparison?.lowest_cash} ${a.cash_comparison?.currency} a night in cash, ${a.cpp} cents per point (${a.credits_charged} credit)`);

await client.close();
```

Its output on 24 November 2026; the prices are live, so yours will differ:

```text
16 tools: shop, award, parity, calendar, compset, stay, hotels, hotel, matrix, job, job_cells, watches, watch_create, watch_delete, chains, usage

hotels → CHIZP Hyatt Place Chicago/Downtown-The Loop
award  → 12000 points a night, 174.56 USD a night in cash, 1.45 cents per point (1 credit)
```

Hand your model two of the sixteen tools, `hotels` and `award`, to keep its prompt small, and ask it for a break-even (“use points if you value a point at less than 1.4 cents”) and not a verdict: what a point is worth is the traveller’s call, not the model’s. Add `parity` to compare the hotel’s own price with Booking.com, Expedia, Hotels.com, Trip.com and Agoda, or `calendar` for a month of nights in one call.

If your stack has no MCP client at all, the same two calls are plain HTTP: [`GET /v1/hotels`](https://directrate.dev/docs/quickstart.md) and [`POST /v1/award`](https://directrate.dev/docs/modes/award.md).

## What it costs

- **directrate:** one credit per tool call on Hyatt, so two for the question when the agent calls `hotels` and `award`. Every answer states its own price, and a call that fails costs nothing. Other chains weigh differently: [Credits & pricing](https://directrate.dev/docs/credits-and-pricing.md).
- **Your model:** its own tokens. With two tools handed to it, the request is small.

The Free plan’s 250 credits a month cover about 125 questions like this one.

---

This page for people: https://directrate.dev/docs/cash-or-points-agent
