OpenAICloudflare Developer PlatformFeb 25, 2026, 12:00 AM

Agents, Workers - Agents SDK v0.6.0: RPC transport for MCP, optional OAuth, hardened schema conversion, and @cloudflare/ai-chat fixes

A condensed section focused on the key takeaways first.

Original Post

Quick Digest

Summary

A condensed section focused on the key takeaways first.

openaienmodel: gpt-5-mini-2025-08-07

Agents SDK v0.6.0 — RPC Durable Object transport for MCP, optional OAuth, hardened schema conversion, and ai-chat fixes

Key Points

  • Durable Object RPC transport for MCP
  • OAuth opt-in for MCP connections
  • Hardened schema converter + ai-chat reliability fixes

Summary

Agents SDK v0.6.0 introduces an experimental RPC transport for MCP using Durable Object bindings (no HTTP/network round-trips), makes OAuth opt-in for MCP connections, hardens the JSON Schema→TypeScript converter, and ships multiple reliability fixes for @cloudflare/ai-chat.

Key Points

  • RPC transport (Durable Object binding)

    • addMcpServer now accepts string | DurableObjectNamespace with TypeScript overloads; pass the DO namespace directly to connect without HTTP.
    • Durable Object hibernation support: binding name and props persist to storage and restore on wake-up; connection IDs survive hibernation.
    • Deduplication: repeated addMcpServer calls return the existing connection.
    • Smaller RPC internals and validation using JSONRPCMessageSchema from the MCP SDK.
    • Experimental API — may change; watch the tracking issue.
  • Optional OAuth for MCP

    • addMcpServer no longer eagerly creates an OAuth provider; servers that don't require auth work without callbackHost.
    • Clear error is thrown on 401s with guidance to provide callbackHost when OAuth is required.
    • Restore-from-storage flow skips auth provider creation if callback URLs are missing.
  • Hardened JSON Schema → TypeScript converter

    • Guards for recursion/depth and circular references to prevent stack overflows.
    • Better $ref resolution (internal JSON Pointers), tuple/prefixItems support, and OpenAPI 3.0 nullable handling.
    • Per-tool error isolation so a bad schema won't crash generateTypes() or getAITools().
    • getAITools() now falls back to { type: "object" } when inputSchema is missing.
  • @cloudflare/ai-chat fixes

    • Tool denial now transitions to output-denied and supports custom denial messages.
    • Streaming responses respect abort/cancel signals and send done signals to clients.
    • persistMessages() reconciles assistant messages to avoid duplicates; requestId support for pre-stream errors.
    • redacted_thinking blocks preserved; endpoint reliability fixes; dynamic client tool APIs restored.

Upgrade

Run:

npm i agents@latest @cloudflare/ai-chat@latest

Notes for engineers: update Typescript types if you rely on addMcpServer overloads; treat RPC transport as experimental and validate hibernation/restore behavior in your Worker tests.

Full Translation

Translations

A translation section that keeps the flow of the original article.

openaijamodel: gpt-5-mini-2025-08-07

Agents、Workers - Agents SDK v0.6.0:MCP向けRPCトランスポート、オプションのOAuth、強化されたスキーマ変換、@cloudflare/ai-chatの修正

Agents SDK v0.6.0:概要

公開日: 2026-02-25

最新の Agents SDK ↗ リリースでは、同一の Worker 内で Agent と McpAgent を RPC 経由で接続できるようになりました — HTTP を使わず、ネットワークのオーバーヘッドなしで通信できます。さらに、簡易な MCP 接続では OAuth をオプトインに変更し、プロダクションワークロード向けにスキーマ変換を強化し、@cloudflare/ai-chat に対する信頼性修正を複数含んでいます。


MCP 向け RPC トランスポート

同一 Worker 内で Durable Object バインディングを使って Agent と McpAgent を接続できるようになりました。接続は Cloudflare ランタイム内に留まり、ネットワーク往復やシリアライズのオーバーヘッドが発生しません。

addMcpServer に Durable Object namespace を直接渡します。

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" },
    });
  }
}

上記は JavaScript / TypeScript どちらでも動作します。addMcpServer メソッドは第二引数に string | DurableObjectNamespace を受け付けるようになり、HTTP と RPC の経路が型安全に区別され、混在できないようになっています。

