Skip to content

Your MCP Tool Is an API for an Unreliable Caller

#mcp #tool-design #llm-agents #api-design #idempotency

Your MCP Tool Is an API for an Unreliable Caller ​

I rebuilt the tool list for a small ledger server twice in one week. The first pass wrapped twelve operations inside a single ledger_admin(action, payload) tool. It took an afternoon and looked tidy. The second pass split the same work into five named tools, took considerably longer, and is the version I would ship.

The difference wasn't the protocol. MCP does its job in both versions: the agent discovers tools, picks one, calls it. The difference was the shape of the contract.

A tool is an API for a caller that is confident, fast, and sometimes wrong. That last property changes almost every design decision. A service caller arrives with credentials, docs, tests, and a stable request in mind. An agent arrives with a context window, no memory of yesterday's outage, and a habit of retrying after a timeout. It may call your tool thirty times in one session. It may fill a field with a plausible value that happens to be wrong because the schema allowed it.

When an agent fails, I keep finding the same thing: the protocol was fine, the tool was bad. A tool that returns four megabytes of JSON crowds the task out of context. A tool with an action enum and a free-form payload forces the model to guess structure. A tool that answers with a stack trace teaches the model nothing, so it calls again.

Start by counting the actions hidden in your biggest tool ​

Wrapping an admin API is the fastest way to build a bad MCP tool.

ledger_admin(action, payload) looks efficient. One tool, one schema, twelve behaviors. In practice the schema can't validate much beyond "this is an object." The description turns into a manual because the constraints live in prose. The server has to switch on action before it can even check permissions. And the audit log records that someone called ledger_admin, which tells an investigator nothing about what actually happened.

The same work fits in five tools:

  • get_invoice
  • list_invoices
  • create_refund_request
  • approve_refund
  • send_refund

Each name carries a verb and a resource. Each can have its own schema, its own policy, its own error codes, and its own approval rule. If send_refund needs a stricter gate than get_invoice, you can express that without an if on a string.

The rule I use is blunt. If the description has to contain the phrase "depending on the action," you have more than one tool. Split it.

Naming matters because the model picks by name first and description second. Use verb_resource. Singular for one item, a list_ prefix for a collection. Avoid fetch_data, handle, process, run. Vague names push the model into choosing by description, which is the weaker signal.

Quick Take: splitting one god tool into five named, typed tools is less about token savings and more about giving each operation a schema that validates, an error code the model can act on, and an audit entry a human can read.

Schemas do the work descriptions can't ​

The schema is the part of the contract a model can follow without reading prose. Assume the caller skims.

For inputs, a few rules pay for themselves immediately:

  • Typed IDs with a format, never any. A UUID-constrained invoiceId rejects the model's guess before your handler runs.
  • Money as amountMinor plus a currency code. Never a float. A float refund is a bug waiting for a rounding error to reach a customer.
  • RFC 3339 timestamps with an explicit timezone.
  • Enums for states instead of free text.
  • Bounded arrays and strings. A tool that accepts 10,000 ids in one call will eventually receive 10,000 ids, and then you own that loop.
  • Separate named fields over a filters object with an unknown shape. The model can fill status and createdAfter. It cannot reliably invent the keys of a dictionary you described in a sentence.

For outputs, one small object beats the raw upstream response every time. Paginate collections with a small default and a hard maximum. A default of 20 and a maximum of 50 is fine for most tools. Strip secrets, internal hostnames, raw stack traces, and unrelated customer records. If your SDK and client both support structured tool output, use it; otherwise return one compact JSON document in a text block.

Key numbers from the ledger sketch12 actions behind the single admin tool's enum. 5 named tools in the split version, one action each. 20 / 50 default and maximum page size for collection reads. 1 digest, bound to exact arguments, short expiry, consumed once per irreversible write.

Here's what a well-shaped read tool looks like:

ts
server.registerTool(
  "get_invoice",
  {
    title: "Get one invoice",
    description:
      "Return one invoice by id. Read only. Amounts are minor units. Use list_invoices to search. Fails with INVOICE_NOT_FOUND.",
    inputSchema: { invoiceId: z.string().uuid() },
    annotations: { readOnlyHint: true },
  },
  async ({ invoiceId }) => {
    const invoice = await ledger.getInvoice(invoiceId);
    if (!invoice) {
      return {
        isError: true,
        content: [{ type: "text", text: "INVOICE_NOT_FOUND: no invoice with that id." }],
      };
    }
    return { content: [{ type: "text", text: JSON.stringify(invoice) }] };
  },
);

Check the SDK version you're on. The registration shape has drifted across releases. The design points survive the drift.

Errors the model can act on ​

A stack trace is noise and an information leak at the same time. What the model needs is a stable code, the numbers required to correct the call, and a pointer to the next tool.

json
{
  "code": "AMOUNT_EXCEEDS_LIMIT",
  "message": "Refund amount 250000 is above the limit 100000.",
  "limitMinor": 100000,
  "hint": "Create an approval request, then call send_refund with its id."
}

The model can act on AMOUNT_EXCEEDS_LIMIT. It cannot act on "Internal Server Error." Keep terminal and retryable failures distinct, because a missing invoice will not appear on the second attempt while a rate limit will clear. If the result doesn't say which one happened, the model retries both and you get duplicate work.

