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
* Document MCP OAuth security hardening from agents PR #696
Add documentation for enhanced OAuth security measures that protect against replay attacks and DoS vulnerabilities:
- New changelog entry explaining the security improvements and breaking changes
- Added security note in OAuth guide describing automatic protections
- Documents state validation with nonce, TTL, and single-use tokens
- Notes callback URL unification across servers
Related to cloudflare/agents#696
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
* remove changelog
* lil cleanup of the mcp oauth docs
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Claude <[email protected]>
Co-authored-by: Matt Carey <[email protected]>
When you build an Agent that connects to OAuth-protected MCP servers (like Slack or Notion), your end users will need to authenticate before the Agent can access their data. This guide shows you how to implement OAuth flows so your users can authorize access seamlessly.
12
+
When connecting to OAuth-protected MCP servers (like Slack or Notion), your users need to authenticate before your Agent can access their data. This guide covers implementing OAuth flows for seamless authorization.
13
13
14
-
## Understanding the OAuth flow
14
+
## How it works
15
15
16
-
When your Agent connects to an OAuth-protected MCP server, here's what happens:
16
+
1. Call `addMcpServer()` with the server URL
17
+
2. If OAuth is required, an `authUrl` is returned instead of connecting immediately
18
+
3. Present the `authUrl` to your user (redirect, popup, or link)
19
+
4. User authenticates on the provider's site
20
+
5. Provider redirects back to your Agent's callback URL
21
+
6. Your Agent completes the connection automatically
17
22
18
-
1.**Your code calls**`addMcpServer()` with the server URL
19
-
2.**If OAuth is required**, it returns an `authUrl` instead of immediately connecting
20
-
3.**Your application presents** the `authUrl` to your user
21
-
4.**Your user authenticates** on the provider's site (Slack, etc.)
22
-
5.**The provider redirects** back to your Agent's callback URL with an authorization code
23
-
6.**Your Agent completes** the connection automatically
23
+
The MCP client uses a built-in `DurableObjectOAuthClientProvider` to manage OAuth state securely — storing a nonce and server ID, validating on callback, and cleaning up after use or expiration.
24
24
25
-
## Connect and initiate OAuth
25
+
## Initiate OAuth
26
26
27
-
When you connect to an OAuth-protected server (like Cloudflare Observability), check if `authUrl` is returned. If present, automatically redirect your user to complete authorization:
27
+
When connecting to an OAuth-protected server, check if `authUrl` is returned. If present, redirect your user to complete authorization:
-**User canceled**: Closed OAuth window before completing authorization
293
-
-**Invalid credentials**: Slack credentials were incorrect
294
-
-**Permission denied**: User lacks required permissions (e.g., not a workspace admin)
283
+
-**Invalid credentials**: Provider credentials were incorrect
284
+
-**Permission denied**: User lacks required permissions
295
285
-**Expired session**: OAuth session timed out
296
286
297
-
Failed connections remain in state until you remove them with `removeMcpServer(serverId)`.
287
+
Failed connections remain in state until removed with `removeMcpServer(serverId)`.
298
288
299
289
## Complete example
300
290
301
-
This example demonstrates a complete Cloudflare Observability OAuth integration. Users connect to Cloudflare Observability, authorize in a popup window, and the connection becomes available. The Agent provides endpoints to connect, check status, and disconnect.
302
-
303
-
:::note
304
-
305
-
For React applications: Replace the `/status` polling endpoint with the `useAgent` hook's `onMcpUpdate` callback for automatic state updates via WebSocket.
306
-
307
-
:::
291
+
This example demonstrates a complete OAuth integration with Cloudflare Observability. Users connect, authorize in a popup window, and the connection becomes available.
308
292
309
293
<TypeScriptExample>
310
294
@@ -313,12 +297,11 @@ import { Agent, type AgentNamespace, routeAgentRequest } from "agents";
0 commit comments