Skip to main content
Glama
Heht571
by Heht571

inspect_network

Check network interfaces and connection status on remote servers via SSH to monitor connectivity and identify potential issues.

Instructions

检查网络接口和连接状态

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
hostnameYes
usernameYes
passwordNo
portNo
timeoutNo

Implementation Reference

  • Core handler function implementing the inspect_network tool logic: SSH to server, run 'ip a' and 'ss -tuln' to get interfaces and listening ports, ping 8.8.8.8 for internet connectivity.
    @handle_exceptions
    def inspect_network(
        hostname: str,
        username: str,
        password: str = "",
        port: int = 22,
        timeout: int = 30
    ) -> dict:
        """检查网络接口和连接状态"""
        result = {"status": "unknown", "interfaces": [], "connections": {}, "error": ""}
    
        try:
            with SSHManager(hostname, username, password, port, timeout) as ssh:
                # 获取网络接口信息
                interfaces_command = "ip a"
                stdin, stdout, stderr = ssh.exec_command(interfaces_command, timeout=timeout)
                interfaces_output = stdout.read().decode().strip()
    
                # 解析网络接口信息
                result["interfaces"] = ServerInspector.parse_network_interfaces(interfaces_output)
    
                # 获取网络连接信息
                connections_command = "ss -tuln"
                stdin, stdout, stderr = ssh.exec_command(connections_command, timeout=timeout)
                connections_output = stdout.read().decode().strip()
    
                # 解析监听端口
                listening_ports = []
                for line in connections_output.split('\n')[1:]:  # 跳过标题行
                    if "LISTEN" in line:
                        parts = line.split()
                        if len(parts) >= 5:
                            address_port = parts[4]
                            if ":" in address_port:
                                port = address_port.split(":")[-1]
                                listening_ports.append(port)
    
                result["connections"]["listening_ports"] = listening_ports
    
                # 检查是否可以连接公网
                internet_check = ssh.exec_command("ping -c 1 -W 2 8.8.8.8", timeout=timeout)
                internet_output = internet_check[1].read().decode().strip()
                result["connections"]["internet_connectivity"] = "1 received" in internet_output
    
                result["status"] = "success"
    
        except Exception as e:
            result["status"] = "error"
            result["error"] = str(e)
    
        return result
  • SSE variant of the core handler function for inspect_network tool, nearly identical to the main one.
    @handle_exceptions
    def inspect_network(
        hostname: str,
        username: str,
        password: str = "",
        port: int = 22,
        timeout: int = 30
    ) -> dict:
        """检查网络接口和连接状态"""
        result = {"status": "unknown", "interfaces": [], "connections": {}, "error": ""}
    
        try:
            with SSHManager(hostname, username, password, port, timeout) as ssh:
                # 获取网络接口信息
                interfaces_command = "ip a"
                stdin, stdout, stderr = ssh.exec_command(interfaces_command, timeout=timeout)
                interfaces_output = stdout.read().decode().strip()
    
                # 解析网络接口信息
                result["interfaces"] = ServerInspector.parse_network_interfaces(interfaces_output)
    
                # 获取网络连接信息
                connections_command = "ss -tuln"
                stdin, stdout, stderr = ssh.exec_command(connections_command, timeout=timeout)
                connections_output = stdout.read().decode().strip()
    
                # 解析监听端口
                listening_ports = []
                for line in connections_output.split('\n')[1:]:  # 跳过标题行
                    if "LISTEN" in line:
                        parts = line.split()
                        if len(parts) >= 5:
                            address_port = parts[4]
                            if ":" in address_port:
                                port = address_port.split(":")[-1]
                                listening_ports.append(port)
    
                result["connections"]["listening_ports"] = listening_ports
    
                # 检查是否可以连接公网
                internet_check = ssh.exec_command("ping -c 1 -W 2 8.8.8.8", timeout=timeout)
                internet_output = internet_check[1].read().decode().strip()
                result["connections"]["internet_connectivity"] = "1 received" in internet_output
    
                result["status"] = "success"
    
        except Exception as e:
            result["status"] = "error"
            result["error"] = str(e)
    
        return result
  • JSON schema definition for the inspect_network tool parameters used in tool listing.
    {"name": "inspect_network", "description": "检查网络接口和连接状态", "parameters": [
        {"name": "hostname", "type": "str", "default": None},
        {"name": "username", "type": "str", "default": None},
        {"name": "password", "type": "str", "default": ""},
        {"name": "port", "type": "int", "default": 22},
        {"name": "timeout", "type": "int", "default": 30}
    ]},
  • Registration of inspect_network in tools_dict and dynamic application of @mcp.tool() decorator.
    tools_dict = {
        'get_memory_info': get_memory_info,
        'remote_server_inspection': remote_server_inspection,
        'get_system_load': get_system_load,
        'monitor_processes': monitor_processes,
        'check_service_status': check_service_status,
        'get_os_details': get_os_details,
        'check_ssh_risk_logins': check_ssh_risk_logins,
        'check_firewall_config': check_firewall_config,
        'security_vulnerability_scan': security_vulnerability_scan,
        'backup_critical_files': backup_critical_files,
        'inspect_network': inspect_network,
        'analyze_logs': analyze_logs,
        'list_docker_containers': list_docker_containers,
        'list_docker_images': list_docker_images,
        'list_docker_volumes': list_docker_volumes,
        'get_container_logs': get_container_logs,
        'monitor_container_stats': monitor_container_stats,
        'check_docker_health': check_docker_health
    }
    
    # 使用装饰器动态注册所有工具
    for name, func in tools_dict.items():
        mcp.tool()(func)
  • Explicit tool dispatch block for inspect_network in SSE server handler.
    elif name == "inspect_network":
        required_args = ["hostname", "username"]
        for arg in required_args:
            if arg not in arguments:
                raise ValueError(f"Missing required argument '{arg}'")
    
        result = inspect_network(
            hostname=arguments["hostname"],
            username=arguments["username"],
            password=arguments.get("password", ""),
            port=arguments.get("port", 22),
            timeout=arguments.get("timeout", 30)
        )
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the action ('inspect') but doesn't describe what the inspection entails (e.g., returns interface details, connection metrics), whether it requires authentication (implied by parameters but not stated), or any side effects (e.g., read-only vs. disruptive). For a tool with 5 parameters and no annotation coverage, this is inadequate.

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, efficient sentence in Chinese that directly states the tool's purpose without unnecessary words. It's appropriately sized and front-loaded, with zero waste, making it easy for an agent to parse quickly.

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

Completeness2/5

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

Given the complexity (5 parameters, no annotations, no output schema) and the server's context with many sibling tools, the description is incomplete. It doesn't cover parameter meanings, usage scenarios, behavioral details, or output expectations, leaving significant gaps for the agent to operate effectively.

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

Parameters2/5

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

Schema description coverage is 0%, meaning none of the 5 parameters are documented in the schema. The description adds no information about parameters, failing to compensate for the coverage gap. It doesn't explain what 'hostname', 'username', etc., are used for (e.g., SSH connection details), leaving their semantics unclear beyond the schema's basic titles.

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

Purpose3/5

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

The description '检查网络接口和连接状态' (Inspect network interfaces and connection status) states a clear purpose with a specific verb ('inspect') and resource ('network interfaces and connection status'), but it doesn't distinguish this tool from siblings like 'remote_server_inspection' or 'check_firewall_config' that might also involve network-related operations. It avoids tautology but lacks sibling differentiation.

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 provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites, context (e.g., troubleshooting vs. monitoring), or exclusions, leaving the agent to infer usage from the tool name and parameters alone. This is a significant gap given the server has multiple inspection-related tools.

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/Heht571/ops-mcp-server'

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