check_command_exists
Verify if a Unix command is available on your system before attempting to use it, preventing errors and ensuring compatibility.
Instructions
Check if a command exists on the system.
Args: command: The command to check
Returns: Information about whether the command exists
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| command | Yes |
Implementation Reference
- unix_manual_server.py:311-359 (handler)The @mcp.tool()-decorated function implementing the 'check_command_exists' MCP tool handler. It checks if the specified command exists on the system by finding its path using get_command_path, validates the command name, and attempts to retrieve version information using --version, -V, or version subcommands.@mcp.tool() def check_command_exists(command: str) -> str: """ Check if a command exists on the system. Args: command: The command to check Returns: Information about whether the command exists """ logger.info(f"Checking if command exists: '{command}'") command_name = command.strip().split()[0] logger.debug(f"Extracted command name: {command_name}") if not re.match(r'^[a-zA-Z0-9_\.-]+$', command_name): logger.warning(f"Invalid command name: '{command_name}'") return f"Invalid command name: '{command_name}'" command_path = get_command_path(command_name) if command_path: logger.info(f"Command '{command_name}' exists at {command_path}") # Try --version logger.debug(f"Trying --version for {command_name}") version_result = safe_execute([command_path, "--version"], timeout=5) if version_result and version_result.returncode < 2 and version_result.stdout.strip(): logger.debug(f"Got version info using --version for {command_name}") return f"Command '{command_name}' exists at {command_path}.\nVersion information: {version_result.stdout.strip()}" # Try -V (some commands use this for version) logger.debug(f"Trying -V for {command_name}") version_result = safe_execute([command_path, "-V"], timeout=5) if version_result and version_result.returncode < 2 and version_result.stdout.strip(): logger.debug(f"Got version info using -V for {command_name}") return f"Command '{command_name}' exists at {command_path}.\nVersion information: {version_result.stdout.strip()}" # Try version logger.debug(f"Trying version subcommand for {command_name}") version_result = safe_execute([command_path, "version"], timeout=5) if version_result and version_result.returncode < 2 and version_result.stdout.strip(): logger.debug(f"Got version info using version subcommand for {command_name}") return f"Command '{command_name}' exists at {command_path}.\nVersion information: {version_result.stdout.strip()}" return f"Command '{command_name}' exists on this system at {command_path}." else: logger.warning(f"Command '{command_name}' does not exist or is not in the PATH") return f"Command '{command_name}' does not exist or is not in the PATH."