|
| 1 | += Hesiod DNS Lookup Cartridge |
| 2 | +:toc: preamble |
| 3 | +:author: Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk> |
| 4 | +:date: 2026-04-25 |
| 5 | +:spdx: PMPL-1.0-or-later |
| 6 | + |
| 7 | +// SPDX-License-Identifier: PMPL-1.0-or-later |
| 8 | + |
| 9 | +DNS record lookup and reverse DNS resolution exposed as MCP tools. |
| 10 | + |
| 11 | +== Features |
| 12 | + |
| 13 | +- **DNS Lookups** — Query A, AAAA, CNAME, MX, NS, SOA, TXT, SRV records |
| 14 | +- **Reverse DNS** — Resolve IP addresses to hostnames |
| 15 | +- **Bulk Queries** — Efficient batch lookups for multiple domains |
| 16 | +- **Type Safety** — Idris2 ABI ensures only valid record types are queried |
| 17 | +- **Proof Pinning** — Loopback invariant: `IsLoopback 5173` at compile-time |
| 18 | + |
| 19 | +== Architecture |
| 20 | + |
| 21 | +[cols="1,3"] |
| 22 | +|=== |
| 23 | +| Component | Purpose |
| 24 | + |
| 25 | +| `abi/Hesiod.idr` |
| 26 | +| Idris2 interface with proof-indexed record types and loopback pinning. |
| 27 | + Ensures at compile-time that only queryable types are passed to FFI. |
| 28 | + |
| 29 | +| `ffi/hesiod_ffi.zig` |
| 30 | +| C-compatible Zig bindings calling system DNS resolver (`libresolv`, `getaddrinfo`). |
| 31 | + Five exported functions: `lookup`, `reverse_lookup`, `bulk_lookup`, `validate_hostname`, `error_message`. |
| 32 | + |
| 33 | +| `adapter/mod.ts` |
| 34 | +| Deno TypeScript bridge. Implements MCP server interface, validates input, calls Zig FFI. |
| 35 | + Runs on `127.0.0.1:5173` (loopback only, per Idris2 proof). |
| 36 | + |
| 37 | +| `mod.js` |
| 38 | +| BoJ cartridge entry point. Dispatches MCP tool calls, health checks, lifecycle hooks. |
| 39 | + |
| 40 | +| `cartridge.json` |
| 41 | +| Tool manifest defining three MCP tools: `dns_lookup`, `dns_reverse_lookup`, `dns_bulk_lookup`. |
| 42 | + Lists ABI interface, FFI exports, adapter config, loopback proof. |
| 43 | +|=== |
| 44 | + |
| 45 | +== MCP Tools |
| 46 | + |
| 47 | +=== `dns_lookup` |
| 48 | + |
| 49 | +Query DNS records for a hostname. |
| 50 | + |
| 51 | +[source,json] |
| 52 | +---- |
| 53 | +{ |
| 54 | + "hostname": "example.com", |
| 55 | + "record_type": "A", |
| 56 | + "timeout_seconds": 5 |
| 57 | +} |
| 58 | +---- |
| 59 | + |
| 60 | +Returns list of matching DNS records (name, type, TTL, value). |
| 61 | + |
| 62 | +=== `dns_reverse_lookup` |
| 63 | + |
| 64 | +Resolve an IP address to hostname(s). |
| 65 | + |
| 66 | +[source,json] |
| 67 | +---- |
| 68 | +{ |
| 69 | + "address": "93.184.216.34", |
| 70 | + "timeout_seconds": 5 |
| 71 | +} |
| 72 | +---- |
| 73 | + |
| 74 | +=== `dns_bulk_lookup` |
| 75 | + |
| 76 | +Batch query multiple hostnames with the same record type. |
| 77 | + |
| 78 | +[source,json] |
| 79 | +---- |
| 80 | +{ |
| 81 | + "hostnames": ["example.com", "example.org", "example.net"], |
| 82 | + "record_type": "A", |
| 83 | + "timeout_seconds": 5 |
| 84 | +} |
| 85 | +---- |
| 86 | + |
| 87 | +Returns results for each hostname in order. |
| 88 | + |
| 89 | +== Building |
| 90 | + |
| 91 | +[source,bash] |
| 92 | +---- |
| 93 | +# Compile Zig FFI |
| 94 | +zig build -Doptimize=ReleaseFast -Dtarget=x86_64-linux |
| 95 | +
|
| 96 | +# Run Deno adapter (development) |
| 97 | +deno run --allow-net adapter/mod.ts |
| 98 | +
|
| 99 | +# Build within BoJ (uses cartridge.json manifest) |
| 100 | +just build-cartridge hesiod-mcp |
| 101 | +---- |
| 102 | + |
| 103 | +== Type Safety |
| 104 | + |
| 105 | +All DNS record type queries are proven queryable at compile-time: |
| 106 | + |
| 107 | +[source,idris] |
| 108 | +---- |
| 109 | +lookup : {rectype : DNSRecordType} -> |
| 110 | + (hostname : String) -> |
| 111 | + Queryable rectype -> -- Proof required |
| 112 | + m LookupResult |
| 113 | +---- |
| 114 | + |
| 115 | +The Idris2 proof system prevents querying unrecognized record types. Only these are provably valid: |
| 116 | + |
| 117 | +- `A` (IPv4) |
| 118 | +- `AAAA` (IPv6) |
| 119 | +- `CNAME` (canonical name) |
| 120 | +- `MX` (mail exchange) |
| 121 | +- `NS` (name server) |
| 122 | +- `SOA` (start of authority) |
| 123 | +- `TXT` (text) |
| 124 | +- `SRV` (service) |
| 125 | + |
| 126 | +== Loopback Invariant |
| 127 | + |
| 128 | +Proof-pinned at compile-time: |
| 129 | + |
| 130 | +[source,idris] |
| 131 | +---- |
| 132 | +loopbackInvariant : IsLoopback 5173 |
| 133 | +loopbackInvariant = LoopbackProof |
| 134 | +---- |
| 135 | + |
| 136 | +The cartridge ONLY listens on `127.0.0.1:5173`. No external network exposure. |
| 137 | + |
| 138 | +== Testing |
| 139 | + |
| 140 | +[source,bash] |
| 141 | +---- |
| 142 | +# Unit tests (Zig FFI) |
| 143 | +zig test ffi/hesiod_ffi.zig |
| 144 | +
|
| 145 | +# Integration tests (MCP protocol) |
| 146 | +deno test --allow-net tests/hesiod_test.ts |
| 147 | +
|
| 148 | +# Proof verification |
| 149 | +idris2 --check abi/Hesiod.idr |
| 150 | +---- |
| 151 | + |
| 152 | +== Integration with BoJ |
| 153 | + |
| 154 | +Cartridge is loaded by BoJ's MCP dispatcher. Available as tool in Claude's context: |
| 155 | + |
| 156 | +1. BoJ calls `boj_cartridge_invoke("hesiod-mcp", tool_name, json_args, ...)` |
| 157 | +2. FFI adapter routes to Zig implementation |
| 158 | +3. Result returned as JSON |
| 159 | + |
| 160 | +== License |
| 161 | + |
| 162 | +PMPL-1.0-or-later (MPL-2.0 legal fallback). |
0 commit comments