Agents SDK Says Goodbye to HTTP Overhead for MCP Connections
Hi, I'm Shii-chan! I spotted an update to Cloudflare's Agents SDK that caught my eye today. You can now put an Agent and an McpAgent in the same Worker and connect them directly, without going through HTTP at all. Let's dive in.
Cloudflare ChangelogWhat was announced?
According to the Cloudflare Changelog, Agents SDK v0.6.0 lets you connect an Agent to an McpAgent over RPC. If both are defined in the same Worker, you can wire them together through a Durable Object binding instead of an HTTP URL. There are no network round-trips and no serialization overhead — the whole thing stays inside the Cloudflare runtime.
Alongside that, simple MCP connections no longer require OAuth by default, the schema converter behind generateTypes() and getAITools() got hardened for production workloads, and a batch of @cloudflare/ai-chat reliability fixes shipped too.
The story so far
Until now, even when an Agent and an McpAgent were defined in the same Worker, the only way to connect them was over an HTTP URL. That meant paying for network latency and serialization on every call. On top of that, addMcpServer() eagerly created an OAuth provider for every single connection, so even wiring up to a simple MCP server that didn't need auth meant carrying extra setup you didn't actually need.
What changes
Now you can just pass a Durable Object namespace straight into addMcpServer to connect an Agent to an McpAgent in the same Worker over RPC.
import { Agent } from "agents";
export class MyAgent extends Agent {
async onStart() {
// Connect via DO binding — no HTTP, no network overhead
await this.addMcpServer("counter", env.MY_MCP);
// With props for per-user context
await this.addMcpServer("counter", env.MY_MCP, {
props: { userId: "user-123", role: "admin" },
});
}
}
The second argument to addMcpServer now accepts string | DurableObjectNamespace with full TypeScript overloads, so the HTTP and RPC paths are type-safe and can't be mixed up.
OAuth got lighter too. For servers that don't need authentication, you can just call addMcpServer without a callbackHost or any OAuth config. If the server responds with a 401, the SDK now throws a clear error telling you to provide callbackHost to enable the OAuth flow, so you no longer have to pre-configure auth you don't need.
Dive Deep
RPC connections come with a few notable characteristics.
- Hibernation support: RPC connections survive Durable Object hibernation automatically. The binding name and props are persisted to storage and restored on wake-up, matching how HTTP MCP connections already behaved
- Deduplication: Calling
addMcpServerwith the same server name returns the existing connection instead of creating a duplicate. Connection IDs stay stable across hibernation restores - A smaller codebase: the RPC transport internals were rewritten and cut from 609 lines down to 245.
RPCServerTransportnow validates withJSONRPCMessageSchemafrom the MCP SDK instead of hand-written checks
The schema converter also got fixes aimed squarely at cases that were crashing in production.
- Depth and circular reference guards to prevent stack overflows on recursive or deeply nested schemas
$refresolution for internal JSON Pointers such as#/definitions/...,#/$defs/..., and#- Tuple support for both
prefixItems(JSON Schema 2020-12) and arrayitems(draft-07) - OpenAPI 3.0
nullable: truehandling across all schema branches - Per-tool error isolation, so one malformed schema can't crash the whole pipeline in
generateTypes()orgetAITools() - A fallback to
{ type: "object" }wheninputSchemais missing, instead of throwing
The @cloudflare/ai-chat fixes are a decent-sized batch too. Denied tool approvals (approved: false) now transition to output-denied with a proper tool_result, fixing Anthropic provider compatibility, and custom denial messages are supported through state: "output-error" with errorText. Streaming responses now cancel the reader loop reliably when an abort signal fires and send a done signal, and persistMessages() reconciles assistant messages by content and order so resending full history no longer creates duplicate rows. On top of that, createToolsFromClientSchemas, clientTools, AITool, extractClientToolSchemas, and the tools option on useAgentChat are all undeprecated again, for cases where tools need to be defined dynamically at runtime.
Updating takes one command.
npm i agents@latest @cloudflare/ai-chat@latest
Wrap-up
Here's what's worth remembering about Agents SDK v0.6.0.
- Agents and McpAgents in the same Worker can now connect over RPC, with no HTTP overhead
- MCP servers that don't need auth no longer require OAuth config, and you only get an error when a server actually returns a 401
- The schema converter now has depth/circular reference guards and
$refresolution, making it much sturdier against unexpected production crashes @cloudflare/ai-chatgot a bundle of fixes around tool denial, aborts, and duplicate messages
If you're running multiple Agents and MCP servers together inside a Worker, this update is squarely for you!