Skip to content

Commit 48563dd

Browse files
committed
remove unnecessary state from radar mcp server
1 parent 0de0dd7 commit 48563dd

File tree

3 files changed

+21
-42
lines changed

3 files changed

+21
-42
lines changed

apps/radar/src/index.ts

Lines changed: 8 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,66 +3,38 @@ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
33
import { McpAgent } from 'agents/mcp'
44
import { 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

128
import { 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
1812
export 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

2618
export 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
6437
const 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

apps/radar/src/tools/radar.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import { getCloudflareClient } from '@repo/mcp-common/src/cloudflare-api'
2-
import { type CloudflareMcpAgent } from '@repo/mcp-common/src/types/cloudflare-mcp-agent'
32
import { PaginationLimitParam, PaginationOffsetParam } from '@repo/mcp-common/src/types/shared'
43

54
import {
65
AsnParam,
76
AsOrderByParam,
8-
DateRangeParam,
7+
DateEndParam,
8+
DateStartParam,
99
IpParam,
1010
SingleLocationParam,
1111
} from '../types/radar'
12+
import type { RadarMCP } from "../index";
1213

13-
export function registerRadarTools(agent: CloudflareMcpAgent) {
14+
export function registerRadarTools(agent: RadarMCP) {
1415
agent.server.tool(
1516
'radar_ases_list',
1617
'List Autonomous Systems',
@@ -129,17 +130,20 @@ export function registerRadarTools(agent: CloudflareMcpAgent) {
129130
offset: PaginationOffsetParam,
130131
asn: AsnParam.optional(),
131132
location: SingleLocationParam,
132-
dateRange: DateRangeParam,
133+
// TODO maybe we don't need this param since we have the other two dateRange: DateRangeParam.optional(),
134+
dateStart: DateStartParam,
135+
dateEnd: DateEndParam,
133136
},
134-
async ({ limit, offset, asn, location, dateRange }) => {
137+
async ({ limit, offset, asn, location, dateStart, dateEnd }) => {
135138
try {
136139
const client = getCloudflareClient(agent.props.accessToken)
137140
const r = await client.radar.trafficAnomalies.get({
138141
limit: limit ?? undefined,
139142
offset: offset ?? undefined,
140143
asn: asn ?? undefined,
141144
location: location ?? undefined,
142-
dateRange: dateRange ?? undefined,
145+
dateStart: dateStart,
146+
dateEnd: dateEnd,
143147
status: 'VERIFIED',
144148
})
145149

apps/radar/src/types/radar.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ export const DateRangeParam: z.ZodType<TrafficAnomalyGetParams['dateRange']> = z
1818
'Invalid Date Range'
1919
)
2020

21+
export const DateStartParam: z.ZodType<TrafficAnomalyGetParams['dateStart']> = z.string().datetime()
22+
export const DateEndParam: z.ZodType<TrafficAnomalyGetParams['dateEnd']> = z.string().datetime()
23+
2124
export const SingleLocationParam: z.ZodType<ASNListParams['location']> = z
2225
.string()
2326
.regex(/^[a-zA-Z]{2}$/, {

0 commit comments

Comments
 (0)