Skip to content

Commit e8bdd03

Browse files
committed
add radar_as_details tool
1 parent 2e97917 commit e8bdd03

File tree

2 files changed

+37
-8
lines changed

2 files changed

+37
-8
lines changed

packages/mcp-common/src/tools/radar.ts

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { getCloudflareClient } from '../cloudflare-api'
22
import { type CloudflareMcpAgent } from '../types/cloudflare-mcp-agent'
3-
import { AsOrderByParam, SingleLocationParam } from '../types/radar'
3+
import { AsnParam, AsOrderByParam, SingleLocationParam } from '../types/radar'
44
import { PaginationLimitParam, PaginationOffsetParam } from '../types/shared'
55

66
export function registerRadarTools(agent: CloudflareMcpAgent) {
@@ -28,7 +28,7 @@ export function registerRadarTools(agent: CloudflareMcpAgent) {
2828
{
2929
type: 'text',
3030
text: JSON.stringify({
31-
result: r,
31+
result: r.asns,
3232
}),
3333
},
3434
],
@@ -45,4 +45,38 @@ export function registerRadarTools(agent: CloudflareMcpAgent) {
4545
}
4646
}
4747
)
48+
49+
agent.server.tool(
50+
'radar_as_details',
51+
'Get Autonomous System details by ASN',
52+
{
53+
asn : AsnParam,
54+
},
55+
async ({ asn }) => {
56+
try {
57+
const client = getCloudflareClient(agent.props.accessToken)
58+
const r = await client.radar.entities.asns.get(asn)
59+
60+
return {
61+
content: [
62+
{
63+
type: 'text',
64+
text: JSON.stringify({
65+
result: r.asn,
66+
}),
67+
},
68+
],
69+
}
70+
} catch (error) {
71+
return {
72+
content: [
73+
{
74+
type: 'text',
75+
text: `Error getting AS details: ${error instanceof Error && error.message}`,
76+
},
77+
],
78+
}
79+
}
80+
}
81+
)
4882
}

packages/mcp-common/src/types/radar.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ import { z } from 'zod'
55

66
import type { ASNListParams } from 'cloudflare/resources/radar/entities/asns.mjs'
77

8-
export const AsnParam: z.ZodType<ASNListParams['asn']> = z
9-
.string()
10-
.optional()
11-
.refine((val) => val?.split(',').every((asn) => parseInt(asn, 10) > 0), {
12-
message: 'ASNs must be positive integers',
13-
})
8+
export const AsnParam = z.number().positive()
149

1510
export const SingleLocationParam: z.ZodType<ASNListParams['location']> = z
1611
.string()

0 commit comments

Comments
 (0)