@@ -3,66 +3,38 @@ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
33import { McpAgent } from 'agents/mcp'
44import { env } from 'cloudflare:workers'
55
6- import {
7- createAuthHandlers ,
8- handleTokenExchangeCallback ,
9- } from '@repo/mcp-common/src/cloudflare-oauth-handler'
10- import { registerAccountTools } from '@repo/mcp-common/src/tools/account'
6+ import { createAuthHandlers , handleTokenExchangeCallback , } from '@repo/mcp-common/src/cloudflare-oauth-handler'
117
128import { registerRadarTools } from './tools/radar'
139
14- import type { AccountSchema , UserSchema } from '@repo/mcp-common/src/cloudflare-oauth-handler'
15-
1610// Context from the auth process, encrypted & stored in the auth token
1711// and provided to the DurableMCP as this.props
1812export type Props = {
1913 accessToken : string
20- user : UserSchema [ 'result' ]
21- accounts : AccountSchema [ 'result' ]
2214}
2315
24- export type State = { activeAccountId : string | null }
16+ export type State = never
2517
2618export class RadarMCP extends McpAgent < Env , State , Props > {
2719 server = new McpServer ( {
2820 name : 'Remote MCP Server with Cloudflare Radar Data' ,
2921 version : '1.0.0' ,
3022 } )
3123
32- initialState : State = {
33- activeAccountId : null ,
24+ constructor (
25+ public ctx : DurableObjectState ,
26+ public env : Env
27+ ) {
28+ super ( ctx , env )
3429 }
3530
3631 async init ( ) {
37- registerAccountTools ( this )
38-
3932 registerRadarTools ( this )
4033 }
41-
42- getActiveAccountId ( ) {
43- // TODO: Figure out why this fail sometimes, and why we need to wrap this in a try catch
44- try {
45- return this . state . activeAccountId ?? null
46- } catch ( e ) {
47- return null
48- }
49- }
50-
51- setActiveAccountId ( accountId : string ) {
52- // TODO: Figure out why this fail sometimes, and why we need to wrap this in a try catch
53- try {
54- this . setState ( {
55- ...this . state ,
56- activeAccountId : accountId ,
57- } )
58- } catch ( e ) {
59- return null
60- }
61- }
6234}
6335
36+ // TODO review these scopes
6437const RadarScopes = {
65- 'account:read' : 'See your account info such as account details, analytics, and memberships.' ,
6638 'user:read' : 'See your user info such as name, email address, and account memberships.' ,
6739 offline_access : 'Grants refresh tokens for long-lived access.' ,
6840} as const
0 commit comments