remove_package
Uninstall packages from Arch Linux systems with options for basic removal, dependency cleanup, or forced removal when needed.
Instructions
[LIFECYCLE] Remove a package from the system. Supports various removal strategies: basic removal, removal with dependencies, or forced removal. Only works on Arch Linux. Requires sudo access.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| package_name | Yes | Name of the package to remove | |
| remove_dependencies | No | Remove package and its dependencies (pacman -Rs). Default: false | |
| force | No | Force removal ignoring dependencies (pacman -Rdd). Use with caution! Default: false |
Implementation Reference
- src/arch_ops_server/pacman.py:322-395 (handler)The core handler function implementing the remove_package tool logic. Executes pacman removal commands with options for dependencies and force, handles errors, and returns structured results.async def remove_package( package_name: str, remove_dependencies: bool = False, force: bool = False ) -> Dict[str, Any]: """ Remove a single package from the system. Args: package_name: Name of package to remove remove_dependencies: If True, remove unneeded dependencies (pacman -Rs) force: If True, force removal ignoring dependencies (pacman -Rdd) Returns: Dict with removal status and information """ if not IS_ARCH: return create_error_response( "NotSupported", "Package removal is only available on Arch Linux" ) if not check_command_exists("pacman"): return create_error_response( "CommandNotFound", "pacman command not found" ) logger.info(f"Removing package: {package_name} (deps={remove_dependencies}, force={force})") # Build command based on options cmd = ["sudo", "pacman"] if force: cmd.extend(["-Rdd"]) # Force remove, skip dependency checks elif remove_dependencies: cmd.extend(["-Rs"]) # Remove with unused dependencies else: cmd.extend(["-R"]) # Basic removal cmd.extend(["--noconfirm", package_name]) try: exit_code, stdout, stderr = await run_command( cmd, timeout=60, # Longer timeout for removal check=False, skip_sudo_check=True # We're using sudo in the command ) if exit_code != 0: logger.error(f"Package removal failed: {stderr}") return create_error_response( "RemovalError", f"Failed to remove {package_name}: {stderr}", f"Exit code: {exit_code}" ) logger.info(f"Successfully removed {package_name}") return { "success": True, "package": package_name, "removed_dependencies": remove_dependencies, "output": stdout } except Exception as e: logger.error(f"Package removal failed with exception: {e}") return create_error_response( "RemovalError", f"Failed to remove {package_name}: {str(e)}" )
- MCP tool schema definition including input validation (JSON schema) and description for the remove_package tool in the @server.list_tools() handler.Tool( name="remove_package", description="[LIFECYCLE] Remove a package from the system. Supports various removal strategies: basic removal, removal with dependencies, or forced removal. Only works on Arch Linux. Requires sudo access.", inputSchema={ "type": "object", "properties": { "package_name": { "type": "string", "description": "Name of the package to remove" }, "remove_dependencies": { "type": "boolean", "description": "Remove package and its dependencies (pacman -Rs). Default: false", "default": False }, "force": { "type": "boolean", "description": "Force removal ignoring dependencies (pacman -Rdd). Use with caution! Default: false", "default": False } }, "required": ["package_name"] } ),
- src/arch_ops_server/server.py:1220-1229 (registration)MCP tool registration and execution handler in @server.call_tool(). Dispatches arguments to the pacman.remove_package function and formats the response.elif name == "remove_package": if not IS_ARCH: return [TextContent(type="text", text="Error: remove_package only available on Arch Linux systems")] package_name = arguments["package_name"] remove_dependencies = arguments.get("remove_dependencies", False) force = arguments.get("force", False) result = await remove_package(package_name, remove_dependencies, force) return [TextContent(type="text", text=json.dumps(result, indent=2))]
- src/arch_ops_server/server.py:26-82 (registration)Import of the remove_package handler function into the MCP server module for tool registration.from . import ( # Wiki functions search_wiki, get_wiki_page_as_text, # AUR functions search_aur, get_aur_info, get_pkgbuild, analyze_pkgbuild_safety, analyze_package_metadata_risk, install_package_secure, # Pacman functions get_official_package_info, check_updates_dry_run, remove_package, remove_packages_batch, list_orphan_packages, remove_orphans, find_package_owner, list_package_files, search_package_files, verify_package_integrity, list_package_groups, list_group_packages, list_explicit_packages, mark_as_explicit, mark_as_dependency, check_database_freshness, # System functions get_system_info, check_disk_space, get_pacman_cache_stats, check_failed_services, get_boot_logs, # News functions get_latest_news, check_critical_news, get_news_since_last_update, # Logs functions get_transaction_history, find_when_installed, find_failed_transactions, get_database_sync_history, # Mirrors functions list_active_mirrors, test_mirror_speed, suggest_fastest_mirrors, check_mirrorlist_health, # Config functions analyze_pacman_conf, analyze_makepkg_conf, check_ignored_packages, get_parallel_downloads_setting, # Utils IS_ARCH, run_command, )
- Tool metadata providing categorization, platform requirements, permissions, workflow context, and related tools for remove_package."remove_package": ToolMetadata( name="remove_package", category="lifecycle", platform="arch", permission="write", workflow="removal", related_tools=["remove_packages_batch", "list_orphan_packages"], prerequisite_tools=[]