Skip to content

Commit 8e8cbe0

Browse files
Document WorkerTransport client capabilities persistence
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
1 parent 2f6c674 commit 8e8cbe0

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,9 @@ 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)
235236

236-
This allows MCP clients to reconnect and resume their session in the event of a connection loss.
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.
237238

238239
### WorkerTransport
239240

@@ -386,7 +387,11 @@ interface MCPStorageApi {
386387
interface TransportState {
387388
sessionId?: string;
388389
initialized: boolean;
389-
protocolVersion?: ProtocolVersion;
390+
initializeParams?: {
391+
capabilities: ClientCapabilities;
392+
clientInfo: { name: string; version: string };
393+
protocolVersion: string;
394+
};
390395
}
391396
```
392397

@@ -409,6 +414,23 @@ const transport = new WorkerTransport({
409414

410415
</TypeScriptExample>
411416

417+
When using persistent storage, the `WorkerTransport` automatically stores and restores:
418+
419+
- **sessionId** — The unique session identifier
420+
- **initialized** — Whether the MCP session has completed initialization
421+
- **initializeParams** — The complete initialization parameters from the client, including:
422+
- **capabilities** — Client capabilities such as support for [elicitation](https://modelcontextprotocol.io/specification/draft/client/elicitation) and [sampling](https://modelcontextprotocol.io/specification/draft/client/sampling)
423+
- **clientInfo** — Information about the connecting client (name and version)
424+
- **protocolVersion** — The negotiated MCP protocol version
425+
426+
The `initializeParams` field is particularly important for serverless environments. When a Durable Object or Agent hibernates and restarts, the `WorkerTransport` automatically replays the initialization request to restore client capabilities on the MCP Server instance. This ensures features like elicitation continue to work correctly after cold starts.
427+
428+
:::note[Backward Compatibility]
429+
430+
The `initializeParams` field is optional to maintain backward compatibility. If you restore state that was persisted before this field was added, the transport will still function correctly, but client capabilities will not be available until the client reconnects and re-initializes.
431+
432+
:::
433+
412434
## Authentication Context
413435

414436
When using [OAuth authentication](/agents/model-context-protocol/authorization/) with `createMcpHandler`, user information is made available to your MCP tools through `getMcpAuthContext()`. Under the hood this uses `AsyncLocalStorage` to pass the request to the tool handler, keeping the authentication context available.

0 commit comments

Comments
 (0)