opnsense_dhcp_list_leases
Retrieve a list of active DHCPv4 leases from OPNsense. Automatically detects and supports both Kea and ISC DHCP backends for compatibility.
Instructions
List all current DHCPv4 leases. Supports both Kea DHCP (default on modern OPNsense) and ISC DHCP (legacy) backends — auto-detects which is active.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/dhcp.ts:432-445 (handler)Handler for opnsense_dhcp_list_leases - tries Kea DHCP leases endpoint first, falls back to ISC DHCP if Kea is unavailable.
case "opnsense_dhcp_list_leases": { // Try Kea first (the modern OPNsense default). If Kea endpoint 404s // (plugin not installed) fall back to ISC dhcpd. This matches the // backend-detection pattern used for static reservations and fixes // #131 — without this, Kea-backed installs returned empty arrays // even when active leases were visible in the OPNsense UI. try { const result = await keaListLeases(client); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; } catch { const result = await iscListLeases(client); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; } } - src/tools/dhcp.ts:367-369 (helper)Helper that calls Kea DHCP leases API endpoint at /kea/leases4/search
async function keaListLeases(client: OPNsenseClient): Promise<unknown> { return await client.get("/kea/leases4/search"); } - src/tools/dhcp.ts:381-383 (helper)Helper that calls ISC DHCP (legacy) leases API endpoint at /dhcpv4/leases/searchLease
async function iscListLeases(client: OPNsenseClient): Promise<unknown> { return await client.get("/dhcpv4/leases/searchLease"); } - src/tools/dhcp.ts:79-84 (registration)Tool definition/registration for opnsense_dhcp_list_leases with no input parameters
{ name: "opnsense_dhcp_list_leases", description: "List all current DHCPv4 leases. Supports both Kea DHCP (default on modern OPNsense) and ISC DHCP (legacy) backends — auto-detects which is active.", inputSchema: { type: "object" as const, properties: {} }, }, - src/index.ts:63-63 (registration)Maps the dhcpToolDefinitions (including opnsense_dhcp_list_leases) to the handleDhcpTool handler in the server registration
for (const def of dhcpToolDefinitions) toolHandlers.set(def.name, handleDhcpTool);