fix(mcp): v0.0.95 compat shims for gradual rollout#1099
Draft
mattzcarey wants to merge 6 commits intomainfrom
Draft
fix(mcp): v0.0.95 compat shims for gradual rollout#1099mattzcarey wants to merge 6 commits intomainfrom
mattzcarey wants to merge 6 commits intomainfrom
Conversation
During gradual rollouts, old Workers (v0.0.95) and new DOs (v0.7.5+) must interoperate. The RPC interface changed completely between versions: - _init/isInitialized/setInitialized → updateProps/getInitializeRequest/setInitializeRequest - WS upgrade to /streamable-http → cf-mcp-method/cf-mcp-message headers - Raw JSONRPC responses → CF_MCP_AGENT_EVENT wrappers DO-side (index.ts): - Add _init(), isInitialized(), setInitialized() compat shims - Dual storage: setInitializeRequest also writes "initialized" boolean - fetch() override detects /streamable-http path, caches transport type - Deferred onStart: tolerate transport init failure for old Workers - onMessage handler for legacy ws.send() frames - shouldSendProtocolMessages suppresses for old-style connections - getTransportType/getSessionId fall back for names without prefix - Tag new-style connections with _mcpNewStyle in onConnect Worker-side (utils.ts): - readInitializedState/writeInitializedState with isRpcMethodMissing fallback - ws.send() messages after connect for old DOs that ignore headers - Handle both CF_MCP_AGENT_EVENT and raw JSONRPC response formats Transport (transport.ts): - writeSSEEvent sends raw JSONRPC for old Workers (no _mcpNewStyle) - Preserve connection state when setting requestIds/_standaloneSse Tests: - 8 compat tests simulating old Worker control flow against new DO
|
oxlint in CI rejects `any` — use `as unknown as OldWorkerStub` instead.
Old Worker uses `idFromName("streamable-http:${sessionId}")`, not a
plain session ID. Updated test to match actual v0.0.95 behavior.
Old Workers use idFromName("streamable-http:${sessionId}"), so the name
always has the transport prefix. Remove _cachedTransportType, deferred
onStart, lazy transport init, transportType storage, and plain-name
fallbacks that were added for a case that doesn't occur.
agents
@cloudflare/ai-chat
@cloudflare/codemode
hono-agents
@cloudflare/voice
@cloudflare/worker-bundler
commit: |
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
Adds backwards/forwards compatibility between v0.0.95 Workers and v0.7.5+ DOs for the streamable-http transport, enabling gradual rollouts where both versions run simultaneously.
_init(),isInitialized(),setInitialized()methods that v0.0.95 Workers call via RPC; dual storage so both old and new formats workreadInitializedState/writeInitializedStatehelpers that try new RPC methods first, fall back to old on method-missing errors;ws.send()after connect for old DOs that ignore headers; handles bothCF_MCP_AGENT_EVENTand raw JSONRPC response formatswriteSSEEventsends raw JSONRPC for old Workers (detected via_mcpNewStyleconnection tag), wrappedCF_MCP_AGENT_EVENTfor newonStarttolerates transport init failure;fetch()andonMessage()lazily initialize when transport type becomes known_init,/streamable-httpWS upgrade,ws.send()messages, raw JSONRPC responses)Context
A customer upgrading from v0.0.95 → v0.7.5 uses gradual rollouts. During deployment, old Workers call new DOs (and vice versa). The RPC interface changed completely between versions — this PR bridges both directions for streamable-http transport.
Test plan
npm run build— compiles cleannpm run check— format/lint/types passnpm test— all 994 tests pass (52 files, 8 skipped pre-existing)