Key Features
RPC Transport for MCP Connections
Agents can now connect to MCP servers in the same Worker using Durable Object bindings instead of HTTP URLs. This eliminates network round-trips and serialization overhead while keeping connections entirely within the Cloudflare runtime.
The implementation includes:
- Hibernation support — RPC connections automatically survive Durable Object hibernation; binding names and context properties persist to storage and restore on wake-up
- Connection deduplication — Repeated calls to
addMcpServerwith the same server name return the existing connection instead of creating duplicates - Simplified transport — The RPC transport was rewritten and reduced from 609 to 245 lines, now using
JSONRPCMessageSchemafrom the MCP SDK for validation
// Connect via Durable Object binding with optional per-user context
await this.addMcpServer("counter", env.MY_MCP, {
props: { userId: "user-123", role: "admin" }
});
Optional OAuth for MCP
OAuth authentication is now opt-in rather than mandatory. Servers that don't require authentication can be connected with a single line of code. If a server responds with 401, the SDK throws a clear error message directing developers to enable the OAuth flow when needed.
Improved Schema Conversion
The JSON Schema to TypeScript converter now handles production edge cases:
- Circular reference and depth guards prevent stack overflows
- Support for
$refresolution with internal JSON Pointers - Tuple support for
prefixItems(JSON Schema 2020-12) and draft-07 arrays - OpenAPI 3.0
nullable: truecompatibility - Per-tool error isolation ensures one malformed schema won't crash the full pipeline
- Missing
inputSchemagracefully falls back to{ type: "object" }
Reliability Improvements
The @cloudflare/ai-chat library receives multiple critical fixes:
- Tool denial flows — Denied approvals now correctly transition to
output-deniedstatus, improving Anthropic provider compatibility - Streaming abort/cancel support — Properly cancels reader loops when abort signals fire
- Message deduplication —
persistMessages()reconciles assistant messages by content and order - Error handling —
requestIdnow available inOnChatMessageOptionsfor pre-stream error responses - Anthropic compatibility —
redacted_thinkingblocks are preserved during message sanitization - Endpoint reliability —
/get-messageshandler moved to constructor wrapper, ensuring it works even when users overrideonRequest - Tool API restoration — Client tool APIs (
createToolsFromClientSchemas,clientTools,AITool) are undeprecated for runtime-defined tools - Schema initialization — Fixed errors when calling
getAITools()inonChatMessage
Getting Started
Update to the latest version with:
npm i agents@latest @cloudflare/ai-chat@latest
The type-safe API ensures HTTP and RPC paths cannot be mixed, catching configuration errors at compile time.