Skip to content

Commit 69f2740

Browse files
author
sabina
committed
add new radar tool attacks
1 parent b5e2da8 commit 69f2740

File tree

3 files changed

+78
-1
lines changed

3 files changed

+78
-1
lines changed

apps/radar/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Currently available tools:
1313
| **Category** | **Tool** | **Description** |
1414
| ---------------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
1515
| **HTTP Requests** | `get_http_requests_data` | Fetches HTTP request data (timeseries, summaries, and grouped timeseries across dimensions like `deviceType`, `botClass`) |
16+
| **L7 Attacks** | `get_l7_attack_data` | Fetches L7 attack data (timeseries, summaries, and grouped timeseries across dimensions like `mitigationProduct`, `ipVersion`) |
1617
| **Autonomous Systems** | `list_autonomous_systems` | Lists ASes; filter by location and sort by population size |
1718
| | `get_as_details` | Retrieves detailed info for a specific ASN |
1819
| **IP Addresses** | `get_ip_details` | Provides details about a specific IP address |

apps/radar/src/tools/radar.ts

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
DomainParam,
1818
DomainRankingTypeParam,
1919
HttpDimensionParam,
20+
L7AttackDimensionParam,
2021
IpParam,
2122
LocationArrayParam,
2223
LocationListParam,
@@ -268,7 +269,7 @@ export function registerRadarTools(agent: RadarMCP) {
268269
'get_http_requests_data',
269270
'Retrieve HTTP request trends. Provide either a `dateRange`, or both `dateStart` and `dateEnd`, to define the time window. ' +
270271
'Use arrays to compare multiple filters — the array index determines which series each filter value belongs to.' +
271-
'For each filter series, you must provide a corresponding `dateRange`, or a `dateStart`/`dateEnd` pair.',
272+
'For each filter series, you must provide a corresponding `dateRange`, or a `dateStart`/`dateEnd` pair. For parsing the results here are some suggestions: Analyze the data if the response is a summary, If the response is a timeseries visualize the data',
272273
{
273274
dateRange: DateRangeArrayParam.optional(),
274275
dateStart: DateStartArrayParam.optional(),
@@ -322,4 +323,64 @@ export function registerRadarTools(agent: RadarMCP) {
322323
}
323324
}
324325
)
326+
327+
328+
agent.server.tool(
329+
'get_l7_attack_data',
330+
'Retrieve L7 app attack trends. Provide either a `dateRange`, or both `dateStart` and `dateEnd`, to define the time window. ' +
331+
'Use arrays to compare multiple filters — the array index determines which series each filter value belongs to.' +
332+
'For each filter series, you must provide a corresponding `dateRange`, or a `dateStart`/`dateEnd` pair.',
333+
{
334+
dateRange: DateRangeArrayParam.optional(),
335+
dateStart: DateStartArrayParam.optional(),
336+
dateEnd: DateEndArrayParam.optional(),
337+
asn: AsnArrayParam,
338+
continent: ContinentArrayParam,
339+
location: LocationArrayParam,
340+
format: DataFormatParam,
341+
dimension: L7AttackDimensionParam,
342+
},
343+
async ({ dateStart, dateEnd, dateRange, asn, location, continent, format, dimension }) => {
344+
try {
345+
if (format !== 'timeseries' && !dimension) {
346+
throw new Error(`The '${format}' format requires a 'dimension' to group the data.`)
347+
}
348+
349+
const client = getCloudflareClient(agent.props.accessToken)
350+
const endpoint = (...args: any) =>
351+
format === 'timeseries'
352+
? client.radar.attacks.layer7[format](...args)
353+
: client.radar.attacks.layer7[format][dimension!](...args)
354+
355+
const r = await endpoint({
356+
asn,
357+
continent,
358+
location,
359+
dateRange,
360+
dateStart,
361+
dateEnd,
362+
})
363+
364+
return {
365+
content: [
366+
{
367+
type: 'text',
368+
text: JSON.stringify({
369+
result: r,
370+
}),
371+
},
372+
],
373+
}
374+
} catch (error) {
375+
return {
376+
content: [
377+
{
378+
type: 'text',
379+
text: `Error getting L7 attack data: ${error instanceof Error && error.message}`,
380+
},
381+
],
382+
}
383+
}
384+
}
385+
)
325386
}

apps/radar/src/types/radar.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import { z } from 'zod'
55

66
import type { HTTPTimeseriesParams, RankingTopParams } from 'cloudflare/resources/radar'
7+
import type { Layer7TimeseriesParams } from 'cloudflare/resources/radar/attacks'
8+
79
import type { ASNListParams } from 'cloudflare/resources/radar/entities'
810

911
export const AsnParam = z
@@ -153,3 +155,16 @@ export const HttpDimensionParam = z
153155
.describe(
154156
"Dimension used to group HTTP data. Allowed only when the format is 'summary' or 'timeseriesGroups'."
155157
)
158+
159+
export const L7AttackDimensionParam = z
160+
.enum([
161+
162+
'httpMethod',
163+
'httpVersion',
164+
'ipVersion',
165+
'mitigationProduct',
166+
])
167+
.optional()
168+
.describe(
169+
"Dimension used to group L7 attack data. Allowed only when the format is 'summary' or 'timeseriesGroups'."
170+
)

0 commit comments

Comments
 (0)