Skip to main content
Glama

remove_packages

Destructive

Remove Arch Linux packages individually or in batch. Supports dependency removal and forced removal ignoring dependencies. Requires sudo.

Instructions

[LIFECYCLE] Unified tool for removing packages (single or multiple). Accepts either a single package name or a list of packages. Supports removal with dependencies and forced removal. Only works on Arch Linux. Requires sudo access. Examples: packages='firefox', remove_dependencies=true → removes Firefox with its dependencies; packages=['pkg1', 'pkg2', 'pkg3'] → batch removal of multiple packages; packages='lib', force=true → force removal ignoring dependencies (dangerous!).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
packagesYesPackage name (string) or list of package names (array) to remove
remove_dependenciesNoRemove packages and their dependencies (pacman -Rs). Default: false
forceNoForce removal ignoring dependencies (pacman -Rdd). Use with caution! Default: false

Implementation Reference

  • Main handler function for the 'remove_packages' tool. Dispatches to remove_package() for single package or remove_packages_batch() for multiple packages.
    async def remove_packages(
        packages: Union[str, List[str]],
        remove_dependencies: bool = False,
        force: bool = False
    ) -> Dict[str, Any]:
        """
        Unified tool for removing packages (single or multiple).
        
        This consolidates two operations:
        - Single package removal (replaces remove_package)
        - Batch package removal (replaces remove_packages_batch)
    
        Args:
            packages: Package name (string) or list of package names to remove
            remove_dependencies: If True, remove unneeded dependencies (pacman -Rs)
            force: If True, force removal ignoring dependencies (pacman -Rdd). Only works for single package.
    
        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"
            )
    
        # Normalize input to list
        if isinstance(packages, str):
            package_list = [packages]
            is_single = True
        else:
            package_list = packages
            is_single = False
    
        if not package_list:
            return create_error_response(
                "ValidationError",
                "No packages specified for removal"
            )
    
        # Validate force flag usage
        if force and not is_single:
            return create_error_response(
                "ValidationError",
                "force flag can only be used with single package removal"
            )
    
        logger.info(f"Removing {len(package_list)} package(s): {package_list} (deps={remove_dependencies}, force={force})")
    
        # Route to appropriate implementation based on input type and flags
        if is_single:
            # Single package removal
            return await remove_package(package_list[0], remove_dependencies, force)
        else:
            # Batch package removal (force not supported)
            return await remove_packages_batch(package_list, remove_dependencies)
  • Tool registration with input schema definition. Declares 'packages', 'remove_dependencies', and 'force' parameters.
    Tool(
        name="remove_packages",
        description="[LIFECYCLE] Unified tool for removing packages (single or multiple). Accepts either a single package name or a list of packages. Supports removal with dependencies and forced removal. Only works on Arch Linux. Requires sudo access. Examples: packages='firefox', remove_dependencies=true → removes Firefox with its dependencies; packages=['pkg1', 'pkg2', 'pkg3'] → batch removal of multiple packages; packages='lib', force=true → force removal ignoring dependencies (dangerous!).",
        inputSchema={
            "type": "object",
            "properties": {
                "packages": {
                    "oneOf": [
                        {"type": "string"},
                        {"type": "array", "items": {"type": "string"}}
                    ],
                    "description": "Package name (string) or list of package names (array) to remove"
                },
                "remove_dependencies": {
                    "type": "boolean",
                    "description": "Remove packages and their 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": ["packages"]
        },
        annotations=ToolAnnotations(destructiveHint=True)
    ),
  • Tool dispatch in call_tool() that routes the 'remove_packages' name to the handler function.
    elif name == "remove_packages":
        if not IS_ARCH:
            return [TextContent(type="text", text=create_platform_error_message("remove_packages"))]
    
        packages = arguments["packages"]
        remove_dependencies = arguments.get("remove_dependencies", False)
        force = arguments.get("force", False)
        result = await remove_packages(packages, remove_dependencies, force)
        return [TextContent(type="text", text=json.dumps(result, indent=2))]
  • Tool metadata definition specifying category, platform, permissions, workflow, and related tools.
    "remove_packages": ToolMetadata(
        name="remove_packages",
        category="lifecycle",
        platform="arch",
        permission="write",
        workflow="removal",
        related_tools=["manage_orphans", "verify_package_integrity"],
        prerequisite_tools=[]
    ),
  • Helper function for single package removal (pacman -R, -Rs, or -Rdd). Called by remove_packages() for single package operations.
    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)}"
            )
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Adds significant context beyond annotations: explains 'remove_dependencies' and 'force' effects, labels force as dangerous. Discloses sudo requirement and platform limitation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loaded with [LIFECYCLE] and clear purpose. Some redundancy but overall structured well with examples. Could be slightly shorter.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Covers main aspects: platform, sudo, parameter effects. No output schema, so return value is not explained, but it's a removal tool where success/failure is typical. Adequate.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema covers 100% of parameters; description adds examples showing usage patterns and meanings, like 'package', 'remove_dependencies', 'force'. Goes beyond schema.

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

Purpose5/5

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

Description clearly states it removes packages, supports single/multiple, with dependency or force removal. It is distinct from sibling tools like install_package_secure.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Specifies it works only on Arch Linux and requires sudo access. Provides examples but does not explicitly exclude other scenarios or mention when not to use.

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

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