Skip to main content
Glama

get_os_details

Retrieve operating system details from remote servers to monitor system information and configuration for server management tasks.

Instructions

获取操作系统详细信息

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
hostnameYes
usernameYes
passwordNo
portNo
timeoutNo

Implementation Reference

  • Primary handler implementation for the 'get_os_details' tool. Uses SSH to fetch and parse comprehensive OS information including distro, version, kernel, architecture, uptime, boot time, and virtualization detection.
    def get_os_details( hostname: str, username: str, password: str = "", port: int = 22, timeout: int = 30 ) -> dict: """获取操作系统详细信息""" result = {"status": "unknown", "os_info": {}, "error": ""} try: with SSHManager(hostname, username, password, port, timeout) as ssh: # 收集各种系统信息 commands = { "hostname": "hostname", "os_release": "cat /etc/os-release || cat /etc/redhat-release || cat /etc/debian_version || uname -a", "kernel": "uname -r", "architecture": "uname -m", "uptime": "uptime -p", "last_boot": "who -b" } os_info = {} for key, command in commands.items(): stdin, stdout, stderr = ssh.exec_command(command, timeout=timeout) output = stdout.read().decode().strip() os_info[key] = output # 解析OS分发版和版本 distro = "Unknown" version = "Unknown" if "NAME=" in os_info["os_release"]: distro_match = re.search(r'NAME="?(.*?)"?', os_info["os_release"], re.MULTILINE) if distro_match: distro = distro_match.group(1) version_match = re.search(r'VERSION="?(.*?)"?', os_info["os_release"], re.MULTILINE) if version_match: version = version_match.group(1) else: version_id_match = re.search(r'VERSION_ID="?(.*?)"?', os_info["os_release"], re.MULTILINE) if version_id_match: version = version_id_match.group(1) os_info["distro"] = distro os_info["version"] = version # 检查是否为虚拟机 vm_check_command = "systemd-detect-virt || dmesg | grep -i virtual || dmidecode | grep -i vmware || dmidecode | grep -i virtualbox || echo 'Unknown'" stdin, stdout, stderr = ssh.exec_command(vm_check_command, timeout=timeout) vm_output = stdout.read().decode().strip() os_info["virtualization"] = "Unknown" if vm_output != "Unknown": for vm_type in ["kvm", "vmware", "virtualbox", "xen", "docker", "lxc", "openvz", "parallels"]: if vm_type.lower() in vm_output.lower(): os_info["virtualization"] = vm_type break result["os_info"] = os_info result["status"] = "success" except Exception as e: result["status"] = "error" result["error"] = str(e) return result
  • Simplified handler for 'get_os_details' in the SSE variant. Collects raw outputs from OS info commands via SSH without additional parsing.
    def get_os_details( hostname: str, username: str, password: str = "", port: int = 22, timeout: int = 30 ) -> dict: """获取操作系统详细信息""" result = {"status": "unknown", "os_info": {}, "error": ""} try: with SSHManager(hostname, username, password, port, timeout) as ssh: # 收集各种系统信息 commands = { "hostname": "hostname", "os_release": "cat /etc/os-release || cat /etc/redhat-release || cat /etc/debian_version || uname -a", "kernel": "uname -r", "architecture": "uname -m", "uptime": "uptime -p", "last_boot": "who -b" } os_info = {} for key, command in commands.items(): stdin, stdout, stderr = ssh.exec_command(command, timeout=timeout) output = stdout.read().decode().strip() os_info[key] = output result["os_info"] = os_info result["status"] = "success" except Exception as e: result["status"] = "error" result["error"] = str(e) return result
  • Tool registration block in main.py where get_os_details is included in the tools_dict and registered to the MCP instance using 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) # 特殊处理list_available_tools,因为它需要mcp实例 @mcp.tool() def _list_available_tools(): return list_available_tools(mcp) return mcp
  • Parameter schema definition for the get_os_details tool used in tool descriptions or validation.
    {"name": "get_os_details", "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} ]}

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