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
Updates documentation to reflect security improvements in OAuth error handling:
- Remove MCPClientOAuthResult from customHandler signature (no longer receives error info)
- Document new `error` field in MCPServer type that stores connection errors
- Update examples to display errors from connection state instead of script alerts
- Add note that error messages are automatically escaped to prevent XSS attacks
- Simplify customHandler examples to only close popup (errors handled separately)
Related to cloudflare/agents#841
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Your main application can detect the popup closing and refresh the connection status.
116
+
Your main application can detect the popup closing and refresh the connection status. If OAuth fails, the connection state becomes `"failed"` and the error message is stored in `server.error` for display in your UI.
When OAuth fails, the connection state becomes `"failed"`. Detect this in your UI and allow users to retry:
213
+
When OAuth fails, the connection state becomes `"failed"` and the error message is stored in the `server.error` field. Display this error in your UI and allow users to retry:
-**Permission denied**: User lacks required permissions
285
279
-**Expired session**: OAuth session timed out
286
280
287
-
Failed connections remain in state until removed with `removeMcpServer(serverId)`.
281
+
Failed connections remain in state until removed with `removeMcpServer(serverId)`. The error message is automatically escaped to prevent XSS attacks, so it is safe to display directly in your UI.
288
282
289
283
## Complete example
290
284
291
-
This example demonstrates a complete OAuth integration with Cloudflare Observability. Users connect, authorize in a popup window, and the connection becomes available.
285
+
This example demonstrates a complete OAuth integration with Cloudflare Observability. Users connect, authorize in a popup window, and the connection becomes available. Errors are automatically stored in the connection state for display in your UI.
Copy file name to clipboardExpand all lines: src/content/docs/agents/model-context-protocol/mcp-client-api.mdx
+4-1Lines changed: 4 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -208,6 +208,7 @@ An `MCPServersState` object containing:
208
208
|"failed";
209
209
capabilities: ServerCapabilities|null;
210
210
instructions: string|null;
211
+
error: string|null;
211
212
}
212
213
>;
213
214
tools: Array<Tool& { serverId: string }>;
@@ -245,7 +246,9 @@ The `state` field indicates the connection lifecycle:
245
246
-`connected` — Transport connection established
246
247
-`discovering` — Discovering server capabilities (tools, resources, prompts)
247
248
-`ready` — Fully connected and operational
248
-
-`failed` — Connection failed
249
+
-`failed` — Connection failed (see `error` field for details)
250
+
251
+
The `error` field contains an error message when `state` is `"failed"`. Error messages from external OAuth providers are automatically escaped to prevent XSS attacks, making them safe to display directly in your UI.
249
252
250
253
Use this method to monitor connection status, list available tools, or build UI for connected servers.
0 commit comments