|
1 | 1 | import { getCloudflareClient } from '../cloudflare-api' |
2 | 2 | import { type CloudflareMcpAgent } from '../types/cloudflare-mcp-agent' |
3 | | -import { AsnParam, AsOrderByParam, IpParam, SingleLocationParam } from '../types/radar' |
| 3 | +import { AsnParam, AsOrderByParam, DateRangeParam, IpParam, SingleLocationParam } from '../types/radar' |
4 | 4 | import { PaginationLimitParam, PaginationOffsetParam } from '../types/shared' |
5 | 5 |
|
6 | 6 | export function registerRadarTools(agent: CloudflareMcpAgent) { |
@@ -113,4 +113,49 @@ export function registerRadarTools(agent: CloudflareMcpAgent) { |
113 | 113 | } |
114 | 114 | } |
115 | 115 | ) |
| 116 | + |
| 117 | + agent.server.tool( |
| 118 | + 'radar_get_traffic_anomalies', |
| 119 | + 'Get traffic anomalies', |
| 120 | + { |
| 121 | + limit: PaginationLimitParam, |
| 122 | + offset: PaginationOffsetParam, |
| 123 | + asn: AsnParam.optional(), |
| 124 | + location: SingleLocationParam, |
| 125 | + dateRange: DateRangeParam |
| 126 | + }, |
| 127 | + async ({ limit, offset, asn, location, dateRange }) => { |
| 128 | + try { |
| 129 | + const client = getCloudflareClient(agent.props.accessToken) |
| 130 | + const r = await client.radar.trafficAnomalies.get({ |
| 131 | + limit: limit ?? undefined, |
| 132 | + offset: offset ?? undefined, |
| 133 | + asn: asn ?? undefined, |
| 134 | + location: location ?? undefined, |
| 135 | + dateRange: dateRange ?? undefined, |
| 136 | + status: "VERIFIED" |
| 137 | + }) |
| 138 | + |
| 139 | + return { |
| 140 | + content: [ |
| 141 | + { |
| 142 | + type: 'text', |
| 143 | + text: JSON.stringify({ |
| 144 | + result: r.trafficAnomalies, |
| 145 | + }), |
| 146 | + }, |
| 147 | + ], |
| 148 | + } |
| 149 | + } catch (error) { |
| 150 | + return { |
| 151 | + content: [ |
| 152 | + { |
| 153 | + type: 'text', |
| 154 | + text: `Error getting IP details: ${error instanceof Error && error.message}`, |
| 155 | + }, |
| 156 | + ], |
| 157 | + } |
| 158 | + } |
| 159 | + } |
| 160 | + ) |
116 | 161 | } |
0 commit comments