opnsense_if_get
Retrieve detailed configuration of a specific OPNsense network interface, including IP addresses, status, and MTU.
Instructions
Get detailed configuration for a specific network interface (IP addresses, status, MTU, etc.)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| interface_name | Yes | Interface name (e.g. 'lan', 'wan', 'opt1') |
Implementation Reference
- src/tools/interfaces.ts:160-199 (handler)Handler function for the 'opnsense_if_get' tool. Parses args via GetInterfaceSchema, resolves the interface name (friendly or device name) using getInterfaceNames API, fetches detailed config from getInterfaceConfig API, and returns the result as JSON.
case "opnsense_if_get": { const parsed = GetInterfaceSchema.parse(args); const input = parsed.interface_name.toLowerCase(); // getInterfaceNames returns {device: friendly} e.g. {re0: "LAN", em0: "WAN"} // Resolve friendly name (e.g. "lan") to device name (e.g. "re0") const nameMap = await client.get<Record<string, string>>( "/diagnostics/interface/getInterfaceNames", ); // Search: input could be a friendly name ("lan") or device name ("re0") let deviceName = parsed.interface_name; for (const [device, friendly] of Object.entries(nameMap)) { if (friendly.toLowerCase() === input || device.toLowerCase() === input) { deviceName = device; break; } } const allInterfaces = await client.get<Record<string, unknown>>( "/diagnostics/interface/getInterfaceConfig", ); const interfaceData = allInterfaces[deviceName]; if (!interfaceData) { const available = Object.entries(nameMap) .map(([device, friendly]) => `${friendly.toLowerCase()} (${device})`) .join(", "); return { content: [ { type: "text", text: `Interface '${parsed.interface_name}' not found. Available: ${available}`, }, ], }; } return { content: [{ type: "text", text: JSON.stringify(interfaceData, null, 2) }] }; } - src/tools/interfaces.ts:9-11 (schema)Zod schema for validating the 'interface_name' input parameter (required non-empty string).
const GetInterfaceSchema = z.object({ interface_name: z.string().min(1, "Interface name is required"), }); - src/tools/interfaces.ts:47-61 (registration)Tool registration definition for 'opnsense_if_get' with name, description, and inputSchema requiring 'interface_name' string.
{ name: "opnsense_if_get", description: "Get detailed configuration for a specific network interface (IP addresses, status, MTU, etc.)", inputSchema: { type: "object" as const, properties: { interface_name: { type: "string", description: "Interface name (e.g. 'lan', 'wan', 'opt1')", }, }, required: ["interface_name"], }, }, - src/index.ts:62-62 (registration)Registration of handleInterfacesTool as the handler for all interfaces tools (including opnsense_if_get) in the toolHandlers map.
for (const def of interfacesToolDefinitions) toolHandlers.set(def.name, handleInterfacesTool); - src/client/opnsense-client.ts:28-35 (helper)The OPNsenseClient.get() method used by the handler to call the OPNsense REST API endpoints (getInterfaceNames and getInterfaceConfig).
async get<T>(path: string): Promise<T> { try { const response = await this.http.get<T>(path); return response.data; } catch (error: unknown) { throw extractError(error, `GET ${path}`); } }