Skip to content

Commit f91e408

Browse files
committed
Add get_ai_data Radar tool
1 parent 6724aa0 commit f91e408

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

apps/radar/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Currently available tools:
1212

1313
| **Category** | **Tool** | **Description** |
1414
| ---------------------- | ------------------------------- | --------------------------------------------------------------------------------------------------------------------- |
15+
| **AI** | `get_ai_data` | Retrieves AI-related data, including traffic from AI user agents, as well as popular models and model tasks. |
1516
| **Autonomous Systems** | `list_autonomous_systems` | Lists ASes; filter by location and sort by population size |
1617
| | `get_as_details` | Retrieves detailed info for a specific ASN |
1718
| **Domains** | `get_domains_ranking` | Gets top or trending domains |
@@ -22,8 +23,8 @@ Currently available tools:
2223
| **HTTP** | `get_http_data` | Retrieves HTTP request data, including timeseries, and breakdowns by dimensions like `deviceType`. |
2324
| **IP Addresses** | `get_ip_details` | Provides details about a specific IP address |
2425
| **Internet Services** | `get_internet_services_ranking` | Gets top Internet services |
25-
| **Internet Speed** | `get_internet_speed_data` | Retrieves summary of bandwidth, latency, jitter, and packet loss, from the previous 90 days of Cloudflare Speed Test. |
2626
| **Internet Quality** | `get_internet_quality_data` | Retrieves a summary or time series of bandwidth, latency, or DNS response time from the Radar Internet Quality Index. |
27+
| **Internet Speed** | `get_internet_speed_data` | Retrieves summary of bandwidth, latency, jitter, and packet loss, from the previous 90 days of Cloudflare Speed Test. |
2728
| **Layer 3 Attacks** | `get_l3_attack_data` | Retrieves L3 attack data, including timeseries, top attacks, and breakdowns by dimensions like `protocol`. |
2829
| **Layer 7 Attacks** | `get_l7_attack_data` | Retrieves L7 attack data, including timeseries, top attacks, and breakdowns by dimensions like `mitigationProduct`. |
2930
| **Traffic Anomalies** | `get_traffic_anomalies` | Lists traffic anomalies and outages; filter by AS, location, start date, and end date |

apps/radar/src/tools/radar.ts

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { getCloudflareClient } from '@repo/mcp-common/src/cloudflare-api'
44
import { PaginationLimitParam, PaginationOffsetParam } from '@repo/mcp-common/src/types/shared'
55

66
import {
7+
AiDimensionParam,
78
AsnArrayParam,
89
AsnParam,
910
AsOrderByParam,
@@ -635,20 +636,24 @@ export function registerRadarTools(agent: RadarMCP) {
635636
'get_internet_quality_data',
636637
'Retrieves a summary or time series of bandwidth, latency, or DNS response time percentiles from the Radar Internet Quality Index (IQI).',
637638
{
639+
dateRange: DateRangeArrayParam.optional(),
640+
dateStart: DateStartArrayParam.optional(),
638641
dateEnd: DateEndArrayParam.optional(),
639642
asn: AsnArrayParam,
640643
continent: ContinentArrayParam,
641644
location: LocationArrayParam,
642645
format: z.enum(['summary', 'timeseriesGroups']),
643646
metric: InternetQualityMetricParam,
644647
},
645-
async ({ dateEnd, asn, location, continent, format, metric }) => {
648+
async ({ dateRange, dateStart, dateEnd, asn, location, continent, format, metric }) => {
646649
try {
647650
const client = getCloudflareClient(agent.props.accessToken)
648651
const r = await client.radar.quality.iqi[format]({
649652
asn,
650653
continent,
651654
location,
655+
dateRange,
656+
dateStart,
652657
dateEnd,
653658
metric,
654659
})
@@ -675,4 +680,51 @@ export function registerRadarTools(agent: RadarMCP) {
675680
}
676681
}
677682
)
683+
684+
agent.server.tool(
685+
'get_ai_data',
686+
'Retrieves AI-related data, including traffic from AI user agents, as well as popular models and model tasks specifically from Cloudflare Workers AI.',
687+
{
688+
dateRange: DateRangeArrayParam.optional(),
689+
dateStart: DateStartArrayParam.optional(),
690+
dateEnd: DateEndArrayParam.optional(),
691+
asn: AsnArrayParam,
692+
continent: ContinentArrayParam,
693+
location: LocationArrayParam,
694+
dimension: AiDimensionParam,
695+
},
696+
async ({ dateRange, dateStart, dateEnd, asn, location, continent, dimension }) => {
697+
try {
698+
const client = getCloudflareClient(agent.props.accessToken)
699+
const r = await resolveAndInvoke(client.radar.ai, dimension, {
700+
asn,
701+
continent,
702+
location,
703+
dateRange,
704+
dateStart,
705+
dateEnd,
706+
})
707+
708+
return {
709+
content: [
710+
{
711+
type: 'text',
712+
text: JSON.stringify({
713+
result: r,
714+
}),
715+
},
716+
],
717+
}
718+
} catch (error) {
719+
return {
720+
content: [
721+
{
722+
type: 'text',
723+
text: `Error getting AI data: ${error instanceof Error && error.message}`,
724+
},
725+
],
726+
}
727+
}
728+
}
729+
)
678730
}

apps/radar/src/types/radar.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,17 @@ export const EmailSecurityDimensionParam = z
293293
])
294294
.describe('Dimension indicating the type and format of Email Security data to retrieve.')
295295

296+
export const AiDimensionParam = z
297+
.enum([
298+
'bots/summary/userAgent',
299+
'bots/timeseriesGroups/userAgent',
300+
'inference/summary/model',
301+
'inference/summary/task',
302+
'inference/timeseriesGroups/model',
303+
'inference/timeseriesGroups/task',
304+
])
305+
.describe('Dimension indicating the type and format of AI data to retrieve.')
306+
296307
export const InternetSpeedDimensionParam = z
297308
.enum(['summary', 'top/locations', 'top/ases'])
298309
.describe('Dimension indicating the type and format of Internet speed data to retrieve.')

0 commit comments

Comments
 (0)