Skip to main content
Glama
jsebgiraldo

OpenWRT SSH MCP Server

by jsebgiraldo

openwrt_list_dhcp_leases

List all DHCP leases to view connected devices with their IP and MAC addresses on an OpenWRT router.

Instructions

List all DHCP leases (connected devices with IP/MAC addresses)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The main handler function that executes the DHCP leases listing. It tries two possible lease file locations (/tmp/dhcp.leases and /var/dhcp.leases), parses the output, and returns a structured list of leases with timestamp, MAC, IP, hostname, and client_id for each device.
    @staticmethod
    async def list_dhcp_leases() -> dict[str, Any]:
        """
        List DHCP leases (connected devices).
        
        Returns:
            dict: DHCP leases information
        """
        # Try both possible locations for DHCP leases file
        commands = [
            "cat /tmp/dhcp.leases",
            "cat /var/dhcp.leases",
        ]
    
        for cmd in commands:
            result = await OpenWRTTools.execute_command(cmd)
            if result["success"] and result["output"]:
                # Parse DHCP leases
                leases = []
                for line in result["output"].strip().split("\n"):
                    if line:
                        parts = line.split()
                        if len(parts) >= 4:
                            leases.append({
                                "timestamp": parts[0],
                                "mac": parts[1],
                                "ip": parts[2],
                                "hostname": parts[3] if len(parts) > 3 else "",
                                "client_id": parts[4] if len(parts) > 4 else "",
                            })
    
                return {
                    "success": True,
                    "leases": leases,
                    "count": len(leases),
                }
    
        return {
            "success": False,
            "error": "Could not read DHCP leases file",
        }
  • Tool schema definition in the list_tools() function. Defines the tool name, description, and input schema (empty object with no required parameters).
    Tool(
        name="openwrt_list_dhcp_leases",
        description="List all DHCP leases (connected devices with IP/MAC addresses)",
        inputSchema={
            "type": "object",
            "properties": {},
            "required": [],
        },
    ),
  • Tool routing in the call_tool() function that maps the tool name 'openwrt_list_dhcp_leases' to its handler implementation OpenWRTTools.list_dhcp_leases().
    elif name == "openwrt_list_dhcp_leases":
        result = await OpenWRTTools.list_dhcp_leases()

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/jsebgiraldo/openwrt_ssh_mcp'

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