You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs: document client capability persistence in WorkerTransport
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 <[email protected]>
Copy file name to clipboardExpand all lines: src/content/docs/agents/model-context-protocol/mcp-handler-api.mdx
+10-3Lines changed: 10 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -158,7 +158,7 @@ Each request to this MCP server creates a new session. The server doesn't mainta
158
158
159
159
## Stateful MCP Servers
160
160
161
-
For stateful MCP servers that need to maintain session state across multiple requests, you can use the `createMcpHandler` function with a `WorkerTransport` instance directly in an `Agent`. This is useful if you want to make use of advanced client features like elicitation and sampling.
161
+
For stateful MCP servers that need to maintain session state across multiple requests, you can use the `createMcpHandler` function with a `WorkerTransport` instance directly in an `Agent`. This is useful if you want to make use of advanced client features like [elicitation](https://modelcontextprotocol.io/specification/draft/client/elicitation) and [sampling](https://modelcontextprotocol.io/specification/draft/client/sampling).
162
162
163
163
Provide a custom `WorkerTransport` with persistent storage. View the [complete example on GitHub](https://github.com/cloudflare/agents/tree/main/examples/mcp-elicitation).
164
164
@@ -232,9 +232,10 @@ With persistent storage, the transport preserves:
232
232
- Session ID across reconnections
233
233
- Protocol version negotiation state
234
234
- Initialization status
235
-
- Client capabilities (such as elicitation and sampling support)
235
+
- Client capabilities (including elicitation and sampling support)
236
+
- Client information (name and version)
236
237
237
-
This allows MCP clients to reconnect and resume their session in the event of a connection loss. Additionally, when an Agent hibernates and restarts in serverless environments, client capabilities are automatically restored, ensuring advanced MCP features like elicitation continue to function correctly.
238
+
This allows MCP clients to reconnect and resume their session in the event of a connection loss. Importantly, client capabilities like [elicitation](https://modelcontextprotocol.io/specification/draft/client/elicitation)are persisted and restored, ensuring that capability-dependent features work correctly after serverless restarts.
238
239
239
240
### WorkerTransport
240
241
@@ -395,6 +396,12 @@ interface TransportState {
395
396
}
396
397
```
397
398
399
+
The `initializeParams` field stores the client capabilities, client information, and protocol version from the initial MCP handshake. When the transport is restored from storage (for example, after a serverless restart), these parameters are replayed to restore the client capabilities on the MCP Server instance. This ensures that capability-dependent features like elicitation continue to work after restarts.
400
+
401
+
:::note[Backward Compatibility]
402
+
The `initializeParams` field is optional. Existing stored state without this field will continue to work — the transport will simply start without restored client capabilities.
0 commit comments