OpenAICloudflare Developer PlatformJul 27, 2026, 12:00 AM

Agents, Workers - Agents SDK adds MCP Specification 2026-07-28 support

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.20.0 — MCP 2026-07-28 (RC) support, stateless handlers, and migration path

Key Points

  • MCP 2026-07-28 client/server support
  • Stateless createMcpHandler factory per-request servers
  • McpAgent deprecated — migrate to SDK v2

Summary

Agents SDK v0.20.0 adds client and server support for the MCP 2026-07-28 release candidate and introduces a stateless server model. The MCP client manager now uses @modelcontextprotocol/client and probes servers with server/discover; if a server does not support the stateless protocol the SDK falls back to the legacy initialize handshake on the same connection. createMcpHandler now accepts a factory that returns an McpServer from @modelcontextprotocol/server, creating an isolated server per request suited for Workers. OAuth callbacks and discovery state handling have been tightened (issuer metadata validated via SDK v2) and persistence across browser redirects and Durable Object hibernation is supported. McpAgent is deprecated and feature-frozen — migrate to the SDK v2 factory + createMcpHandler.

Key Points

  • Client behavior

    • Client manager probes with server/discover for MCP 2026-07-28 and transparently falls back to the legacy initialize handshake on the same connection when needed.
    • Existing addMcpServer calls do not require a protocol-version or separate clients per generation.
  • Stateless server model

    • createMcpHandler(factory) accepts a factory that returns an McpServer (from @modelcontextprotocol/server) and creates an isolated server instance per request.
    • Workers wrapper validates browser origins, supports delegation to trusted Origin middleware, and exposes typed change notifications.
    • Stateless elicitation uses input_required via multi-round-trip requests (MRTR); the SDK collects input, retries the operation, and resolves the original callTool, getPrompt, or readResource promise.
  • Backward compatibility & migration

    • The same createMcpHandler(createServer)(request, env, ctx) route can serve both MCP 2026-07-28 clients and legacy clients; no separate routes are required for ordinary tools, prompts, and resources.
    • Use isLegacyRequest() to route only legacy traffic to an existing sessionful server while you transition clients.
    • Migration steps (practical):
      • Upgrade: npm i agents@latest (or yarn add agents@latest, pnpm add agents@latest, bun add agents@latest).
      • Move SDK v1 server definitions into an SDK v2 factory and serve with createMcpHandler(factory, options).
      • If your server depends on sessionful features, run both the sessionful route and the stateless handler during migration and allow sessions to drain.
  • Deprecations and compatibility

    • McpAgent is deprecated and feature-frozen; migrate to stateless handlers as soon as practical.
    • createMcpHandler(v1Server, options) is scheduled for removal in the next major release; prefer SDK v2 factories.
    • MCPClientManager.callTool overloads are consolidated; use callTool(params, options) or callTool(confirm, params, options) as appropriate.
    • The MCP 2026-07-28 draft also deprecates Roots, Sampling, Logging, the old HTTP+SSE transport, and Dynamic Client Registration.

Action items for engineers

  • Upgrade the agents package to the latest version.
  • Convert SDK v1 server implementations into SDK v2 factories and serve them with createMcpHandler.
  • Use isLegacyRequest() to route legacy traffic during rollout.
  • Audit sessionful features (RPC, pushed requests, streams, replay) and design stateless equivalents or keep a temporary sessionful route while migrating.
  • Test OAuth issuer validation and discovery persistence across redirects/hibernation.

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 が MCP Specification 2026-07-28 をサポート追加

概要

Agents SDK v0.20.0 は MCP 2026-07-28 リリース候補へのクライアントとサーバーのサポートを追加しました。Workers は MCP トランスポートセッションや Durable Object を使わずにツール、プロンプト、リソース、elicitation を提供できます。Agents は MCP 2026-07-28 サーバーと既存のレガシーサーバーの両方に接続できます。

クライアントサポート

  • MCP クライアントマネージャは現在 @modelcontextprotocol/client を使用します。
  • 各接続で server/discover により MCP 2026-07-28 の対応をプローブします。サーバーがステートレスプロトコルをサポートしない場合、クライアントは同一接続上でレガシーの initialize ハンドシェイクにフォールバックします。
  • 既存の addMcpServer 呼び出しはプロトコルバージョン設定やプロトコル世代ごとの別クライアントを必要としません。
  • ステートレスリクエストでは、elicitation は input_required を使いマルチラウンドトリップリクエスト(MRTR)に対応します。レガシーパスはプッシュされたリクエストに対して同じフォームと URL ハンドラを使用します。
  • SDK は入力を収集し、元の操作をリトライし、元の callToolgetPrompt、または readResource のプロミスを最終結果で解決します。
  • OAuth コールバックは v2 SDK を通じて発行者メタデータを検証します。Discovery 状態と発行者に紐づく資格情報はブラウザリダイレクトや Durable Object のハイバネーション間で永続化されます。

ステートレスサーバーの実行

createMcpHandler@modelcontextprotocol/server からのサーバーを返すファクトリを受け取れるようになりました。ファクトリは各リクエストごとに分離されたサーバーを作成します。例:

import { McpServer } from "@modelcontextprotocol/server" ;
import { createMcpHandler } from "agents/mcp/server" ;
function createServer () {
    return new McpServer ({ name: "example" , version: "1.0.0"});
}
export default {
    fetch ( request , env , ctx ) {
        return createMcpHandler (createServer)(request, env, ctx);
    },
};

別の例(型注釈付き):

import { McpServer } from "@modelcontextprotocol/server" ;
import { createMcpHandler } from "agents/mcp/server" ;
function createServer () {
    return new McpServer ({ name: "example" , version: "1.0.0" });
}
export default {
    fetch ( request , env , ctx ) {
        return createMcpHandler (createServer)(request, env, ctx);
    },
} satisfies ExportedHandler ;
  • agents/mcp/server の分離されたエントリは McpAgentWorkerTransport、MCP クライアントトランスポート、および SDK v1 モジュールをステートレスサーバーバンドルから除外します。
  • Workers ラッパーは現在のブラウザ Origin を検証し、信頼された Origin ミドルウェアへの明示的な委任をサポートし、リクエストハンドリングと型付きの変更通知を公開します。

後方互換性

  • 同一の createMcpHandler(createServer)(request, env, ctx) ルートは、MCP 2026-07-28 クライアントとステートレスリクエストを使うレガシークライアントの両方に対応します。通常のツール、プロンプト、リソースに対して個別のルートやツール定義は不要です。
  • McpAgent は非推奨(deprecated)かつ機能凍結です。既存の McpAgent サーバーはできるだけ早くステートレスハンドラへ移行してください。
  • サーバーがプロトコルセッション、RPC、サーバーからクライアントへのプッシュリクエスト、独立したストリーム、またはリプレイに依存する場合、マイグレーションガイドを参照してステートレスの同等機能を設計し、クライアント移行中は両方のルートを併行して実行してください。

既存の SDK v1 サーバーの移行

  1. Agents SDK をアップグレードします:

    npm yarn pnpm bun npm i agents@latest yarn add agents@latest pnpm add agents@latest bun add agents@latest

  2. 既存の SDK v1 サーバー定義を SDK v2 ファクトリに移し、createMcpHandler で提供します。ハンドラのデフォルトのレガシー互換性により、ほとんどのステートレス展開はルートを1つだけで済みます。

  3. 既存の McpAgent サーバーがまだセッション依存の機能を必要とする場合、その横にステートレスパスを追加します。isLegacyRequest() を使ってレガシーのトラフィックのみ既存ルートに送る例:

    import { isLegacyRequest } from "@modelcontextprotocol/server" ; import { createMcpHandler } from "agents/mcp/server" ; import { MyMcpAgent } from "./legacy-server" ; import { createServer } from "./server" ;

    const stateless = createMcpHandler (createServer, { route: "/mcp" , legacy: "reject" , }); const legacy = MyMcpAgent. serve ( "/mcp" );

    export default { async fetch ( request , env , ctx ) { if ( await isLegacyRequest (request)) { return legacy. fetch (request, env, ctx); } return stateless (request, env, ctx); }, };

  • 型注釈例:

    import { isLegacyRequest } from "@modelcontextprotocol/server" ; import { createMcpHandler } from "agents/mcp/server" ; import { MyMcpAgent } from "./legacy-server" ; import { createServer } from "./server" ;

    const stateless = createMcpHandler (createServer, { route: "/mcp" , legacy: "reject" , }); const legacy = MyMcpAgent. serve ( "/mcp" );

    export default { async fetch ( request : Request , env : Env , ctx : ExecutionContext ) { if ( await isLegacyRequest (request)) { return legacy. fetch (request, env, ctx); } return stateless (request, env, ctx); }, } satisfies ExportedHandler<Env>;

  1. 残るセッション依存機能を移行し、既存セッションのドレインを許可した後にレガシールートを削除してください。
  2. パッケージ変更、互換性の制限、ロールアウト手順については「Migrate to MCP SDK v2」を参照してください。

v0.20.0 の非推奨(Deprecated)事項

以下の Agents SDK API がこのリリースで非推奨になりました。

Deprecated API置換ステータス
McpAgentSDK v2 ファクトリと createMcpHandler を使ってステートレスサーバーに移行します。状態ful 機能を削除する前にマイグレーションガイドを参照してください。機能凍結。削除バージョンは未定。
createMcpHandler(v1Server, options)サーバーを SDK v2 ファクトリに移し createMcpHandler(factory, options) を呼び出してください。セッション依存の機能については一時的な橋渡しとして createLegacyMcpHandler のみを使ってください。次のメジャーリリースで削除予定。
MCPClientManager.callTool(params, resultSchema, options)withX402Client 相当のオーバーロードcallTool(params, options) または callTool(confirm, params, options) を使用してください。互換性のためのオーバーロード。削除バージョンは未定。
  • MCP 2026-07-28 草案では、Roots、Sampling、Logging、旧 HTTP+SSE トランスポート、および Dynamic Client Registration の個別 deprecate も行われています。