主な機能:

  • ハイバネーション対応 — Durable Object のハイバネーション復帰後も RPC 接続は自動的に復元されます。バインディング名と props はストレージに保存され、起床時に復元されます。HTTP の MCP 接続と同等の挙動です。
  • 重複排除 — 同じサーバー名で addMcpServer を呼ぶと既存の接続を返し、重複した接続を作成しません。接続 ID はハイバネーション復元後も安定しています。
  • サーフェスの縮小 — RPC トランスポートの内部実装を 609 行から 245 行に縮小しました。RPCServerTransport は手作りのチェックの代わりに MCP SDK の JSONRPCMessageSchema を検証に使用します。

注意: RPC トランスポートは実験的です。API はフィードバックに応じて変更される可能性があります。更新はトラッキング issue ↗ を参照してください。


MCP 接続での OAuth をオプトインに

addMcpServer() はもはや接続ごとに自動的に OAuth プロバイダを作成しません。認証を必要としないサーバーでは、単純な呼び出しだけで動作します。

// No callbackHost, no OAuth config — just works
await this.addMcpServer("my-server", "https://mcp.example.com");

サーバーが 401 を返した場合、SDK は次の明確なエラーを投げます:

"This MCP server requires OAuth authentication. Provide callbackHost in addMcpServer options to enable the OAuth flow."

ストレージからの復元フローでもコールバック URL が欠落している場合は適切に処理され、OAuth を要求しないサーバーについては認証プロバイダ作成をスキップします。


JSON Schema -> TypeScript コンバータの強化

generateTypes()getAITools() で使われるスキーマコンバータが、以前は本番でクラッシュを引き起こしていたエッジケースに対応するようになりました。

  • 深さと循環参照のガード — 再帰的または深くネストされたスキーマでのスタックオーバーフローを防止します。
  • $ref 解決 — 内部 JSON Pointer(#/definitions/...#/$defs/...#)をサポートします。
  • タプル対応 — prefixItems(JSON Schema 2020-12)および配列 items(draft-07)をサポートします。
  • OpenAPI 3.0 nullable: true — すべてのスキーマ分岐でサポートされます。
  • ツール単位のエラー隔離 — 1 つの不正なスキーマが generateTypes()getAITools() の全パイプラインをクラッシュさせないようになりました。
  • 入力スキーマ欠落時のフォールバック — getAITools() は投げる代わりに { type: "object" } にフォールバックします。

@cloudflare/ai-chat の修正

  • ツール拒否フロー — 拒否されたツール承認(approved: false)は tool_result を伴う output-denied に遷移するようになり、Anthropic プロバイダ互換性の問題を修正しました。カスタム拒否メッセージは state: "output-error"errorText でサポートされます。
  • 中止/キャンセル対応 — ストリーミング応答は中止シグナル発火時にリーダーループを正しくキャンセルし、クライアントへ done シグナルを送ります。
  • 重複メッセージの永続化 — persistMessages() は内容と順序で assistant メッセージを照合し、クライアントが全履歴を再送した場合の重複行の挿入を防ぎます。
  • requestId in OnChatMessageOptions — ハンドラはストリーム前の失敗に対して適切にタグ付けされたエラーレスポンスを返せるようになりました。
  • redacted_thinking の保持 — メッセージサニタイザが Anthropic の redacted_thinking ブロックを除去しなくなりました。
  • /get-messages の信頼性 — エンドポイント処理を prototype の onRequest() オーバーライドからコンストラクタラッパーに移動し、ユーザーが onRequest をオーバーライドして super.onRequest() を呼ばない場合でも動作するようにしました。
  • クライアントツール API の復活 — createToolsFromClientSchemasclientToolsAIToolextractClientToolSchemas、および useAgentChattools オプションは、ランタイムでツールが動的に定義されるユースケースのために SDK で復活しました。
  • jsonSchema 初期化問題の修正 — onChatMessage 内で getAITools() を呼ぶ際の jsonSchema not initialized エラーを修正しました。

アップグレード

最新バージョンに更新するには:

npm i agents@latest @cloudflare/ai-chat@latest

参考・リソース

  • API ドキュメント
  • ヘルプセンター
  • System Status

© 2026 Cloudflare, Inc. Privacy Policy | Terms of Use

Agents, Workers - Agents SDK v0.6.0: RPC transport for MCP, optional OAuth, hardened schema conversion, and @cloudflare/ai-chat fixes | Cloudflare Developer Platform | DocsDigest