All posts
Engineering

Designing MCP tools that AI agents can afford to use

How we designed the Won.dev MCP server so agents see the cost of every call, stay within a budget and recover from errors on their own.

Won.dev team

An AI agent that only reads documents can't do much damage. An agent that buys data or sends emails spends real money and acts in your name. When we designed the Won.dev MCP server, we started from one question: what does an agent need to know to spend money responsibly?

Our answer has four parts: the agent must see costs, it must have a hard limit, it must understand its errors, and the tools must be the same ones your code uses.

Every result carries its cost

A person sees a price tag before they buy. An agent only sees what a tool returns. So every Won.dev tool result includes a usage object:

{
  "importers": 128,
  "top": { "name": "Acme Seating Co.", "shipments": 46 },
  "usage": { "cost": 0.12, "balance": 48.08 }
}

With the cost in context, the model can reason about it: "That search cost $0.12 and found 128 importers. Fetching full profiles for the top 10 is worth it." Without it, the model can only guess. We put the cost in the result itself, not in a separate billing tool, because the agent then sees it at the moment it decides on the next step.

Limits the agent cannot cross

Seeing costs is not enough. Models make mistakes, loop, or misread a task. So limits are enforced by the server, not by the prompt:

  • A budget per API key. Give each agent its own key with a spending limit. When it is used up, calls fail.
  • max_cost per call. The agent, or your code, can cap a single call. If the call would cost more, it fails with budget_exceeded before any work is done.
  • Failed calls are free. A call that fails because of a limit costs nothing, so a limit never causes a charge.

This gives you a simple rule you can trust: an agent can never spend more than its key allows, whatever it decides to do.

Errors written for the model

Agents read error messages literally. "Bad request" leaves a model with nothing to do. Every Won.dev error has a stable code, a message and a hint that says what to do next:

{
  "error": {
    "code": "budget_exceeded",
    "message": "This request would cost more than `max_cost` or the key's remaining budget.",
    "hint": "Raise `max_cost`, raise the key's budget in the console, or narrow the request."
  }
}

The hint is written as an instruction the agent can follow. In practice this lets agents recover on their own: they narrow the request, for example with a lower limit or a shorter date range, or they stop and ask you to raise the budget. The full list is in the error reference.

Typed tools with plain parameters

Models call tools more reliably when the parameters say what they mean. We use names like hs_code, importer_country and since instead of a query language, and every tool has a JSON schema with a short description of each field. A model doesn't have to learn our syntax. It fills in a form.

We also keep one task per tool. trade_search_companies finds buyers or suppliers and trade_get_company returns one company's profile. Small tools are easier for a model to choose between than one tool with many modes.

The same API underneath

MCP tools call the same API as your code, with the same prices, limits and errors. This matters for two reasons. You can prototype a workflow with an agent and later move it into code without surprises. And there is only one set of rules to understand, test and audit.

Try it

Add the server to your MCP client with your API key:

{
  "mcpServers": {
    "won": {
      "url": "https://won.dev/mcp",
      "headers": { "Authorization": "Bearer won_live_..." }
    }
  }
}

Then ask your agent to find importers of a product. Trade data tools are live today. Enrichment, email and messaging tools join the same server as they launch. Create an API key to start.

From cold list to closed won

Create an API key, try every endpoint free with a test key, then pay only for the results you get.

Get API key