bgp_prefix
Look up BGP routing details for IP prefixes to identify announcing ASNs, network names, countries, and regional internet registries.
Instructions
Look up details for a specific IP prefix/CIDR. Returns announcing ASNs, name, country, and RIR.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| prefix | Yes | IP prefix (e.g. '1.1.1.0') | |
| cidr | Yes | CIDR mask (e.g. 24) |
Implementation Reference
- src/bgp/index.ts:103-124 (handler)The actual implementation of the bgp_prefix logic, fetching data from bgpview.io.
export async function bgpPrefix(prefix: string, cidr: number): Promise<BgpPrefixResult> { const key = `prefix:${prefix}/${cidr}`; const cached = cache.get(key); if (cached) return cached; const data = await bgpFetch(`/prefix/${prefix}/${cidr}`); const result: BgpPrefixResult = { prefix: data.prefix, cidr: data.cidr, asns: (data.asns ?? []).map((a: any) => ({ asn: a.asn, name: a.name, description: a.description, countryCode: a.country_code, })), name: data.name ?? "", description: data.description_short ?? "", countryCode: data.country_code ?? "", rir: data.rir_allocation?.rir_name ?? "", }; cache.set(key, result); return result; } - src/bgp/index.ts:27-35 (schema)The return type schema for the bgp_prefix tool.
interface BgpPrefixResult { prefix: string; cidr: number; asns: { asn: number; name: string; description: string; countryCode: string }[]; name: string; description: string; countryCode: string; rir: string; } - src/protocol/tools.ts:361-369 (registration)Tool registration and definition for bgp_prefix in the MCP tool registry.
const bgpPrefixTool: ToolDef = { name: "bgp_prefix", description: "Look up details for a specific IP prefix/CIDR. Returns announcing ASNs, name, country, and RIR.", schema: { prefix: z.string().describe("IP prefix (e.g. '1.1.1.0')"), cidr: z.number().describe("CIDR mask (e.g. 24)"), }, execute: async (args) => json(await bgpPrefix(args.prefix as string, args.cidr as number)), };