Skip to main content
Glama

find_when_installed

Check when an Arch Linux package was first installed and view its upgrade history to track system changes and troubleshoot issues.

Instructions

[HISTORY] Find when a package was first installed and its upgrade history. Only works on Arch Linux.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
package_nameYesName of the package to search for

Implementation Reference

  • Core handler function that parses the pacman log file (/var/log/pacman.log) to find the first installation timestamp, upgrade history, and removal records for the specified package.
    async def find_when_installed(package_name: str) -> Dict[str, Any]: """ Find when a package was first installed and its upgrade history. Args: package_name: Name of the package to search for Returns: Dict with installation date and upgrade history """ if not IS_ARCH: return create_error_response( "NotSupported", "This feature is only available on Arch Linux" ) logger.info(f"Finding installation history for package: {package_name}") try: pacman_log = Path(PACMAN_LOG) if not pacman_log.exists(): return create_error_response( "NotFound", f"Pacman log file not found at {PACMAN_LOG}" ) first_install = None upgrades = [] removals = [] with open(pacman_log, 'r') as f: for line in f: parsed = parse_log_line(line) if not parsed or parsed["package"] != package_name: continue action = parsed["action"].lower() if action == "installed": if first_install is None: first_install = parsed elif action in ["upgraded", "downgraded", "reinstalled"]: upgrades.append(parsed) elif action == "removed": removals.append(parsed) if first_install is None: return create_error_response( "NotFound", f"No installation record found for package: {package_name}" ) logger.info(f"Package {package_name}: installed {first_install['timestamp']}, {len(upgrades)} upgrades, {len(removals)} removals") return { "package": package_name, "first_installed": first_install, "upgrade_count": len(upgrades), "upgrades": upgrades, "removal_count": len(removals), "removals": removals, "currently_removed": len(removals) > 0 and (not upgrades or removals[-1]["timestamp"] > upgrades[-1]["timestamp"]) } except Exception as e: logger.error(f"Failed to find installation history: {e}") return create_error_response( "LogParseError", f"Failed to find installation history: {str(e)}" )
  • ToolMetadata providing categorization (history), platform requirements (arch), permissions (read), workflow (audit), and related tools for the find_when_installed tool.
    "find_when_installed": ToolMetadata( name="find_when_installed", category="history", platform="arch", permission="read", workflow="audit", related_tools=["get_transaction_history"], prerequisite_tools=[]
  • Package-level import of the find_when_installed function from logs.py, exposing it for use in the MCP server.
    from .logs import ( get_transaction_history, find_when_installed, find_failed_transactions, get_database_sync_history )
  • Helper function to parse individual lines from the pacman log, extracting timestamp, action, package name, and version info. Used by find_when_installed.
    def parse_log_line(line: str) -> Optional[Dict[str, Any]]: """ Parse a single line from pacman log. Args: line: Log line to parse Returns: Dict with parsed data or None if not a transaction line """ # Format: [YYYY-MM-DD HH:MM] [ACTION] package (version) match = re.match( r'\[(\d{4}-\d{2}-\d{2})\s+(\d{2}:\d{2})\]\s+\[(\w+)\]\s+(.+)', line ) if not match: return None date_str, time_str, action, details = match.groups() timestamp = f"{date_str}T{time_str}:00" # Parse package details # Format: "package_name (version)" or "package_name (old -> new)" pkg_match = re.match(r'(\S+)\s+\((.+)\)', details) if pkg_match: package = pkg_match.group(1) version_info = pkg_match.group(2) else: # Some log lines don't have version info package = details version_info = "" return { "timestamp": timestamp, "action": action, "package": package, "version_info": version_info, "raw_line": line.strip() }

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/nihalxkumar/arch-mcp'

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