24 lines
1.8 KiB
TypeScript
24 lines
1.8 KiB
TypeScript
import { hasPermission } from "../../lib/permissions.js"
|
|
import { resolveHostsSchema, resolveNetworkHosts } from "../../services/network-host-resolution.js"
|
|
import { fingerprint, McpError } from "./security.js"
|
|
import { effectiveMcpConnection } from "./store.js"
|
|
import type { add } from "./actions.js"
|
|
|
|
export function registerNetworkHostActions(register: typeof add) {
|
|
// Match the existing POST /api/network/resolve-hosts permission boundary.
|
|
// Observer mode still prevents configuration writes using this grant.
|
|
register("network.hosts.resolve", "mm_network_hosts_resolve", "IPv4-резолв hostname системным resolver хоста менеджера", "network", "mm:network:write", "read", "global", resolveHostsSchema, {
|
|
read: async (input, context) => {
|
|
const assertReadable = async () => {
|
|
if (context.signal?.aborted) throw new McpError("READ_CANCELLED", "Резолв отменён", 409)
|
|
const current = await effectiveMcpConnection(context.principal)
|
|
if (!hasPermission(current.owner_permissions, "mm:network:write") || !hasPermission(current.policy.permissions, "mm:network:write")) throw new McpError("PERMISSION_DENIED", "Право сетевой диагностики отозвано", 403)
|
|
if (fingerprint(current.policy) !== fingerprint(context.connection.policy)) throw new McpError("RESET_REQUIRED", "Область сетевой диагностики изменилась", 409)
|
|
}
|
|
await assertReadable()
|
|
try { return await resolveNetworkHosts(input, { signal: context.signal, assertReadable }) }
|
|
catch (error) { await assertReadable(); if (error instanceof McpError) throw error; throw new McpError("STATE_UNAVAILABLE", "Резолв не подтверждён", 409) }
|
|
},
|
|
})
|
|
}
|