Skip to content

Commit 7704885

Browse files
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]>
1 parent 8e8cbe0 commit 7704885

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/content/docs/agents/model-context-protocol/mcp-handler-api.mdx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ Each request to this MCP server creates a new session. The server doesn't mainta
158158

159159
## Stateful MCP Servers
160160

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).
162162

163163
Provide a custom `WorkerTransport` with persistent storage. View the [complete example on GitHub](https://github.com/cloudflare/agents/tree/main/examples/mcp-elicitation).
164164

@@ -232,9 +232,10 @@ With persistent storage, the transport preserves:
232232
- Session ID across reconnections
233233
- Protocol version negotiation state
234234
- 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)
236237

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.
238239

239240
### WorkerTransport
240241

@@ -395,6 +396,12 @@ interface TransportState {
395396
}
396397
```
397398

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.
403+
:::
404+
398405
<TypeScriptExample>
399406

400407
```ts

0 commit comments

Comments
 (0)