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/discoverfor MCP 2026-07-28 and transparently falls back to the legacy initialize handshake on the same connection when needed. - Existing
addMcpServercalls do not require a protocol-version or separate clients per generation.
- Client manager probes with
-
Stateless server model
createMcpHandler(factory)accepts a factory that returns anMcpServer(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_requiredvia multi-round-trip requests (MRTR); the SDK collects input, retries the operation, and resolves the originalcallTool,getPrompt, orreadResourcepromise.
-
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(oryarn 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.
- Upgrade:
- The same
-
Deprecations and compatibility
McpAgentis 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.callTooloverloads are consolidated; usecallTool(params, options)orcallTool(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
agentspackage 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.