@@ -4,13 +4,15 @@ import { McpAgent } from 'agents/mcp'
4
4
import { env } from 'cloudflare:workers'
5
5
6
6
import {
7
- CloudflareAuthHandler ,
7
+ createAuthHandlers ,
8
8
handleTokenExchangeCallback ,
9
9
} from '@repo/mcp-common/src/cloudflare-oauth-handler'
10
10
import { registerAccountTools } from '@repo/mcp-common/src/tools/account'
11
11
12
12
import { registerIntegrationsTools } from './tools/integrations'
13
13
14
+
15
+
14
16
import type { AccountSchema , UserSchema } from '@repo/mcp-common/src/cloudflare-oauth-handler'
15
17
16
18
// Context from the auth process, encrypted & stored in the auth token
@@ -22,8 +24,8 @@ export type Props = {
22
24
}
23
25
24
26
export type State = { activeAccountId : string | null }
25
-
26
27
export class MyMCP extends McpAgent < Env , State , Props > {
28
+ // @ts -ignore
27
29
server = new McpServer ( {
28
30
name : 'Remote MCP Server with Workers Observability' ,
29
31
version : '1.0.0' ,
@@ -34,11 +36,9 @@ export class MyMCP extends McpAgent<Env, State, Props> {
34
36
}
35
37
36
38
async init ( ) {
39
+ // @ts -ignore
37
40
registerAccountTools ( this )
38
-
39
- registerIntegrationsTools ( this , env . CLOUDFLARE_GLOBAL_API_KEY )
40
-
41
- // TODO: registerFindingsTools @mleslie
41
+ registerIntegrationsTools ( this )
42
42
}
43
43
44
44
getActiveAccountId ( ) {
@@ -64,13 +64,22 @@ export class MyMCP extends McpAgent<Env, State, Props> {
64
64
}
65
65
}
66
66
}
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
67
76
68
77
export default new OAuthProvider ( {
69
78
apiRoute : '/sse' ,
70
79
// @ts -ignore
71
80
apiHandler : MyMCP . mount ( '/sse' ) ,
72
81
// @ts -ignore
73
- defaultHandler : CloudflareAuthHandler ,
82
+ defaultHandler : createAuthHandlers ( { scopes : CloudflareOneCasbScopes } ) ,
74
83
authorizeEndpoint : '/oauth/authorize' ,
75
84
tokenEndpoint : '/token' ,
76
85
tokenExchangeCallback : ( options ) =>
0 commit comments