Skip to content

Commit 2333a18

Browse files
committed
Use Cloudflare Observability MCP as example
1 parent 5e4934a commit 2333a18

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

src/content/docs/agents/guides/oauth-mcp-client.mdx

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ sidebar:
99

1010
import { Render, TypeScriptExample, PackageManagers } from "~/components";
1111

12-
When you build an Agent that connects to OAuth-protected MCP servers (like GitHub, 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 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.
1313

1414
## Understanding the OAuth flow
1515

@@ -18,26 +18,26 @@ When your Agent connects to an OAuth-protected MCP server, here's what happens:
1818
1. **Your code calls** `addMcpServer()` with the server URL
1919
2. **If OAuth is required**, it returns an `authUrl` instead of immediately connecting
2020
3. **Your application presents** the `authUrl` to your user
21-
4. **Your user authenticates** on the provider's site (GitHub, Slack, etc.)
21+
4. **Your user authenticates** on the provider's site (Slack, etc.)
2222
5. **The provider redirects** back to your Agent's callback URL with an authorization code
2323
6. **Your Agent completes** the connection automatically
2424

2525
## Connect and initiate OAuth
2626

27-
When you connect to an OAuth-protected server (like GitHub), check if `authUrl` is returned. If present, automatically redirect your user to complete authorization:
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:
2828

2929
<TypeScriptExample>
3030

3131
```ts title="src/index.ts"
32-
export class GitHubAgent extends Agent<Env, never> {
32+
export class ObservabilityAgent extends Agent<Env, never> {
3333
async onRequest(request: Request): Promise<Response> {
3434
const url = new URL(request.url);
3535

36-
if (url.pathname.endsWith("connect-github") && request.method === "POST") {
37-
// Attempt to connect to GitHub's MCP server
36+
if (url.pathname.endsWith("connect-observability") && request.method === "POST") {
37+
// Attempt to connect to Cloudflare Observability MCP server
3838
const { id, authUrl } = await this.addMcpServer(
39-
"GitHub",
40-
"https://api.githubcopilot.com/mcp/",
39+
"Cloudflare Observability",
40+
"https://observability.mcp.cloudflare.com/mcp",
4141
);
4242

4343
if (authUrl) {
@@ -59,7 +59,7 @@ export class GitHubAgent extends Agent<Env, never> {
5959

6060
</TypeScriptExample>
6161

62-
Your user is automatically redirected to GitHub (or whichever provider) to authorize access.
62+
Your user is automatically redirected to the provider's OAuth page to authorize access.
6363

6464
**Alternative approaches**: Instead of automatic redirect, you can present the `authUrl` to your user as:
6565
- **Popup window**: `window.open(authUrl, '_blank', 'width=600,height=700')` (for dashboard-style apps)
@@ -253,7 +253,7 @@ function App() {
253253
});
254254

255255
// Retry connection
256-
const response = await fetch(`/agents/my-agent/session-id/connect-github`, {
256+
const response = await fetch(`/agents/my-agent/session-id/connect-observability`, {
257257
method: "POST",
258258
body: JSON.stringify({ serverUrl, name }),
259259
});
@@ -287,15 +287,15 @@ function App() {
287287
Common failure reasons:
288288

289289
- **User canceled**: Closed OAuth window before completing authorization
290-
- **Invalid credentials**: GitHub/Slack credentials were incorrect
290+
- **Invalid credentials**: Slack credentials were incorrect
291291
- **Permission denied**: User lacks required permissions (e.g., not a workspace admin)
292292
- **Expired session**: OAuth session timed out
293293

294294
Failed connections remain in state until you remove them with `removeMcpServer(serverId)`.
295295

296296
## Complete example
297297

298-
This example demonstrates a complete GitHub OAuth integration. Users click "Connect GitHub", authorize in a popup window, and the connection becomes available. The Agent provides endpoints to connect, check status, and disconnect.
298+
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.
299299

300300
:::note
301301

@@ -310,10 +310,10 @@ import { Agent, type AgentNamespace, routeAgentRequest } from "agents";
310310
import type { MCPClientOAuthResult } from "agents/mcp";
311311

312312
type Env = {
313-
GitHubAgent: AgentNamespace<GitHubAgent>;
313+
ObservabilityAgent: AgentNamespace<ObservabilityAgent>;
314314
};
315315

316-
export class GitHubAgent extends Agent<Env, never> {
316+
export class ObservabilityAgent extends Agent<Env, never> {
317317
onStart() {
318318
// Configure OAuth callback to close popup window
319319
this.mcp.configureOAuthCallback({
@@ -324,7 +324,7 @@ export class GitHubAgent extends Agent<Env, never> {
324324
});
325325
} else {
326326
return new Response(
327-
`<script>alert('GitHub authorization failed: ${result.authError}'); window.close();</script>`,
327+
`<script>alert('Authorization failed: ${result.authError}'); window.close();</script>`,
328328
{ headers: { "content-type": "text/html" } },
329329
);
330330
}
@@ -335,19 +335,19 @@ export class GitHubAgent extends Agent<Env, never> {
335335
async onRequest(request: Request): Promise<Response> {
336336
const url = new URL(request.url);
337337

338-
// Endpoint: Connect to GitHub MCP server
339-
if (url.pathname.endsWith("connect-github") && request.method === "POST") {
338+
// Endpoint: Connect to Cloudflare Observability MCP server
339+
if (url.pathname.endsWith("connect-observability") && request.method === "POST") {
340340
const { id, authUrl } = await this.addMcpServer(
341-
"GitHub",
342-
"https://api.githubcopilot.com/mcp/",
341+
"Cloudflare Observability",
342+
"https://observability.mcp.cloudflare.com/mcp",
343343
);
344344

345345
if (authUrl) {
346346
return new Response(
347347
JSON.stringify({
348348
serverId: id,
349349
authUrl: authUrl,
350-
message: "Please authorize GitHub access",
350+
message: "Please authorize Cloudflare Observability access",
351351
}),
352352
{ headers: { "Content-Type": "application/json" } },
353353
);
@@ -379,13 +379,13 @@ export class GitHubAgent extends Agent<Env, never> {
379379
});
380380
}
381381

382-
// Endpoint: Disconnect from GitHub
382+
// Endpoint: Disconnect from Cloudflare Observability
383383
if (url.pathname.endsWith("disconnect") && request.method === "POST") {
384384
const { serverId } = (await request.json()) as { serverId: string };
385385
await this.removeMcpServer(serverId);
386386

387387
return new Response(
388-
JSON.stringify({ message: "Disconnected from GitHub" }),
388+
JSON.stringify({ message: "Disconnected from Cloudflare Observability" }),
389389
{ headers: { "Content-Type": "application/json" } },
390390
);
391391
}

0 commit comments

Comments
 (0)