MCPConnectionState enum for improved type safety
The Agents SDK now exports an MCPConnectionState enum that provides better type safety and consistency when working with MCP server connection states.
Connection states are now available as enum constants instead of string literals:
import { MCPConnectionState } from "agents";
// Check connection states using enum constantsif (server.state === MCPConnectionState.READY) { console.log("Server is ready to use");}Available states:
MCPConnectionState.AUTHENTICATING- Waiting for OAuth authorization to completeMCPConnectionState.CONNECTING- Establishing transport connection to MCP serverMCPConnectionState.DISCOVERING- Discovering server capabilities (tools, resources, prompts)MCPConnectionState.READY- Fully connected and ready to useMCPConnectionState.FAILED- Connection failed at some point
If you were using string literals to check connection states, update your code:
if (server.state === "ready") { // Do something}import { MCPConnectionState } from "agents";
if (server.state === MCPConnectionState.READY) { // Do something}MCP client connections now use fail-fast behavior with Promise.all instead of Promise.allSettled, providing quicker feedback when server capability discovery fails. The SDK also now only attempts to register capabilities that the server advertises, improving reliability and reducing unnecessary errors.
The connection state machine has been refined:
- Non-OAuth servers:
CONNECTING→DISCOVERING→READY - OAuth servers:
AUTHENTICATING→ (callback) →CONNECTING→DISCOVERING→READY - Errors: Any state can transition to
FAILEDon error
- MCP server state broadcasts now occur before and after OAuth connection establishment, providing better real-time updates to connected clients
- Connection state is set to
FAILEDbefore throwing errors during capability discovery, ensuring proper state management
For more information, refer to the McpClient API reference.
Was this helpful?
- Resources
- API
- New to Cloudflare?
- Directory
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- © 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark