mcp dns queries MCNS via an agent to list all zones and DNS records. mcp node routes queries mc-proxy on each node for listener/route status, matching the mcproxyctl status output format. New agent RPCs: ListDNSRecords, ListProxyRoutes. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
41 lines
981 B
Go
41 lines
981 B
Go
package agent
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
mcpv1 "git.wntrmute.dev/mc/mcp/gen/mcp/v1"
|
|
)
|
|
|
|
// ListDNSRecords queries MCNS for all zones and their records.
|
|
func (a *Agent) ListDNSRecords(ctx context.Context, _ *mcpv1.ListDNSRecordsRequest) (*mcpv1.ListDNSRecordsResponse, error) {
|
|
a.Logger.Debug("ListDNSRecords called")
|
|
|
|
zones, err := a.DNS.ListZones(ctx)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("list zones: %w", err)
|
|
}
|
|
|
|
resp := &mcpv1.ListDNSRecordsResponse{}
|
|
for _, z := range zones {
|
|
records, err := a.DNS.ListZoneRecords(ctx, z.Name)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("list records for zone %q: %w", z.Name, err)
|
|
}
|
|
|
|
zone := &mcpv1.DNSZone{Name: z.Name}
|
|
for _, r := range records {
|
|
zone.Records = append(zone.Records, &mcpv1.DNSRecord{
|
|
Id: int64(r.ID),
|
|
Name: r.Name,
|
|
Type: r.Type,
|
|
Value: r.Value,
|
|
Ttl: int32(r.TTL), //nolint:gosec // TTL is bounded
|
|
})
|
|
}
|
|
resp.Zones = append(resp.Zones, zone)
|
|
}
|
|
|
|
return resp, nil
|
|
}
|