lldp
Retrieve the LLDP neighbor table to identify directly connected devices and their network details.
Instructions
Show LLDP neighbor table
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- opnsense_mcp/tools/lldp.py:26-66 (handler)LLDPTool class with execute() method that calls client.get_lldp_table() and returns neighbor data.
class LLDPTool: """Tool for retrieving LLDP neighbor table information.""" name = "lldp" description = "Show LLDP neighbor table" input_schema = {"type": "object", "properties": {}, "required": []} def __init__(self, client: OPNsenseClient | None) -> None: """ Initialize the LLDP tool. Args: client: OPNsense client instance for API communication. """ self.client = client async def execute(self, params: dict[str, Any]) -> dict[str, Any]: """ Execute LLDP neighbor table lookup. Args: params: Execution parameters (unused for LLDP). Returns: Dictionary containing LLDP neighbor results. """ try: if not self.client: return { "neighbors": [], "status": "error", "error": "No client available", } neighbors = await self.client.get_lldp_table() return {"neighbors": neighbors, "status": "success"} except Exception as e: logger.exception("Failed to get LLDP neighbors") return {"neighbors": [], "status": "error", "error": str(e)} - opnsense_mcp/tools/lldp.py:13-23 (schema)Pydantic model defining the schema for LLDP neighbor entries.
class LLDPEntry(BaseModel): """Model for LLDP neighbor table entries.""" intf: str chassis_id: str port_id: str port_descr: str | None = None sys_name: str | None = None sys_descr: str | None = None sys_cap: str | None = None mgmt_ip: str | None = None - opnsense_mcp/tools/__init__.py:18-25 (registration)Tool registry mapping the name 'lldp' to LLDPTool class.
TOOL_CLASSES = { "arp": ARPTool, "system": SystemTool, "dhcp": DHCPTool, "dhcp_lease_delete": DHCPLeaseDeleteTool, "lldp": LLDPTool, "interface": InterfaceTool, "interface_list": InterfaceListTool, - opnsense_mcp/server.py:328-330 (registration)Server-side tool definition with name and description for the MCP protocol.
"name": "lldp", "description": "Show LLDP neighbor table", "inputSchema": { - opnsense_mcp/utils/api.py:1171-1209 (helper)API helper method that fetches and parses the LLDP neighbor table from the OPNsense LLDPd plugin endpoint at /api/lldpd/service/neighbor.
async def get_lldp_table(self: "OPNsenseClient") -> list[dict[str, str]]: """Get LLDP neighbor table from the LLDPd plugin endpoint and parse it.""" try: response = await self._make_request("GET", "/api/lldpd/service/neighbor") text = response.get("response", "") neighbors = [] current = {} for line in text.splitlines(): line = line.strip() if line.startswith("Interface:"): if current: neighbors.append(current) current = {} current["intf"] = line.split(":", 1)[1].split(",")[0].strip() elif line.startswith("ChassisID:"): current["chassis_id"] = line.split(":", 1)[1].strip() elif line.startswith("SysName:"): current["system_name"] = line.split(":", 1)[1].strip() elif line.startswith("SysDescr:"): current["system_description"] = line.split(":", 1)[1].strip() elif line.startswith("MgmtIP:"): current["management_address"] = line.split(":", 1)[1].strip() elif line.startswith("PortID:"): current["port_id"] = line.split(":", 1)[1].strip() elif line.startswith("PortDescr:"): current["port_description"] = line.split(":", 1)[1].strip() elif line.startswith("Capability:"): cap = line.split(":", 1)[1].strip() if "capabilities" in current: current["capabilities"] += ", " + cap else: current["capabilities"] = cap if current: neighbors.append(current) except Exception: logger.exception("Failed to get LLDP table") return [] else: return neighbors