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: update MCP connection states and error handling
This sync updates the documentation to reflect changes from cloudflare/agents PR #672:
- Documented new connection state machine with separate CONNECTED and READY states
- ClientConnection.init() no longer automatically discovers capabilities
- Added MCPConnectionState enum documentation with all possible states
- Documented new CONNECTED state for transport connection without capabilities
- Added detailed state transition flows for OAuth and non-OAuth connections
- Updated error handling section to reflect fail-fast behavior with Promise.all
- Added explanations for each connection state
- Clarified the difference between CONNECTED and READY states
Related PR: cloudflare/agents#672
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
Copy file name to clipboardExpand all lines: src/content/docs/agents/model-context-protocol/mcp-client-api.mdx
+39-23Lines changed: 39 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -245,6 +245,37 @@ The `state` field indicates the current connection status and follows a state ma
245
245
246
246
Use this method to monitor connection status, list available tools, or build UI for connected servers.
247
247
248
+
## Connection State Machine
249
+
250
+
MCP client connections follow a state machine that ensures proper initialization and capability discovery. The connection states are defined in the `MCPConnectionState` enum:
You can also provide a `customHandler` function for full control over the callback response. Refer to the [OAuth handling guide](/agents/guides/oauth-mcp-client) for details.
268
299
269
-
## Connection States
270
-
271
-
The `MCPConnectionState` enum defines all possible connection states:
Use these constants when comparing connection states to ensure type safety and avoid string typos.
290
-
291
300
## Error Handling
292
301
293
-
Use error detection utilities to handle connection errors:
302
+
MCP client connections now fail fast with immediate error propagation. If server capability discovery fails, an error is thrown immediately rather than continuing with empty arrays. Use error detection utilities to handle connection errors:
-**Connection failures** — Network issues or invalid URLs will throw errors during the `connecting` state
331
+
-**Discovery failures** — If the server fails to return capabilities, an error is thrown immediately during the `discovering` state (uses `Promise.all` for fail-fast behavior)
332
+
-**Transport not supported** — If the specified transport type is not implemented by the server, `isTransportNotImplemented()` will return `true`
333
+
318
334
:::note[Discovery error handling]
319
335
320
336
Starting with the latest release, MCP client discovery failures now throw errors immediately instead of silently continuing with empty tool arrays. This ensures connection issues are caught early and handled explicitly. Monitor the connection `state` field to detect `failed` states.
0 commit comments