Skip to main content
Glama
itunified-io

mcp-opnsense

by itunified-io

opnsense_diag_reverse_dns

Resolve any IP address to its hostname via reverse DNS lookup on the OPNsense firewall.

Instructions

Perform a reverse DNS lookup (IP to hostname) from the OPNsense firewall

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYesIP address to reverse-lookup

Implementation Reference

  • Handler case for 'opnsense_diag_reverse_dns' in the switch statement. It parses the address argument, then calls the OPNsense API endpoint /diagnostics/dns/reverse_lookup?address=... and returns the result as JSON.
    case "opnsense_diag_reverse_dns": {
      const parsed = z.object({ address: z.string().min(1) }).parse(args);
      const result = await client.get(
        `/diagnostics/dns/reverse_lookup?address=${encodeURIComponent(parsed.address)}`,
      );
      return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
    }
  • Tool definition / input schema for 'opnsense_diag_reverse_dns' registered in diagnosticsToolDefinitions. Defines the 'address' parameter as a required string for reverse DNS lookup.
    {
      name: "opnsense_diag_reverse_dns",
      description:
        "Perform a reverse DNS lookup (IP to hostname) from the OPNsense firewall",
      inputSchema: {
        type: "object" as const,
        properties: {
          address: {
            type: "string",
            description: "IP address to reverse-lookup",
          },
        },
        required: ["address"],
      },
    },
  • src/index.ts:61-61 (registration)
    Registration of diagnostics tools: maps each tool name from diagnosticsToolDefinitions to handleDiagnosticsTool handler in the toolHandlers map.
    for (const def of diagnosticsToolDefinitions) toolHandlers.set(def.name, handleDiagnosticsTool);
  • The main handler function handleDiagnosticsTool that dispatches to the switch case for reverse_dns.
    export async function handleDiagnosticsTool(
      name: string,
      args: Record<string, unknown>,
      client: OPNsenseClient,
    ): Promise<{ content: Array<{ type: "text"; text: string }> }> {
      try {
        switch (name) {
          case "opnsense_diag_arp_table": {
            const filters = ArpFilterSchema.parse(args);
            const result = await client.get<unknown>("/diagnostics/interface/getArp");
    
            // Apply client-side filtering if any filter params provided
            if (filters.ip || filters.mac || filters.interface) {
              const entries = Array.isArray(result) ? result : [];
              const filtered = entries.filter((entry: Record<string, unknown>) => {
                if (filters.ip && !String(entry["ip"] ?? "").includes(filters.ip)) return false;
                if (filters.mac && !String(entry["mac"] ?? "").toLowerCase().includes(filters.mac.toLowerCase())) return false;
                if (filters.interface && String(entry["intf"] ?? "") !== filters.interface) return false;
                return true;
              });
              return { content: [{ type: "text", text: JSON.stringify(filtered, null, 2) }] };
            }
    
            return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
          }
    
          case "opnsense_diag_routes": {
            const result = await client.get("/diagnostics/interface/getRoutes");
            return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
          }
    
          case "opnsense_diag_ping": {
            const parsed = PingSchema.parse(args);
    
            // OPNsense 24.7+: job-based ping API (set → start → poll → remove)
            const setResult = await client.post<{ uuid?: string; result?: string }>(
              "/diagnostics/ping/set",
              { ping: { settings: { hostname: parsed.address, count: String(parsed.count) } } },
            );
    
            const jobId = setResult.uuid;
            if (!jobId) {
              return { content: [{ type: "text", text: JSON.stringify(setResult, null, 2) }] };
            }
    
            await client.post(`/diagnostics/ping/start/${jobId}`);
    
            // Poll until send count reaches requested count (status stays "running" throughout)
            const maxWait = Math.max(parsed.count * 2000, 10000);
            const start = Date.now();
            let result: Record<string, unknown> | undefined;
            while (Date.now() - start < maxWait) {
              await new Promise((r) => setTimeout(r, 1500));
              const jobs = await client.get<{
                rows?: Array<Record<string, unknown>>;
              }>("/diagnostics/ping/search_jobs");
              const job = (jobs.rows ?? []).find(
                (j) => j.id === jobId || j.uuid === jobId,
              );
              if (job && Number(job.send ?? 0) >= parsed.count) {
                result = job;
                break;
              }
            }
    
            // Cleanup
            try {
              await client.post(`/diagnostics/ping/remove/${jobId}`);
            } catch {
              // Best-effort cleanup
            }
    
            if (!result) {
              return { content: [{ type: "text", text: "Ping timed out waiting for results" }] };
            }
    
            // Format clean output
            const output = {
              host: result.hostname,
              packets_sent: result.send,
              packets_received: result.received,
              packet_loss: result.loss,
              rtt_min_ms: result.min,
              rtt_avg_ms: result.avg,
              rtt_max_ms: result.max,
              rtt_stddev_ms: result["std-dev"],
            };
            return { content: [{ type: "text", text: JSON.stringify(output, null, 2) }] };
          }
    
          case "opnsense_diag_traceroute": {
            const parsed = TracerouteSchema.parse(args);
    
            // OPNsense 24.7+: set is synchronous — executes traceroute and returns results
            const result = await client.post("/diagnostics/traceroute/set", {
              traceroute: {
                settings: {
                  hostname: parsed.address,
                },
              },
            });
    
            return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
          }
    
          case "opnsense_diag_dns_lookup": {
            const parsed = DnsLookupSchema.parse(args);
    
            // OPNsense 24.7+: use reverse_lookup for IP→hostname resolution
            // Forward lookup (hostname→IP) is not available via API in 24.7
            const result = await client.get(
              `/diagnostics/dns/reverse_lookup?address=${encodeURIComponent(parsed.hostname)}`,
            );
            return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
          }
    
          case "opnsense_diag_reverse_dns": {
            const parsed = z.object({ address: z.string().min(1) }).parse(args);
            const result = await client.get(
              `/diagnostics/dns/reverse_lookup?address=${encodeURIComponent(parsed.address)}`,
            );
            return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
          }
    
          case "opnsense_diag_fw_states": {
            const result = await client.post("/diagnostics/firewall/query_states");
            return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
          }
    
          case "opnsense_diag_fw_logs": {
            const parsed = FwLogsSchema.parse(args);
            const result = await client.get(
              `/diagnostics/firewall/log?limit=${parsed.limit}`,
            );
            return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
          }
    
          case "opnsense_diag_system_info": {
            const result = await client.get("/core/system/status");
            return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
          }
    
          case "opnsense_diag_log_system": {
            const parsed = LogQuerySchema.parse(args);
            const result = await fetchLogWithFallback(client, "system", parsed.limit);
            return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
          }
    
          case "opnsense_diag_log_gateways": {
            const parsed = LogQuerySchema.parse(args);
            const result = await fetchLogWithFallback(client, "gateways", parsed.limit);
            return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
          }
    
          case "opnsense_diag_log_routing": {
            const parsed = LogQuerySchema.parse(args);
            const result = await fetchLogWithFallback(client, "routing", parsed.limit);
            return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
          }
    
          case "opnsense_diag_log_resolver": {
            const parsed = LogQuerySchema.parse(args);
            const result = await fetchLogWithFallback(client, "resolver", parsed.limit);
            return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
          }
    
          default:
            return {
              content: [{ type: "text", text: `Unknown diagnostics tool: ${name}` }],
            };
        }
      } catch (error: unknown) {
        const message = error instanceof Error ? error.message : "Unknown error";
        return {
          content: [{ type: "text", text: `Error executing ${name}: ${message}` }],
        };
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description must fully disclose behavioral traits. It only states the action without mentioning error handling, timeout, network dependencies, or what the response contains. This lack of detail limits transparency for the agent.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single sentence of 11 words, efficiently conveying the tool's purpose without redundancy. It is front-loaded and uses clear language, earning its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple one-parameter tool with no output schema, the description adequately explains the function but lacks details on return value format, potential failures, or prerequisites. This incomplete context may hinder full autonomous usage.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema already describes the 'address' parameter with 100% coverage. The description reinforces that the address is an IP for reverse lookup, adding no new semantic information beyond the schema. Baseline 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool performs a reverse DNS lookup (IP to hostname) from the OPNsense firewall. The verb 'Perform' and the specific resource 'OPNsense firewall' clarify the action. The sibling 'opnsense_diag_dns_lookup' is for forward lookup, so this description effectively distinguishes the tool's purpose.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for reverse DNS lookup but does not explicitly state when to use this tool over alternatives like 'opnsense_diag_dns_lookup' (forward lookup) or other diagnostic tools. There is no guidance on conditions or exclusions, leaving the agent to infer from the name.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/itunified-io/mcp-opnsense'

If you have feedback or need assistance with the MCP directory API, please join our Discord server