Skip to content

Commit 2c9cae3

Browse files
committed
Add layer 3 attacks Radar tool
1 parent 9c2ab68 commit 2c9cae3

File tree

3 files changed

+73
-1
lines changed

3 files changed

+73
-1
lines changed

apps/radar/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ 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`) |
16+
| **Layer 7 Attacks** | `get_l7_attack_data` | Fetches L7 attack data (timeseries, summaries, and grouped timeseries across dimensions like `mitigationProduct`, `ipVersion`) |
17+
| **Layer 3 Attacks** | `get_l3_attack_data` | Fetches L3 attack data (timeseries, summaries, and grouped timeseries across dimensions like `protocol`, `duration`) |
1718
| **Internet Speed** | `get_internet_speed_data` | Retrieve summary of bandwidth, latency, jitter, and packet loss, from the previous 90 days of Cloudflare Speed Test. |
1819
| **Autonomous Systems** | `list_autonomous_systems` | Lists ASes; filter by location and sort by population size |
1920
| | `get_as_details` | Retrieves detailed info for a specific ASN |

apps/radar/src/tools/radar.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
HttpDimensionParam,
2020
InternetServicesCategoryParam,
2121
IpParam,
22+
L3AttackDimensionParam,
2223
L7AttackDimensionParam,
2324
LocationArrayParam,
2425
LocationListParam,
@@ -418,6 +419,63 @@ export function registerRadarTools(agent: RadarMCP) {
418419
}
419420
)
420421

422+
agent.server.tool(
423+
'get_l3_attack_data',
424+
'Retrieve application layer (L3) attack trends.',
425+
{
426+
dateRange: DateRangeArrayParam.optional(),
427+
dateStart: DateStartArrayParam.optional(),
428+
dateEnd: DateEndArrayParam.optional(),
429+
asn: AsnArrayParam,
430+
continent: ContinentArrayParam,
431+
location: LocationArrayParam,
432+
format: DataFormatParam,
433+
dimension: L3AttackDimensionParam,
434+
},
435+
async ({ dateStart, dateEnd, dateRange, asn, location, continent, format, dimension }) => {
436+
try {
437+
if (format !== 'timeseries' && !dimension) {
438+
throw new Error(`The '${format}' format requires a 'dimension' to group the data.`)
439+
}
440+
441+
const client = getCloudflareClient(agent.props.accessToken)
442+
const endpoint = (...args: any) =>
443+
format === 'timeseries'
444+
? client.radar.attacks.layer3[format](...args)
445+
: client.radar.attacks.layer3[format][dimension!](...args)
446+
447+
const r = await endpoint({
448+
asn,
449+
continent,
450+
location,
451+
dateRange,
452+
dateStart,
453+
dateEnd,
454+
})
455+
456+
return {
457+
content: [
458+
{
459+
type: 'text',
460+
text: JSON.stringify({
461+
result: r,
462+
}),
463+
},
464+
],
465+
}
466+
} catch (error) {
467+
return {
468+
content: [
469+
{
470+
type: 'text',
471+
text: `Error getting L3 attack data: ${error instanceof Error && error.message}`,
472+
},
473+
],
474+
}
475+
}
476+
}
477+
)
478+
421479
agent.server.tool(
422480
'get_internet_speed_data',
423481
'Retrieve summary of bandwidth, latency, jitter, and packet loss, from the previous 90 days of Cloudflare Speed Test.',

apps/radar/src/types/radar.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,16 @@ export const L7AttackDimensionParam = z
187187
.describe(
188188
"Dimension used to group L7 attack data. Allowed only when the format is 'summary' or 'timeseriesGroups'."
189189
)
190+
191+
export const L3AttackDimensionParam = z
192+
.enum([
193+
'protocol',
194+
'ipVersion',
195+
'vector',
196+
'bitrate',
197+
// TODO: add 'vertical' and 'industry' once they are in the cloudflare API lib
198+
])
199+
.optional()
200+
.describe(
201+
"Dimension used to group L7 attack data. Allowed only when the format is 'summary' or 'timeseriesGroups'."
202+
)

0 commit comments

Comments
 (0)