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 client API for enum-based connection states
Synchronizes documentation with cloudflare/agents PR #672 which introduces
enum-based connection state management.
Changes:
- Document new MCPConnectionState enum export with usage examples
- Update getMcpServers() return type to use MCPConnectionState enum
- Add examples showing type-safe state checking with enum constants
- Document fail-fast behavior during capability discovery
Related PR: cloudflare/agents#672
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
Your Agent can connect to external [Model Context Protocol (MCP)](https://modelcontextprotocol.io) servers to access tools, resources, and prompts. The `Agent` class provides three methods to manage MCP connections:
12
+
Your Agent can connect to external [Model Context Protocol (MCP)](https://modelcontextprotocol.io) servers to access tools, resources, and prompts. The `Agent` class provides three methods to manage MCP connections.
13
+
14
+
## Connection States
15
+
16
+
The Agents SDK exports an `MCPConnectionState` enum for type-safe connection state checking:
The `MCPConnectionState` enum includes these values:
43
+
44
+
-**`MCPConnectionState.AUTHENTICATING`** (`"authenticating"`) — Waiting for OAuth authorization to complete
45
+
-**`MCPConnectionState.CONNECTING`** (`"connecting"`) — Establishing transport connection to MCP server
46
+
-**`MCPConnectionState.DISCOVERING`** (`"discovering"`) — Discovering server capabilities (tools, resources, prompts)
47
+
-**`MCPConnectionState.READY`** (`"ready"`) — Fully connected and ready to use
48
+
-**`MCPConnectionState.FAILED`** (`"failed"`) — Connection failed at some point
49
+
50
+
### Connection Behavior
51
+
52
+
When establishing connections, the MCP client follows a fail-fast approach during capability discovery. If any capability (tools, resources, or prompts) fails to load from the server, the entire connection will transition to the `FAILED` state immediately. This ensures that connections are only marked as `READY` when all advertised capabilities are successfully available.
53
+
47
54
Connections persist in the Agent's [SQL storage](/agents/api-reference/store-and-sync-state), and when an Agent connects to an MCP server, all tools from that server become available automatically.
48
55
49
56
## Agent MCP Client Methods
@@ -183,19 +190,16 @@ None.
183
190
An `MCPServersState` object containing:
184
191
185
192
```ts
193
+
importtype { MCPConnectionState } from"agents";
194
+
186
195
{
187
196
servers: Record<
188
197
string,
189
198
{
190
199
name: string;
191
200
server_url: string;
192
201
auth_url: string|null;
193
-
state:
194
-
|"authenticating"
195
-
|"connecting"
196
-
|"ready"
197
-
|"discovering"
198
-
|"failed";
202
+
state: MCPConnectionState;
199
203
capabilities: ServerCapabilities|null;
200
204
instructions: string|null;
201
205
}
@@ -211,24 +215,42 @@ An `MCPServersState` object containing:
The `state` field can be: `authenticating`, `connecting`, `ready`, `discovering`, or `failed`. Use this method to monitor connection status, list available tools, or build UI for connected servers.
253
+
The `state` field is of type `MCPConnectionState` and can be compared using the enum constants (for example, `MCPConnectionState.READY`, `MCPConnectionState.AUTHENTICATING`). Use this method to monitor connection status, list available tools, or build UI for connected servers.
0 commit comments