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 OAuth documentation to reflect security improvements from PR #841:
- Remove vulnerable pattern of displaying errors via script tags
- Document new error field on MCPServer type for safe error display
- Update custom OAuth handler examples to use secure pattern
- Add note about XSS prevention in popup OAuth flows
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Your main application can detect the popup closing and refresh the connection status.
126
117
118
+
:::note[Error handling in popup flow]
119
+
120
+
When using the popup approach, authentication errors are automatically stored in the connection state with the `error` field on the `MCPServer` object. Display these errors in your main application UI rather than in the popup window. This approach prevents XSS vulnerabilities and provides better user experience.
When OAuth fails, the connection state becomes `"failed"`. Detect this in your UI and allow users to retry:
216
+
When OAuth fails, the connection state becomes `"failed"`. The `error` field on the server object contains details about the failure. Detect this in your UI and allow users to retry:
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
@@ -206,6 +206,7 @@ An `MCPServersState` object containing:
206
206
|"discovering"
207
207
|"ready"
208
208
|"failed";
209
+
error: string|null;
209
210
capabilities: ServerCapabilities|null;
210
211
instructions: string|null;
211
212
}
@@ -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 (check `error` field for details)
250
+
251
+
The `error` field contains a human-readable error message when `state` is `"failed"`. Error messages are automatically sanitized to prevent XSS vulnerabilities. This field is `null` for all other states.
249
252
250
253
Use this method to monitor connection status, list available tools, or build UI for connected servers.
0 commit comments