← Back
Cloudflare
Cloudflare Agents SDK v0.6.0 adds RPC transport for MCP, optional OAuth, and schema hardening
Cloudflare Workers · releasefeatureapisdkperformance · developers.cloudflare.com ↗

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 addMcpServer with 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 JSONRPCMessageSchema from 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 $ref resolution with internal JSON Pointers
  • Tuple support for prefixItems (JSON Schema 2020-12) and draft-07 arrays
  • OpenAPI 3.0 nullable: true compatibility
  • Per-tool error isolation ensures one malformed schema won't crash the full pipeline
  • Missing inputSchema gracefully 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-denied status, improving Anthropic provider compatibility
  • Streaming abort/cancel support — Properly cancels reader loops when abort signals fire
  • Message deduplicationpersistMessages() reconciles assistant messages by content and order
  • Error handlingrequestId now available in OnChatMessageOptions for pre-stream error responses
  • Anthropic compatibilityredacted_thinking blocks are preserved during message sanitization
  • Endpoint reliability/get-messages handler moved to constructor wrapper, ensuring it works even when users override onRequest
  • Tool API restoration — Client tool APIs (createToolsFromClientSchemas, clientTools, AITool) are undeprecated for runtime-defined tools
  • Schema initialization — Fixed errors when calling getAITools() in onChatMessage

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.