feat(mcp): add SDK v2 client and stateless server support - #1557
Merged
mattzcarey merged 21 commits intoJul 27, 2026
Conversation
🦋 Changeset detectedLatest commit: 4995470 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
6 tasks
mattzcarey
force-pushed
the
chore/mcp-sdk-v2-upgrade
branch
from
July 7, 2026 12:51
bbb79a9 to
384c432
Compare
agents
@cloudflare/ai-chat
@cloudflare/codemode
create-think
hono-agents
@cloudflare/shell
@cloudflare/think
@cloudflare/voice
@cloudflare/worker-bundler
commit: |
mattzcarey
marked this pull request as ready for review
July 7, 2026 13:03
mattzcarey
force-pushed
the
chore/mcp-sdk-v2-upgrade
branch
from
July 14, 2026 10:57
42ce495 to
8059e94
Compare
mattzcarey
force-pushed
the
chore/mcp-sdk-v2-upgrade
branch
2 times, most recently
from
July 14, 2026 18:15
c86cbec to
80a8fbd
Compare
3 tasks
mattzcarey
force-pushed
the
chore/mcp-sdk-v2-upgrade
branch
2 times, most recently
from
July 22, 2026 15:19
6be2cac to
c38957c
Compare
mattzcarey
force-pushed
the
chore/mcp-sdk-v2-upgrade
branch
2 times, most recently
from
July 27, 2026 14:16
4d6b303 to
483a8f4
Compare
The SDK v2 handler intentionally leaves deployment validation to its host, but the Agents Worker wrapper previously delegated present Origin headers without a guard. Validate them against localhost-class hostnames by default, expose an explicit browser-host allowlist, and keep Origin-less non-browser clients working. Also allow the modern Mcp-Method and Mcp-Name headers in default CORS preflights and remove the now-clean v2 conformance baselines.
- delegate scenario execution to the official conformance CLI - remove non-gating extension lanes, empty baselines, and redundant tests - keep bounded concurrency and truthful process/warning handling - create a fresh legacy chess server for each request
Remove the two stale modern-protocol exceptions fixed by alpha.10, leaving the stateless server lane 40/40 clean and the modern client lane with four documented expected failures. Also drop the temporary MCP release-age exclusions.
Wrap callable Agents handlers inside Worker object fetch exports so Wrangler does not treat them as WorkerEntrypoint classes. Carry multi-round elicitation data in signed requestState because each retry includes only the current round's input responses.
Match the existing Agents and Sentry migration pattern: keep the Worker object export and pass the SDK v2 factory to the callable handler. The .fetch method remains available for request-options composition but is not required for Worker dispatch.
Expose only callable/fetch request handling and typed change notifications. Keep upstream close and bus internals private, reject the bus option, and remove now-unreachable close-race machinery from the legacy compatibility adapter.
Keep Worker dispatch on the callable signature and expose only the lower-level fetch(request, options?) method from the SDK. Remove the redundant fetch(request, env, ctx) overload.
Direct deprecated SDK v1 handler and McpAgent users to SDK v2 factories first, reserving legacy handlers for temporary sessionful migration lanes. Document the full v0.20.0 deprecation set and correct the x402 result-schema guidance.
mattzcarey
force-pushed
the
chore/mcp-sdk-v2-upgrade
branch
from
July 27, 2026 16:56
6e39342 to
60d720f
Compare
Use the package-defined start scripts and describe the McpAgent example as a deprecated migration reference rather than a new-server path.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Upgrade the Agents MCP stack to the split MCP SDK v2 packages. New client and server paths support MCP 2026-07-28, while temporary legacy lanes let existing sessionful deployments migrate without an abrupt cutover.
stateless server
agents/mcp/serverentry for the Agents Worker wrapper;@modelcontextprotocol/server@2.0.0-beta.5;McpServerowned by the upstream SDK rather than re-exporting it;McpAgent,WorkerTransport, MCP client transports, PartyServer, and SDK v1 from the stateless bundle;legacy: "reject"for a stateless-only endpoint;WorkerTransport;allowedOriginHostnames: "*"when trusted upstream middleware performs validation;fetch(request, options?)method plus typednotifymethods while keeping upstream lifecycle and event-bus internals private.The compatibility
agents/mcpentry remains available for migration. Its implementation is now separated into explicit compatibility and legacy modules.createLegacyMcpHandlerandWorkerTransportcan temporarily retain sessionful SDK v1 behavior while it is replaced.McpAgentis deprecated and feature-frozen.Client
@modelcontextprotocol/client@2.0.0-beta.5;server/discoverand falls back to the legacyinitializehandshake on the same connection;callTool,getPrompt, andreadResourcepending while input is collected;agents/mcp/client;callTooloverload;priorshape for safe HTTP restoration.OAuth and integrations
skipIssuerMetadataValidationcompatibility option for trusted legacy metadata;@cloudflare/codemodean optional peer, with direct dependencies added to every workspace consumer.Elicitation examples
examples/mcp-elicitation-mrtr: stateless Elicitation, including a two-round tool flow;examples/mcp-elicitation: legacy Elicitation, retaining Durable Object state,WorkerTransport, pushed form/URL requests, and SSE replay.Structure and coverage
agents/mcp/server;design/mcp.md;Deprecations
McpAgentis deprecated and feature-frozen; migrate to an SDK v2 factory withcreateMcpHandler.createMcpHandleris deprecated for removal in the next major version; move the server to an SDK v2 factory and reservecreateLegacyMcpHandlerfor temporary sessionful migration lanes.MCPClientManager.callToolandwithX402Client(...).callToolare deprecated; pass request options instead.Lifecycle boundary
In-flight stateless Elicitation remains memory-only. Durable Object hibernation, isolate restart, transport loss, or connection reconstruction rejects the active operation. This PR does not persist
requestStateor add a manual continuation API.Verification
mainat6c01c8d8(agents@0.19.0), with no merge commits or base divergencepnpm install --frozen-lockfilepnpm run ci— all 33 build/test targets, package exports, formatting, lint, and all 118 TypeScript projectspnpm --filter agents run test:conformance@modelcontextprotocol/conformance@0.2.0-alpha.10McpAgent: 29 clean / 3 documented failures eachFixes #1848.