
An existing API can now become an MCP server in a few clicks: API gateway products will publish an API’s existing operations as MCP tools, one tool per operation. Anthropic’s tool-design guidance calls this out: “A common error we’ve observed is tools that merely wrap existing software functionality or API endpoints (opens in a new tab)”.
A wrapper changes how the API is called. It does not change who decides what to call. A program’s decision (which call, with what intent) is written in code, so you can test it once and know it. An agent computes its decision from the input, the context and the wording of its tool descriptions.
Give an agent the same input and it might make the intended call, retry with a new key so a second order lands, or read “reorder” as “change” and call update_order. None of these paths is written down anywhere you can review.
What others have found
- Four models given identical inputs at temperature 0.7 produced “2.3-4.2 distinct action sequences per 10 runs” (Mehta (opens in a new tab), ICML 2026 workshop).
- Temperature 0 does not reliably fix it. In tau-bench (opens in a new tab), with the agent at temperature 0.0 and a simulated user at 1.0, gpt-4o completed 61.2% of retail tasks on one try and under 25% on all eight.
- Determinism can be engineered: Thinking Machines (opens in a new tab) made 1,000 temperature-0 completions identical with batch-invariant kernels. Wording still moves the decision. Editing tool descriptions alone gave a tool “up to 10× more usage” (Faghih et al. (opens in a new tab), EMNLP 2025).
- The protocol adds duplicates of its own. MCP 2026-07-28: “a broken response stream loses the in-flight request; clients MUST re-issue it as a new request with a new request ID” (changelog (opens in a new tab)). Tool annotations such as
idempotentHintare hints, and clients “MUST consider tool annotations to be untrusted unless they come from trusted servers” (tools spec (opens in a new tab)).
Where the contract lives
Put the contract outside the model. An instruction in the prompt is one more input the model weighs. A rule in the gateway applies to every call.
Anyone can wrap your API in an MCP server, and the API owner has no say in who does it or what its tool descriptions say. So put the MCP servers you host behind the same API gateway as the API. Every agent call then passes the gateway twice: once as a tool call, where it sees the tool and its arguments, and once as an API call, where it sees the write. Anyone else’s MCP server over your API still meets the second pass.
Most teams already have the door. Few have taught it what an agent needs. A gateway that authenticates the calling application and rate-limits it does not, on its own, know which agent is behind the call, recognise a re-issued write, or remember what the caller read before it writes.
Two things stay outside any gateway: tools built into the agent host, such as shell and file access, and MCP servers you do not host. For those, whoever runs the agent pins the tool descriptions it was approved to see.
Eight design principles
You likely use most of these patterns already. What changed is the caller.
| # | Principle | Where | Why |
|---|---|---|---|
| 1 | Sole path. Agent traffic reaches your tools and your API only through the gateway; only the gateway holds downstream credentials | Both hops | If the agent can route around a control, the control does not hold. Tools built into the agent host bypass anything in front of MCP; the MCP blog (opens in a new tab) notes shell risk applies “whether the tool arrived via MCP or was built into the host” |
| 2 | Identity per action. Every call carries who asked, which agent, which tool version | Both hops | Audit and budgets need a key, and MCP 2026-07-28 removed protocol-level sessions (opens in a new tab) |
| 3 | One intent, one write. The gateway derives an idempotency key per intended action, so retries and re-issues map to the same key | API hop | The re-issue rule above. Stripe (opens in a new tab)’s keys exist to “safely repeat the request without risk of creating a second object” |
| 4 | Approval outside the prompt. The destructive class needs an approval, decided on the operation and its arguments | API hop | The spec says a human SHOULD be able to deny invocations. A policy that sees only tool names cannot tell “delete one draft” from “delete all” |
| 5 | Pinned tool contract. A hash of each tool description; a change fails closed until re-approved | MCP hop | The “rug pull” (Invariant Labs (opens in a new tab)), and wording moves decisions |
| 6 | Budget as a contract term. A ceiling per agent identity or trace (traceparent) | MCP hop | An agent stuck in a loop spends money and rate limit until someone notices |
| 7 | A stale read cannot write. The gateway adds the version the caller read to each write; a write with no read is refused | API hop | RFC 9110 section 13.1.1 (opens in a new tab): If-Match exists “to prevent accidental overwrites when multiple user agents might be acting in parallel on the same resource” |
| 8 | Declared compensation. Every write declares its undo; the gateway logs it per step | API hop | Saga and compensating transaction |
The principles split along your read path and your write path. On the read path, identity, budget and the pinned tool contract do the work, the gateway notes the version each caller read, and a cache absorbs the repeated reads agents make. The write path needs all eight. A read-only API, such as a public weather service, has only a read path, so the principles apply only partially.
Use them as questions when you buy a gateway or an agent platform, and as a roadmap when you build one.
A reference implementation
Same agent. Same API. Same orders. One path bills the customer twice.
A small bookstore’s REST API has two operations, get_book and place_order, published as MCP tools by a one-click wrapper. A scripted agent places the same orders twice: once straight through the wrapper, and once with the wrapper and the API behind one gateway.
Through the wrapper alone, a lost response becomes two orders, a price change between read and order goes unnoticed, a 50-copy order goes through with no one asked, and an edited tool description reaches the agent. Behind the gateway, the same calls end in one order, a refusal until the agent reads again, a wait for a person, and a blocked call.
The code, and how to run it: github.com/prasadgopi/agent-contract-layer (opens in a new tab)
What this does not solve
- Intent equivalence (principle 3): nothing defines when two calls with different parameters are the same action. Stripe rejects (opens in a new tab) a reused key with different parameters; MCP describes errors as feedback the model can use to “retry with adjusted parameters”. Whether to reject or supersede has to be decided per tool.
- Backends without versions (principle 7): a conditional write needs a backend that exposes a version.
- Prompt injection: the principles limit what a steered call can do. They do not stop the model being steered.
- Read-only does not mean harmless: a response can carry instructions aimed at the model.
- Agent identity (principle 2): delegation standards are still forming.
- Wrong answers: a call that meets all eight principles can still be the wrong call.
Sources (10)
- Model Context Protocol, Tools, specification 2026-07-28 — https://modelcontextprotocol.io/specification/2026-07-28/server/tools (opens in a new tab) ; changelog — https://modelcontextprotocol.io/specification/2026-07-28/changelog (opens in a new tab)
- Hungerford, Morrow, Chang, Tool Annotations as Risk Vocabulary: What Hints Can and Can’t Do, MCP blog, 16 Mar 2026 — https://blog.modelcontextprotocol.io/posts/2026-03-16-tool-annotations/ (opens in a new tab)
- Anthropic, Writing effective tools for agents — with agents, 11 Sep 2025 — https://www.anthropic.com/engineering/writing-tools-for-agents (opens in a new tab)
- Aman Mehta, When Agents Disagree With Themselves, arXiv:2602.11619, v2 15 Jul 2026, ICML 2026 workshop — https://arxiv.org/abs/2602.11619 (opens in a new tab)
- Yao, Shinn, Razavi, Narasimhan, tau-bench, arXiv:2406.12045, 17 Jun 2024 — https://arxiv.org/abs/2406.12045 (opens in a new tab)
- Horace He and Thinking Machines, Defeating Nondeterminism in LLM Inference, 10 Sep 2025 — https://thinkingmachines.ai/blog/defeating-nondeterminism-in-llm-inference/ (opens in a new tab)
- Faghih et al., Tool Preferences in Agentic LLMs are Unreliable, EMNLP 2025, arXiv:2505.18135v2 — https://arxiv.org/abs/2505.18135v2 (opens in a new tab)
- Beurer-Kellner, Fischer, MCP Security Notification: Tool Poisoning Attacks, Invariant Labs, 1 Apr 2025 — https://invariantlabs.ai/blog/mcp-security-notification-tool-poisoning-attacks (opens in a new tab)
- Stripe API reference, Idempotent requests — https://docs.stripe.com/api/idempotent_requests (opens in a new tab)
- Fielding, Nottingham, Reschke (eds.), RFC 9110: HTTP Semantics, IETF, June 2022, section 13.1.1 — https://www.rfc-editor.org/rfc/rfc9110.html#name-if-match (opens in a new tab)