The hint should name the next tool or the missing approval, not restate a policy document. That slot is for the single next step.

Reads can be broad. Writes should be narrow. ​

MCP tool annotations include readOnlyHint, destructiveHint, idempotentHint, and openWorldHint. Treat them as labels, not enforcement. A server can mark a write as read-only and nothing in the protocol stops it. Clients use these hints to decide when to prompt a human, and that prompt is a UX feature, not a security control.

Read tools can stay broad, but they still need bounds. A read tool that scans a table without a limit is a denial-of-service tool with a friendly name.

Write tools should be few and narrow, and they need two properties to survive a retry. First, accept an idempotency key, or derive one server-side from an approval record. An agent that times out on a refund will retry. Without a key the customer gets two refunds. With one, the second call returns the first result.

Second, split irreversible actions into preview and confirm:

The digest binds to the exact arguments and expires quickly. That gives a human something concrete to approve, and injected text cannot quietly edit the amount between preview and send.

I don't derive the idempotency key from the model. It has no way to know whether the previous call completed and the response was lost in transit. It will happily generate a fresh key on retry and hand you a duplicate. Derive the key from the approval record or the refund's own identity, on the server.

Skip batch write tools unless the domain demands them. A tool that takes an array of refunds needs a policy for partial failure, ordering, and atomicity, and most agents can loop over single calls and report each result.

Descriptions carry the contract too ​

The model chooses by name and description. A weak description breaks tool selection even when every schema is perfect.

Weak: "Gets invoice."

Strong: "Return one invoice by id. Read only. Amounts are minor units. Does not list invoices; use list_invoices. Fails with INVOICE_NOT_FOUND."

Four things, every time: what it does, what it does not do, the units, and the tool to use instead. Marketing language burns context and makes the tool sound less precise than it is.

One caveat I keep in mind. A description is a claim by the server. A third-party server can describe a read tool that writes, or a narrow tool that proxies a shell. The client trusts the code, not the prose. Install servers you've reviewed, and don't let an agent install a new one for itself.

Authorization has to live in the server ​

Transport authentication identifies a session. On HTTP transports that might be an OAuth token. It does not answer whether this call may touch invoice 4412 for tenant 12.

Never accept tenantId or userId as ordinary tool arguments and trust them. If the model supplies the tenant, injected text can supply the tenant. Derive the principal from the authenticated session, then check the resource against it. If your transport can't carry a principal, run one server instance per tenant or keep a session-to-principal map on the server side. Don't push that map into the model.

Scope credentials per server. A read-only server and a write server shouldn't share a token. If the agent only needs to read invoices, that server doesn't get a payment key, and a bad prompt has less to reach.

Log every call with the authenticated principal, tool name, redacted arguments, and result code. Return a correlation id in the error payload so support can find the call.

Twelve actions against five tools ​

Here's how the two designs compare on the things that actually bite during an incident.

Propertyledger_adminFive named tools
Tools to choose from15
Actions per schema12, behind one enum1 per tool
Input typingFree-form payloadTyped fields per tool
Validation before the handlerLittlePer action
Permission checkSwitch on actionPer tool
Audit log entryledger_adminsend_refund, get_invoice
Error codesGenericStable per tool
Retry safetyDepends on the actionIdempotency key or digest

These are design accounting for two sketches, not a measurement of your server. Run the same count on yours: number of tools, actions per tool, typed fields, stable error codes, and one retry test per write tool.

Common Pitfalls ​

Splitting until the names blur. Five tools with near-identical names force the model to choose by description, which is the weaker signal. If two tools are hard to tell apart, merge them or rename them. Tool count is not the goal.

Putting a stack trace in the error result. It fills context with noise, it leaks internal hostnames and file paths, and it gives the model nothing to correct. A code plus one number beats a traceback every time.

Letting the model supply the tenant. Reading tenantId from arguments turns a hallucinated value into a cross-tenant write. Check where your server reads it from; if it's the argument list, move it to the session tonight.

Trusting readOnlyHint as a guardrail. Annotations change client behavior and nothing else. The server is the authority, so enforce read-only by not wiring write handlers into that server at all.

Accepting floats for money. Keep amountMinor as an integer plus a separate currency code. Float rounding on a refund is the kind of bug that surfaces in a reconciliation report two weeks later.

One Thing to Remember ​

Most of the cost in this design isn't the split itself. It's the plumbing that makes retries safe: idempotency keys, digest storage, stable codes, correlation ids. For an internal read-only tool with no side effects, you can skip nearly all of it. For anything that moves money or state, the plumbing is the feature.

The Bottom Line ​

If your agent touches money or irreversible state, build preview and confirm. A digest bound to exact arguments, short expiry, consumed once, plus a server-derived idempotency key. Without both, a timeout becomes a duplicate refund and you find out from a customer.

If you're exposing an existing admin API and the description needs "depending on the action," split it before launch. Start with whichever tool your agent calls most, give it a typed schema and one stable error code, and ship that single split first. You'll learn more from one instrumented tool than from a five-tool rewrite done blind.

If your transport can't carry a principal, stop and fix that first. One server instance per tenant, or a server-side session map. Any authorization design where tenantId arrives in the argument list is a prompt injection away from a cross-tenant write, and annotations won't save you.