-
Notifications
You must be signed in to change notification settings - Fork 330
fix: WorkerTransport doesn't persist clientCapabilities, breaking elicitation in serverless #783
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: WorkerTransport doesn't persist clientCapabilities, breaking elicitation in serverless #783
Conversation
🦋 Changeset detectedLatest commit: 9bd943a The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
Claude Code ReviewIssue Found: Line 558: Redundant type guard check const initMessage = messages.find(isInitializeRequest);
if (initMessage && isInitializeRequest(initMessage)) {The if (initMessage) {Otherwise: LGTM The implementation correctly solves the capability persistence problem. The approach of replaying the initialize request is reasonable given SDK limitations. Tests are comprehensive, covering edge cases and backward compatibility. |
Update documentation to reflect changes from cloudflare/agents PR #783: - Add initializeParams field to TransportState interface - Document automatic persistence and restoration of client capabilities - Explain behavior in serverless environments (Durable Objects/Agents) - Note backward compatibility with older stored state Related to: cloudflare/agents#783
commit: |
Update MCP handler API documentation to reflect that WorkerTransport now persists and restores client capabilities across serverless restarts. Changes: - Document that client capabilities (elicitation, sampling) are persisted - Update TransportState interface to show initializeParams field - Add explanation of capability restoration mechanism - Include backward compatibility note - Add links to elicitation and sampling specifications Related to cloudflare/agents#783 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
mattzcarey
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix check and a couple of questions. Awesome work :)
Update documentation to reflect PR cloudflare/agents#783 changes: - Updated TransportState interface to include initializeParams field - Added documentation explaining that client capabilities, client info, and protocol version are now persisted and restored across serverless restarts - Emphasized importance of capability persistence for elicitation and sampling features - Added detailed field descriptions for TransportState interface This enables MCP servers to properly support advanced client features like elicitation after serverless cold starts. Related: cloudflare/agents#783 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Updates documentation to reflect that WorkerTransport now persists client capabilities across serverless restarts. This fixes an issue where elicitation and other capability-dependent features would fail after hibernation or cold starts. Changes: - Add initializeParams to TransportState interface documentation - Document that client capabilities are persisted and restored - Clarify the behavior of state restoration Related to cloudflare/agents#783 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
0d65eb7 to
b9e1176
Compare
mattzcarey
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
epic stuff, congrats
Summary
Persist and restore client capabilities (
initializeParams) across serverless restarts when usingWorkerTransportwith storage.Problem
When using
WorkerTransportwith storage in a serverless environment (like Cloudflare Workers), client capabilities (like elicitation support) were not persisted across requests. This caused elicitation and other capability-dependent features to fail after a serverless cold start with:Root Cause:
TransportStateonly stored{ sessionId, initialized }_clientCapabilitiesis stored in-memory on the MCP SDK'sServerinstance_clientCapabilitieswasundefinedbecause it wasn't restoredSolution
Store the full
initializeParams(capabilities, clientInfo, protocolVersion) and replay the initialize request during state restoration to restore_clientCapabilitieson the Server instance.Changes
packages/agents/src/mcp/worker-transport.ts:RESTORE_REQUEST_IDconstant for the synthetic restore request IDTransportStateinterface to includeinitializeParamsinitializeParamsduring initialization before callingsaveState()this.onmessage()duringrestoreState()to restore_clientCapabilitiessend()to prevent error from missing streampackages/agents/src/tests/mcp/transports/worker-transport.test.ts:"Client Capabilities Persistence (Serverless Restart)"with 5 tests covering persistence, restoration, and backward compatibilityBreaking Changes
None. The
TransportStateinterface change is backward compatible - old stored state withoutinitializeParamswill continue to work (capabilities just won't be restored).Future Improvement
The ideal solution would be to extend the MCP TypeScript SDK with a function to directly update
clientCapabilitieson the Server instance, rather than replaying the initialize request. This would be a cleaner approach that doesn't rely on internal implementation details.Closes #777
🤖 Generated with OpenCode using Claude