Code Mode: the better way to use MCP

It turns out we

Code Mode: a better way to use MCP

It’s easy to feel frustrated watching agents fumble with a dozen little “tools.” They try, but something’s off. We’ve been handing tools directly to LLMs and expecting magic. Turns out, there’s a better way.

Here’s the simple idea: instead of exposing MCP tools as clumsy tool-calls, convert them into a **TypeScript API** and ask the LLM to *write code* that calls that API. Sounds small. Feels huge. Why? Because LLMs have seen *tons* of real-world TypeScript but very few examples of those special tool-call tokens. So they’re better at writing code than at using contrived tool encodings.

The payoff is real. When an agent needs to string multiple calls together, code can handle the plumbing — pass results directly, avoid repetitive token back-and-forth, and only return the final answers the LLM actually needs. It’s faster, cleaner, and uses fewer tokens. Imagine skipping the noisy middleman and letting the agent actually program its way through a task. Nice.

Cloudflare already extended the Agents SDK to support this “code mode.” Connect to an MCP server, the SDK converts the server schema into TypeScript definitions (with docs), and the agent gets a proper programming API to use. You still get the uniformity and safety of MCP — authorization, docs, sandboxing — but now the agent operates in a mode it’s naturally good at: writing code.

If you’re building agents or just curious about better tool use, this is worth trying. It feels like teaching someone to use a power drill instead of asking them to glue pieces together by hand. Cleaner, faster, and a little more elegant.

Read more: https://blog.cloudflare.com/code-mode/

Code Mode: die bessere Art, MCP zu nutzen

Es ist frustrierend, wenn Agenten mit vielen kleinen „Tools“ kämpfen. Wir haben ihnen diese Tools direkt gegeben und gehofft, dass alles glatt läuft. Die überraschend einfache Lösung: mach aus den MCP-Tools eine **TypeScript-API** und lass das LLM Code schreiben, der diese API nutzt. Klingt klein. Ist groß.

Warum? LLMs haben massenhaft echten TypeScript‑Code gesehen, aber kaum die speziellen „Tool‑Call“-Token. Also sind sie besser darin, Code zu schreiben, als diese künstlichen Aufrufe zu formen. Das spart Tokens, vereinfacht Abläufe und vermeidet unnötiges Hin‑ und Herschicken von Zwischenergebnissen.

Cloudflare hat das Agents SDK um diesen „Code Mode“ erweitert. Verbindest du ein MCP‑Server, erzeugt das SDK TypeScript‑Definitionen aus dem Schema — inklusive Dokumentation — und das Agent kann sicher im Sandbox‑Kontext die API nutzen. Du behältst die Vorteile von MCP (Autorisierung, Standarddokumentation, Sicherheitsgrenzen), aber das Agent arbeitet in einer Form, die ihm wirklich liegt: es programmiert.

Kurz gesagt: Code Mode fühlt sich an, als würdest du jemandem einen Bohrer geben statt Kleber — präziser, schneller und eleganter. Falls du Agenten baust oder einfach neugierig bist, probier’s aus. Mehr dazu hier: https://blog.cloudflare.com/code-mode/

Kommentar abschicken