Skip to main content
Glama
zillow
by zillow

terminateApp

Stop a mobile application by specifying its package ID to close running processes and free device resources.

Instructions

Terminate an app by package name

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
appIdYesApp package ID of the app

Implementation Reference

  • Registration of the "terminateApp" tool using ToolRegistry.registerDeviceAware, linking the name, description, input schema, and handler function.
    ToolRegistry.registerDeviceAware(
      "terminateApp",
      "Terminate an app by package name",
      packageNameSchema,
      terminateAppHandler
    );
  • The registered handler function for the terminateApp tool. It creates a TerminateApp instance, executes it with the appId, and formats the response.
    const terminateAppHandler = async (device: BootedDevice, args: AppActionArgs) => {
      try {
        const terminateApp = new TerminateApp(device);
        const result = await terminateApp.execute(args.appId); // observe = true
    
        return createJSONToolResponse({
          message: `Terminated app ${args.appId}`,
          observation: result.observation,
          ...result
        });
      } catch (error) {
        throw new ActionableError(`Failed to terminate app: ${error}`);
      }
    };
  • Zod input schema for the terminateApp tool, defining the required 'appId' parameter.
    export const packageNameSchema = z.object({
      appId: z.string().describe("App package ID of the app"),
    });
  • Core execution logic of terminating the app: checks if installed/running/foreground, then force-stops via adb, returns detailed result.
    async execute(
      packageName: string,
      progress?: ProgressCallback
    ): Promise<TerminateAppResult> {
    
      return this.observedInteraction(
        async () => {
    
          // Check if app is installed
          const isInstalledCmd = `shell pm list packages -f ${packageName} | grep -c ${packageName}`;
          const isInstalledOutput = await this.adb.executeCommand(isInstalledCmd, undefined, undefined, true);
          const isInstalled = parseInt(isInstalledOutput.trim(), 10) > 0;
    
          if (!isInstalled) {
            return {
              success: true,
              packageName,
              wasInstalled: false,
              wasRunning: false,
              wasForeground: false
            };
          }
    
          // Check if app is running
          const isRunning = true;
    
          if (!isRunning) {
            return {
              success: true,
              packageName,
              wasInstalled: true,
              wasRunning: false,
              wasForeground: false
            };
          }
    
          // Check if app is in foreground
          const currentAppCmd = `shell "dumpsys window windows | grep '${packageName}'"`;
          const currentAppOutput = await this.adb.executeCommand(currentAppCmd);
    
          // App is in foreground if it's either the top app or an IME target
          const isTopApp = currentAppOutput.includes(`topApp=ActivityRecord{`) &&
            currentAppOutput.includes(`${packageName}`);
          const isImeTarget = currentAppOutput.includes(`imeLayeringTarget`) &&
            currentAppOutput.includes(`${packageName}`);
    
          const isForeground = isTopApp || isImeTarget;
    
          await this.adb.executeCommand(`shell am force-stop ${packageName}`);
    
          return {
            success: true,
            packageName,
            wasInstalled: true,
            wasRunning: true,
            wasForeground: isForeground,
          };
        },
        {
          changeExpected: false, // TODO: Can make this true if we
          progress
        }
      );
    }
  • TypeScript interface defining the output/result structure of the terminateApp operation.
    export interface TerminateAppResult {
      success: boolean;
      packageName: string;
      wasInstalled: boolean;
      wasRunning: boolean;
      wasForeground: boolean;
      observation?: ObserveResult;
      error?: string;
    }
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. While 'Terminate' implies a destructive action, it doesn't specify whether this requires special permissions, what happens to app data, whether it's reversible, or potential side effects. 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 extremely concise at just 5 words, front-loading the essential information with zero wasted words. Every element ('Terminate', 'app', 'package name') earns its place in this efficient single-sentence structure.

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 destructive tool with no annotations and no output schema, the description is insufficiently complete. It doesn't address behavioral implications, return values, error conditions, or how it differs from similar tools. Given the complexity of app termination, more context is needed.

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?

The schema has 100% description coverage for its single parameter ('appId'), so the baseline is 3. The description adds no additional parameter information beyond what's already in the schema, maintaining this adequate but unenhanced level.

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 action ('Terminate') and target resource ('an app by package name'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'killDevice' or 'launchApp' which also affect app/device state, so it doesn't reach the highest clarity level.

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 about when to use this tool versus alternatives like 'killDevice' or 'launchApp', nor about prerequisites or context. The description only states what the tool does, not when it's appropriate.

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/zillow/auto-mobile'

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