@@ -4,13 +4,15 @@ import { McpAgent } from 'agents/mcp'
44import { env } from 'cloudflare:workers'
55
66import {
7- CloudflareAuthHandler ,
7+ createAuthHandlers ,
88 handleTokenExchangeCallback ,
99} from '@repo/mcp-common/src/cloudflare-oauth-handler'
1010import { registerAccountTools } from '@repo/mcp-common/src/tools/account'
1111
1212import { registerIntegrationsTools } from './tools/integrations'
1313
14+
15+
1416import type { AccountSchema , UserSchema } from '@repo/mcp-common/src/cloudflare-oauth-handler'
1517
1618// Context from the auth process, encrypted & stored in the auth token
@@ -22,8 +24,8 @@ export type Props = {
2224}
2325
2426export type State = { activeAccountId : string | null }
25-
2627export class MyMCP extends McpAgent < Env , State , Props > {
28+ // @ts -ignore
2729 server = new McpServer ( {
2830 name : 'Remote MCP Server with Workers Observability' ,
2931 version : '1.0.0' ,
@@ -34,11 +36,9 @@ export class MyMCP extends McpAgent<Env, State, Props> {
3436 }
3537
3638 async init ( ) {
39+ // @ts -ignore
3740 registerAccountTools ( this )
38-
39- registerIntegrationsTools ( this , env . CLOUDFLARE_GLOBAL_API_KEY )
40-
41- // TODO: registerFindingsTools @mleslie
41+ registerIntegrationsTools ( this )
4242 }
4343
4444 getActiveAccountId ( ) {
@@ -64,13 +64,22 @@ export class MyMCP extends McpAgent<Env, State, Props> {
6464 }
6565 }
6666}
67+ const CloudflareOneCasbScopes = {
68+ 'account:read' : 'See your account info such as account details, analytics, and memberships.' ,
69+ 'user:read' : 'See your user info such as name, email address, and account memberships.' ,
70+ 'workers:write' :
71+ 'See and change Cloudflare Workers data such as zones, KV storage, namespaces, scripts, and routes.' ,
72+ 'workers_observability:read' : 'See observability logs for your account' ,
73+ 'teams:read' : 'See Cloudflare One Resources' ,
74+ offline_access : 'Grants refresh tokens for long-lived access.' ,
75+ } as const
6776
6877export default new OAuthProvider ( {
6978 apiRoute : '/sse' ,
7079 // @ts -ignore
7180 apiHandler : MyMCP . mount ( '/sse' ) ,
7281 // @ts -ignore
73- defaultHandler : CloudflareAuthHandler ,
82+ defaultHandler : createAuthHandlers ( { scopes : CloudflareOneCasbScopes } ) ,
7483 authorizeEndpoint : '/oauth/authorize' ,
7584 tokenEndpoint : '/token' ,
7685 tokenExchangeCallback : ( options ) =>
0 commit comments