Skip to main content
Glama

ensure_package

Install or remove packages on remote servers via SSH to maintain desired system states. This tool verifies package presence or absence and takes action when needed.

Instructions

Ensures a package is installed or removed

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sessionIdYesSSH session ID
nameYesPackage name
stateYesDesired state

Implementation Reference

  • The implementation of the ensurePackage function, which sanitizes the input, checks if the package is already installed, and runs the appropriate installation command for the detected package manager.
    export async function ensurePackage(
      sessionId: string,
      packageName: string,
      sudoPassword?: string
    ): Promise<PackageResult> {
      // Validate and sanitize package name to prevent injection
      const safePackageName = sanitizePackageName(packageName);
      logger.debug('Ensuring package is installed', { sessionId, packageName: safePackageName });
    
      const session = sessionManager.getSession(sessionId);
      if (!session) {
        throw new Error(`Session ${sessionId} not found or expired`);
      }
    
      try {
        // Detect OS and package manager
        const osInfo = await sessionManager.getOSInfo(sessionId);
        const pm = osInfo.packageManager;
    
        if (pm === 'unknown') {
          throw createPackageManagerError(
            'No supported package manager found',
            'Supported package managers: apt, dnf, yum, pacman, apk, zypper, brew'
          );
        }
        if (osInfo.platform === 'windows') {
          throw createPackageManagerError(
            'Package management on Windows hosts is not supported by this tool yet',
            'Use winget/choco manually or install via other Windows package workflows'
          );
        }
    
        logger.debug('Detected package manager', { sessionId, pm });
    
        // Check if package is already installed
        const isInstalled = await checkPackageInstalled(sessionId, safePackageName, pm);
        if (isInstalled) {
          logger.info('Package already installed', { sessionId, packageName: safePackageName });
          return {
            ok: true,
            pm,
            code: 0,
            stdout: `Package ${safePackageName} is already installed`,
            stderr: ''
          };
        }
    
        // Install the package using sanitized name
        const installCommand = getInstallCommand(pm, safePackageName);
        logger.debug('Installing package', { sessionId, packageName: safePackageName, command: installCommand });
    
        const runInstaller = pm === 'brew'
          ? () => execCommand(sessionId, installCommand)
          : () => execSudo(sessionId, installCommand, sudoPassword);
    
        const result = await runInstaller();
    
        const packageResult: PackageResult = {
          ok: result.code === 0,
          pm,
          code: result.code,
          stdout: result.stdout,
          stderr: result.stderr
        };
    
        if (result.code === 0) {
          logger.info('Package installed successfully', { sessionId, packageName: safePackageName });
        } else {
          logger.error('Package installation failed', { sessionId, packageName: safePackageName, code: result.code });
        }
    
        return packageResult;
    
      } catch (error) {
        logger.error('Failed to ensure package', { sessionId, packageName, error });
        throw error;
      }
    }
  • Input validation schema for the ensure_package tool.
    export const EnsurePackageSchema = z.object({
      sessionId: z.string().min(1),
      name: z.string().min(1),
      sudoPassword: z.string().optional()
    });
  • src/mcp.ts:475-479 (registration)
    Registration/handler logic for the ensure_package MCP tool within the main MCP loop.
    case 'ensure_package': {
      const params = EnsurePackageSchema.parse(args);
      const result = await ensurePackage(params.sessionId, params.name, params.sudoPassword);
      logger.info('Package ensured', { sessionId: params.sessionId, name: params.name });
      return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions ensuring installation or removal but lacks details on permissions required (e.g., sudo access), idempotency, error handling, or system impacts (e.g., dependencies). This is inadequate for a mutation tool with zero annotation coverage.

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 with zero waste. It's front-loaded with the core purpose ('Ensures a package is installed or removed'), making it easy to parse quickly without unnecessary elaboration.

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?

For a mutation tool with no annotations and no output schema, the description is incomplete. It doesn't cover behavioral aspects like side effects, return values, or error conditions, which are critical for safe agent operation. Given the complexity of package management, more context is needed to ensure reliable 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?

Schema description coverage is 100%, so parameters are well-documented in the schema. The description adds minimal value by implying the tool uses 'state' to determine action, but doesn't clarify semantics beyond what the schema provides (e.g., what 'present' or 'absent' entail operationally). Baseline 3 is appropriate as 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 purpose with specific verbs ('installed or removed') and resource ('package'), making it immediately understandable. However, it doesn't differentiate from sibling tools like 'proc_exec' or 'proc_sudo' which might also handle packages, leaving room for ambiguity in a tool-rich environment.

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?

No guidance is provided on when to use this tool versus alternatives. The description doesn't mention prerequisites (e.g., needing an SSH session), compare it to similar tools like 'proc_exec' for package management, or specify scenarios where it's preferred over manual commands, leaving the agent to infer usage context.

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