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
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
Copy file name to clipboardExpand all lines: src/content/docs/agents/model-context-protocol/mcp-handler-api.mdx
+24-2Lines changed: 24 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -232,8 +232,9 @@ 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
236
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.
237
238
238
239
### WorkerTransport
239
240
@@ -386,7 +387,11 @@ interface MCPStorageApi {
386
387
interfaceTransportState {
387
388
sessionId?:string;
388
389
initialized:boolean;
389
-
protocolVersion?:ProtocolVersion;
390
+
initializeParams?: {
391
+
capabilities:ClientCapabilities;
392
+
clientInfo: { name:string; version:string };
393
+
protocolVersion:string;
394
+
};
390
395
}
391
396
```
392
397
@@ -409,6 +414,23 @@ const transport = new WorkerTransport({
409
414
410
415
</TypeScriptExample>
411
416
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
+
412
434
## Authentication Context
413
435
414
436
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