Skip to main content
Glama
coreyhines

coreyhines/opnsense-mcp

interface_list

Retrieve available network interface names for OPNsense firewall rule configuration, enabling dynamic policy updates.

Instructions

Get available interface names for firewall rules

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • InterfaceListTool class with execute() method that fetches interface names from OPNsense API (/api/interfaces/overview/export), supplements with ARP/NDP data, and optionally resolves logical interface names (e.g., 'WAN') to device names.
    class InterfaceListTool:
        """Tool for getting available firewall interface names."""
    
        def __init__(self, client: OPNsenseClient | None) -> None:
            """
            Initialize the interface list tool.
    
            Args:
                client: OPNsense client instance for API communication.
    
            """
            self.client = client
    
        async def resolve_logical_name(
            self, logical_name: str, interfaces: dict
        ) -> str | None:
            """
            Resolve a logical interface name (e.g., 'WAN') to the real device name (e.g., 'ax1').
            Matches against 'identifier' and 'description' fields (case-insensitive), preferring enabled interfaces.
            Returns the device name or None if not found.
            """
            import logging
    
            logical_lc = logical_name.lower()
            logger = logging.getLogger(__name__)
            debug_lines = []
            debug_lines.append(
                f"[DEBUG] Resolving logical name '{logical_name}' (lower: '{logical_lc}') against interfaces:"
            )
            for k, v in interfaces.items():
                debug_lines.append(
                    f"[DEBUG] Interface key: {k}, identifier: {v.get('identifier')}, description: {v.get('description')}, enabled: {v.get('enabled')}, device: {v.get('device')}, name: {v.get('name')}"
                )
            logger.debug("\n".join(debug_lines))
            # Prefer enabled interfaces
            candidates = [v for v in interfaces.values() if v.get("enabled")]
            # Match identifier
            for iface in candidates:
                if iface.get("identifier", "").lower() == logical_lc:
                    logger.debug("Matched by identifier: %s", iface)
                    return iface.get("device") or iface.get("name")
            # Match description
            for iface in candidates:
                if iface.get("description", "").lower() == logical_lc:
                    logger.debug("Matched by description: %s", iface)
                    return iface.get("device") or iface.get("name")
            # Fallback: match in all interfaces
            for iface in interfaces.values():
                if iface.get("identifier", "").lower() == logical_lc:
                    logger.debug("Fallback matched by identifier: %s", iface)
                    return iface.get("device") or iface.get("name")
                if iface.get("description", "").lower() == logical_lc:
                    logger.debug("Fallback matched by description: %s", iface)
                    return iface.get("device") or iface.get("name")
            logger.debug("No match found for logical name '%s'", logical_name)
            return None
    
        async def execute(self, params: dict[str, Any] | None = None) -> dict[str, Any]:
            """
            Get available interface names for firewall rules.
    
            Args:
                params: Optional execution parameters. If 'resolve' is set, resolve that logical name.
    
            Returns:
                Dictionary containing interface names and descriptions, and resolved device if requested.
    
            Note:
                Uses /api/interfaces/overview/export as the primary source. See issue #2 for long-term refactor plan.
    
            """
            import json
            import os
    
            try:
                if not self.client:
                    return {
                        "interfaces": {},
                        "status": "error",
                        "error": "No client available",
                    }
                merged = {}
                try:
                    aliases_raw = await self.client._make_request(
                        "GET", "/api/interfaces/overview/export"
                    )
                    if isinstance(aliases_raw, list):
                        # If the API returns a list, convert to dict by device or identifier
                        for entry in aliases_raw:
                            key = (
                                entry.get("device")
                                or entry.get("identifier")
                                or entry.get("name")
                            )
                            if key:
                                merged[key] = entry
                    elif isinstance(aliases_raw, dict):
                        for key, value in aliases_raw.items():
                            merged[key] = value
                except Exception as e:
                    logger.error(f"Failed to fetch /api/interfaces/overview/export: {e}")
                # Optionally supplement with ARP/NDP
                try:
                    interfaces = await self.client.get_interfaces()
                    for entry in interfaces:
                        if entry.get("name") and entry["name"] not in merged:
                            merged[entry["name"]] = entry
                except Exception as e:
                    logger.warning(f"Failed to supplement with ARP/NDP: {e}")
                if not merged:
                    # Fallback to mock data
                    mock_path = os.path.join(
                        os.path.dirname(__file__),
                        "../../examples/mock_data/interfaces.json",
                    )
                    try:
                        with open(os.path.abspath(mock_path)) as f:
                            data = json.load(f)
                            merged = {
                                e.get("name", ""): e for e in data.get("interfaces", [])
                            }
                    except Exception as e:
                        logger.error(f"Failed to load mock data: {e}")
                        merged = {}
                result = {
                    "interfaces": merged,
                    "total": len(merged),
                    "status": "success" if merged else "error",
                    "error": None if merged else "No interfaces found",
                }
                # If 'resolve' param is set, resolve logical name
                if params and "resolve" in params:
                    resolved = await self.resolve_logical_name(params["resolve"], merged)
                    result["resolved_device"] = resolved
                return result
            except Exception as e:
                logger.exception("Failed to get interface list")
                return {"interfaces": {}, "status": "error", "error": str(e)}
  • MCP tool schema registration for 'interface_list' - defines name, description ('Get available interface names for firewall rules'), and empty inputSchema (no required params, though 'resolve' can be passed).
    {
        "name": "interface_list",
        "description": "Get available interface names for firewall rules",
        "inputSchema": {
            "type": "object",
            "properties": {},
            "required": [],
        },
    },
  • Tool schema registration in the tools list returned by MCP 'tools/list' method.
    {
        "name": "interface_list",
        "description": "Get available interface names for firewall rules",
        "inputSchema": {
            "type": "object",
            "properties": {},
            "required": [],
        },
    },
  • Routing of 'interface_list' tool call to interface_list_tool.execute(arguments) in handle_message().
    if tool_name == "interface_list":
        result = await interface_list_tool.execute(arguments)
        return {
            "jsonrpc": "2.0",
            "id": msg_id,
            "result": {"content": [{"type": "text", "text": str(result)}]},
        }
  • Tool registry mapping 'interface_list' to InterfaceListTool class in TOOL_CLASSES dict.
    "interface": InterfaceTool,
    "interface_list": InterfaceListTool,
    "firewall": FirewallTool,
Behavior4/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It clearly indicates a read-only operation ('Get'), which is sufficient for a zero-parameter list tool. No additional behavioral traits (e.g., caching, ordering) are mentioned, but the tool's simplicity makes this adequate.

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, concise sentence that front-loads the verb and resource. It contains no unnecessary words or redundancy, making it efficient and easy to parse.

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

Completeness4/5

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

Given the tool's simplicity (no parameters, no output schema), the description is largely complete. It explains the tool's purpose and context ('for firewall rules'), though it could optionally specify whether the list is exhaustive or filtered. Overall, it provides enough context for basic understanding.

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 has no parameters, and the description does not add any parameter-related information. Since schema coverage is 100% (no parameters to describe), baseline is 3. The tool's simplicity means no additional parameter semantics are needed.

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 that the tool retrieves interface names specifically for firewall rules, using a specific verb ('Get') and resource ('interface names'). It distinguishes itself from sibling tools like fw_rules or set_fw_rule by focusing on listing available interfaces rather than managing rules.

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

Usage Guidelines2/5

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

The description does not provide any guidance on when to use this tool versus alternatives. While the context 'for firewall rules' hints at a use case, there is no explicit mention of prerequisites, context of use, or when not to use it.

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/coreyhines/opnsense-mcp'

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