Skip to main content
Glama

os_detect

Identify the operating system and environment details on remote servers via SSH to enable appropriate automation and configuration.

Instructions

Detects operating system and environment information

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sessionIdYesSSH session ID

Implementation Reference

  • The handler for 'os_detect' in mcp.ts calls sessionManager.getOSInfo.
    case 'os_detect': {
      const { sessionId } = SessionIdSchema.parse(args);
      const result = await sessionManager.getOSInfo(sessionId);
      logger.info('OS detected', { sessionId });
      return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
    }
  • The sessionManager.getOSInfo method retrieves or performs OS detection.
    async getOSInfo(sessionId: string): Promise<OSInfo> {
      const session = this.getSession(sessionId);
      if (!session) {
        throw new Error(`Session ${sessionId} not found or expired`);
      }
    
      if (session.osInfo) {
        return session.osInfo;
      }
    
      const osInfo = await detectOS(session.ssh);
      session.osInfo = osInfo;
      return osInfo;
    }
  • The detectOS function in detect.ts contains the actual logic for OS detection on the remote server.
    export async function detectOS(ssh: NodeSSH): Promise<OSInfo> {
      logger.debug('Starting OS detection');
      
      try {
        // Detect architecture
        const archResult = await safeExec(ssh, 'uname -m');
        let arch = archResult.stdout.trim();
        if (!arch) {
          const winArch = await safeExec(ssh, 'powershell -NoLogo -NoProfile -Command "$env:PROCESSOR_ARCHITECTURE"');
          arch = winArch.stdout.trim();
        }
        if (!arch) {
          arch = 'unknown';
        }
    
        // Detect platform/kernel
        let platform: Platform = 'unknown';
        let distro = 'unknown';
        let version = 'unknown';
        let defaultShell: ShellType = 'unknown';
        let tempDir: string | undefined;
    
        const unameResult = await safeExec(ssh, 'uname -s');
        const uname = unameResult.stdout.trim().toLowerCase();
    
        if (uname.includes('linux')) {
          platform = 'linux';
        } else if (uname.includes('darwin')) {
          platform = 'darwin';
        } else if (uname.includes('windows')) {
          platform = 'windows';
        }
    
        // Windows fallback detection (when uname is not available)
        if (platform === 'unknown') {
          const winCheck = await safeExec(ssh, 'cmd /c ver');
          if (winCheck.code === 0 && winCheck.stdout) {
            platform = 'windows';
            version = winCheck.stdout.trim();
          }
        }
    
        // macOS detection fallback
        if (platform === 'unknown') {
          const macCheck = await safeExec(ssh, 'sw_vers -productName');
          if (macCheck.code === 0 && macCheck.stdout.toLowerCase().includes('mac')) {
            platform = 'darwin';
          }
        }
    
        // Detect shell
        if (platform === 'windows') {
          defaultShell = 'powershell';
          const psShell = await safeExec(ssh, 'echo $env:SHELL');
          const shell = psShell.stdout.trim();
          tempDir = normalizeWindowsPath((await safeExec(ssh, 'powershell -NoLogo -NoProfile -Command "$env:TEMP"')).stdout.trim()) || 'C:/Windows/Temp';
    
          let packageManager: PackageManager = 'unknown';
          const wingetCheck = await safeExec(ssh, 'powershell -NoLogo -NoProfile -Command "Get-Command winget -ErrorAction SilentlyContinue"');
          if (wingetCheck.code === 0 && wingetCheck.stdout.toLowerCase().includes('winget')) {
            packageManager = 'winget';
          } else {
            const chocoCheck = await safeExec(ssh, 'choco -v');
            if (chocoCheck.code === 0) {
              packageManager = 'choco';
            }
          }
    
          const osInfo: OSInfo = {
            platform,
            distro: 'windows',
            version,
            arch,
            shell: shell || 'powershell',
            packageManager,
            init: 'windows-service',
            defaultShell,
            tempDir
          };
    
          logger.debug('OS detection completed', osInfo);
          return osInfo;
        }
    
        const shellResult = await safeExec(ssh, 'echo $SHELL');
        const shell = shellResult.stdout.trim().split('/').pop() || 'unknown';
    
        // Linux distro detection
        if (platform === 'linux') {
          const detectionCommands = [
            'cat /etc/os-release',
            'cat /etc/lsb-release',
            'cat /etc/redhat-release',
            'cat /etc/debian_version'
          ];
    
          for (const cmd of detectionCommands) {
            const result = await safeExec(ssh, cmd);
            if (result.code !== 0 || !result.stdout.trim()) {
              continue;
            }
    
            const output = result.stdout.toLowerCase();
    
            if (cmd === 'cat /etc/os-release') {
              const lines = result.stdout.split('\n');
              for (const line of lines) {
                if (line.startsWith('ID=')) {
                  distro = line.split('=')[1].replace(/\"/g, '').trim();
                }
                if (line.startsWith('VERSION_ID=')) {
                  version = line.split('=')[1].replace(/\"/g, '').trim();
                }
              }
              break;
            } else if (cmd === 'cat /etc/lsb-release') {
              const lines = result.stdout.split('\n');
              for (const line of lines) {
                if (line.startsWith('DISTRIB_ID=')) {
                  distro = line.split('=')[1].replace(/\"/g, '').trim().toLowerCase();
                }
                if (line.startsWith('DISTRIB_RELEASE=')) {
                  version = line.split('=')[1].replace(/\"/g, '').trim();
                }
              }
              break;
            } else if (output.includes('red hat') || output.includes('rhel') || output.includes('centos')) {
              distro = 'rhel';
              const versionMatch = result.stdout.match(/(\\d+\\.\\d+)/);
              if (versionMatch) {
                version = versionMatch[1];
              }
              break;
            } else if (output.includes('debian')) {
              distro = 'debian';
              version = result.stdout.trim();
              break;
            }
          }
        }
    
        // macOS distro detection
        if (platform === 'darwin') {
          const productName = await safeExec(ssh, 'sw_vers -productName');
          const productVersion = await safeExec(ssh, 'sw_vers -productVersion');
          distro = productName.stdout.trim() || 'macos';
          version = productVersion.stdout.trim() || 'unknown';
          defaultShell = shell.includes('zsh') ? 'sh' : 'bash';
        }
    
        // Package manager detection
        let packageManager: PackageManager = 'unknown';
        if (platform === 'linux') {
          const packageManagers = [
            { command: 'command -v apt-get || which apt-get', manager: 'apt' as PackageManager },
            { command: 'command -v dnf || which dnf', manager: 'dnf' as PackageManager },
            { command: 'command -v yum || which yum', manager: 'yum' as PackageManager },
            { command: 'command -v pacman || which pacman', manager: 'pacman' as PackageManager },
            { command: 'command -v apk || which apk', manager: 'apk' as PackageManager },
            { command: 'command -v zypper || which zypper', manager: 'zypper' as PackageManager }
          ];
    
          for (const { command, manager } of packageManagers) {
            const result = await safeExec(ssh, command);
            if (result.code === 0) {
              packageManager = manager;
              break;
            }
          }
        } else if (platform === 'darwin') {
          const brewResult = await safeExec(ssh, 'command -v brew || which brew');
          if (brewResult.code === 0) {
            packageManager = 'brew';
          }
          defaultShell = shell.includes('zsh') ? 'sh' : 'bash';
        }
    
        // Init system detection
        let init: InitSystem = 'unknown';
        if (platform === 'linux') {
          const systemctlResult = await safeExec(ssh, 'command -v systemctl || which systemctl');
          const serviceResult = await safeExec(ssh, 'command -v service || which service');
          if (systemctlResult.code === 0) {
            init = 'systemd';
          } else if (serviceResult.code === 0) {
            init = 'service';
          }
        } else if (platform === 'darwin') {
          init = 'launchd';
        }
    
        tempDir = platform === 'darwin' || platform === 'linux' ? '/tmp' : tempDir;
        defaultShell = defaultShell === 'unknown' ? (shell.includes('bash') ? 'bash' : 'sh') : defaultShell;
    
        const osInfo: OSInfo = {
          platform,
          distro,
          version,
          arch,
          shell,
          packageManager,
          init,
          defaultShell,
          tempDir
        };
    
        logger.debug('OS detection completed', osInfo);
        return osInfo;
    
      } catch (error) {
        logger.error('Failed to detect OS information', { error });
        throw createFilesystemError(
          'Failed to detect OS information',
          'Ensure the SSH connection is working and the remote system responds to basic commands'
        );
      }
    }
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 what the tool does but fails to describe how it behaves: it doesn't specify what information is returned (e.g., OS version, architecture), whether it's a read-only operation, or any potential side effects like network usage. This leaves significant gaps for a tool that interacts with a system.

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 that directly states the tool's purpose without any wasted words. It's front-loaded and appropriately sized for a simple tool, making it easy 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 of detecting OS and environment info, the description is incomplete. With no annotations and no output schema, it fails to explain what data is returned, the format of the output, or any behavioral traits like error handling. This makes it inadequate for an agent to understand the full context of use.

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 100% description coverage, with the single parameter 'sessionId' clearly documented as 'SSH session ID'. The description adds no additional meaning beyond this, as it doesn't explain why a session ID is needed or how it affects detection. Baseline 3 is appropriate since the schema does the heavy lifting.

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

Purpose4/5

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

The description clearly states the tool's function with a specific verb ('detects') and resource ('operating system and environment information'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools, which are mostly file system, process, and SSH operations, so this tool appears distinct by default but without explicit comparison.

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 or in what context it's appropriate. It lacks any mention of prerequisites, such as needing an active SSH session, or exclusions, leaving the agent to infer usage from the parameter alone.

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/oaslananka/mcp-ssh-tool'

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