Cloudflare Agents SDK cuts redundant MCP schema conversion, opens up direct Code Mode access
Hi, I'm Shii-chan! Today I want to walk you through a small but genuinely useful update to Cloudflare's Agents SDK.
Cloudflare ChangelogWhat was announced?
According to the Cloudflare Changelog, there's a set of updates to the Agents SDK and the packages built on top of it, @cloudflare/think and @cloudflare/codemode. Here are the highlights:
- MCP JSON Schema conversion is now reused instead of being redone on every model turn
@cloudflare/thinkaddsincludeMcpTools, letting you turn off Think's automatic MCP tool exposure@cloudflare/codemode's durable runtime handle now exposesexecute(),search(), anddescribe()directly, so hosts that don't use the AI SDK can call it too
The story so far
Until now, the Agents SDK's MCP client had to convert every connected MCP server's JSON Schema into a Zod schema again on every single model turn, even when the connection stayed alive and the tool catalog hadn't changed at all.
On top of that, @cloudflare/think would automatically call getAITools() as soon as it connected to MCP, exposing every connected MCP tool by default. If you were already exposing those same tools through Code Mode or some other mechanism, you'd end up with duplicate exposure, and there was no way to opt out.
The Code Mode durable runtime was also built around the assumption that it would be adapted into an AI SDK tool, which made it awkward for MCP servers or other hosts that don't use the AI SDK to execute code or inspect connector methods directly.
What changes
This update brings a few concrete improvements:
- MCP schema conversion costs no longer pile up as the model takes more turns, since converted schemas are cached as long as the live connection keeps the same tool catalog
- If Think's automatic tool exposure gets in your way, you can now take control with
includeMcpTools = false - The Code Mode durable runtime can be called directly by MCP servers or other hosts, without adapting it into an AI SDK tool
In short, you no longer need to hand-roll a thin AI SDK wrapper just to combine MCP and Code Mode the way you want.
Dive Deep
First, the MCP schema conversion improvement. The Agents SDK's MCP client now reuses its converted input and output schemas as long as a live connection keeps the same tool catalog, avoiding the wasteful work of re-converting every MCP JSON Schema to Zod on each model turn.
Next, @cloudflare/think's new includeMcpTools property. Setting it to false skips Think's automatic getAITools() call. Here's what that looks like:
includeMcpTools = false;
waitForMcpConnections = true;
This is meant for cases where you're already exposing MCP tools through Code Mode or another mechanism outside Think's automatic tool set. Even with it set to false, MCP tool registration, connection restoration, discovery, raw catalog access, direct calls, and Code Mode connectors keep working as before. If you need the raw MCP catalog, you can grab it with listTools().
Finally, @cloudflare/codemode@latest adds execute(), search(), and describe() directly to the durable runtime handle. That means MCP servers and other hosts can execute code and discover connector methods without adapting the runtime into an AI SDK tool. Here's a rough idea of the usage:
const matches = await runtime.search("create issue");
const docs = await runtime.describe(matches.results[0].path);
const outcome = await runtime.execute({
code: `async () => github.create_issue({ title: "Bug" })`
});
On top of that, results from search() and describe() now flag methods that need approval with requiresApproval: true, so execution can pause and get resolved through the existing approve() and reject() methods. That reduces the risk of accidentally auto-running a sensitive method.
You can grab the update with one command:
npm i agents@latest @cloudflare/think@latest @cloudflare/codemode@latest
Wrap-up
Here's the rundown of this update:
- MCP schema conversion is reused instead of being redone every turn
includeMcpTools = falselets you opt out of Think's automatic MCP tool exposure (the raw catalog is still available vialistTools())- The Code Mode durable runtime gains
execute(),search(), anddescribe()for direct use by non-AI-SDK hosts - Methods that need approval are flagged with
requiresApprovaland can be controlled withapprove()/reject()
If you've been building your own MCP server or a custom host that wants to talk to Code Mode directly, or you've been fighting with Think's automatic tool exposure, this quiet little release is squarely for you!