feat(mcp): добавить чтение полной таблицы маршрутов BGP
Docker images / prepare-release (push) Successful in 12s
Docker images / backend-test (push) Successful in 11m50s
Docker images / frontend-image (push) Successful in 4m5s
Docker images / updater-image (push) Successful in 41s
Docker images / netflow-agent-image (push) Successful in 35s
Docker images / backend-image (push) Successful in 2m29s
Docker images / publish-release (push) Successful in 12s
Docker images / notify-webhook (push) Successful in 2s

This commit is contained in:
Denozordec committed 2026-12-01 21:25:12 +07:00
1 parent 94c50b9660
commit 731c19a14d
4 files changed
+268 -1

No files matched your search

@@ -1,10 +1,12 @@
import { z } from "zod"
import { hasPermission } from "../../lib/permissions.js"
import { bgpPrefixRows } from "../../services/bgp-prefix-model.js"
import { BgpRibChanged, bgpRibSelection, readBgpRib } from "../../services/bgp-rib-observation.js"
import { nativeBgpRows } from "../../services/bgp-export-model.js"
import { getServerRowById } from "../servers/repository/servers-repository.js"
import { routerClient } from "./resources.js"
import { effectiveMcpConnection } from "./store.js"
import { createRoutingSourceContext, readRoutingEndpoints } from "./routing-observation-source.js"
import { fingerprint, McpError } from "./security.js"
import type { ActionContext } from "./action-types.js"
import type { add } from "./actions.js"
@@ -17,6 +19,27 @@ async function access(context: ActionContext) {
if (fingerprint(current.policy) !== fingerprint(context.connection.policy)) throw new McpError("RESET_REQUIRED", "Область чтения BGP изменилась", 409)
}
export function registerBgpPrefixActions(register: typeof add) {
const observation = bgpRibSelection.extend({ serverId: z.number().int().positive().safe() })
register("routing.bgp.rib.read", "mm_bgp_rib_get", "Нативная IPv4 BGP RIB по таблице: count-only или страницы всех путей, включая filtered. В следующих страницах передавайте expectedFingerprint первой страницы", "bgp", permissions, "read", "servers", observation, { read: async (input, context) => {
const { serverId, ...selection } = observation.parse(input)
await access(context)
const source = await createRoutingSourceContext(await readRoutingEndpoints([serverId]))
if (source.expected.length !== 1) throw new McpError("DEVICE_UNAVAILABLE", "Источник RIB недоступен", 409)
const check = async () => { await access(context); await source.assertCurrent() }
try {
await check()
const { client } = await routerClient(serverId)
const startedAt = new Date().toISOString()
const result = await readBgpRib(client, selection, check, context.signal)
await check()
return { serverId, ...result, startedAt, observedAt: new Date().toISOString(), timestampKind: "backend-receipt", forwardingVerified: false }
} catch (error) {
await check()
if (error instanceof McpError) throw error
if (error instanceof BgpRibChanged) throw new McpError("STATE_CONFLICT", "Состояние RIB изменилось; повторите чтение с первой страницы", 409)
throw new McpError("STATE_UNAVAILABLE", "Полнота нативного чтения IPv4 BGP RIB не подтверждена", 409)
}
} })
register("routing.bgp.prefixes.read", "mm_bgp_prefixes_get", "Наблюдаемые BGP-префиксы IPv4/IPv6 в явной таблице; active nullable, без доказательства forwarding или attribution к peer", "bgp", permissions, "read", "servers", z.object({
serverId: z.number().int().positive().safe(), family: z.enum(["ipv4", "ipv6"]).default("ipv4"),
table: z.string().trim().min(1).max(100).refine(value => !/[\u0000-\u001f\u007f]/.test(value)).default("main"),