mobile_terminate_app
Stop and terminate an app on a mobile device by specifying the device identifier and package name. Use this tool to force-close applications during mobile automation testing.
Instructions
Stop and terminate an app on mobile device
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| device | Yes | The device identifier to use. Use mobile_list_available_devices to find which devices are available to you. | |
| packageName | Yes | The package name of the app to terminate |
Implementation Reference
- src/server.ts:281-294 (registration)Registration of the 'mobile_terminate_app' MCP tool. Includes input schema for 'device' and 'packageName', and handler that uses getRobotFromDevice to get the platform-specific robot and calls its terminateApp method.tool( "mobile_terminate_app", "Terminate App", "Stop and terminate an app on mobile device", { device: z.string().describe("The device identifier to use. Use mobile_list_available_devices to find which devices are available to you."), packageName: z.string().describe("The package name of the app to terminate"), }, async ({ device, packageName }) => { const robot = getRobotFromDevice(device); await robot.terminateApp(packageName); return `Terminated app ${packageName}`; } );
- src/server.ts:289-292 (handler)Handler function for the tool. Retrieves the Robot instance for the given device and invokes terminateApp(packageName). The actual termination logic is implemented in platform-specific Robot subclasses (AndroidRobot, IosRobot, MobileDevice).async ({ device, packageName }) => { const robot = getRobotFromDevice(device); await robot.terminateApp(packageName); return `Terminated app ${packageName}`;
- src/server.ts:285-288 (schema)Input schema using Zod for the tool parameters: device (string) and packageName (string).{ device: z.string().describe("The device identifier to use. Use mobile_list_available_devices to find which devices are available to you."), packageName: z.string().describe("The package name of the app to terminate"), },
- src/server.ts:142-179 (helper)Helper function getRobotFromDevice that determines the device type and returns the appropriate Robot implementation (IosRobot for real iOS, AndroidRobot for Android, MobileDevice for simulators). Used by the tool handler.const getRobotFromDevice = (deviceId: string): Robot => { // from now on, we must have mobilecli working ensureMobilecliAvailable(); // Check if it's an iOS device const iosManager = new IosManager(); const iosDevices = iosManager.listDevices(); const iosDevice = iosDevices.find(d => d.deviceId === deviceId); if (iosDevice) { return new IosRobot(deviceId); } // Check if it's an Android device const androidManager = new AndroidDeviceManager(); const androidDevices = androidManager.getConnectedDevices(); const androidDevice = androidDevices.find(d => d.deviceId === deviceId); if (androidDevice) { return new AndroidRobot(deviceId); } // Check if it's a simulator (will later replace all other device types as well) const response = mobilecli.getDevices({ platform: "ios", type: "simulator", includeOffline: false, }); if (response.status === "ok" && response.data && response.data.devices) { for (const device of response.data.devices) { if (device.id === deviceId) { return new MobileDevice(deviceId); } } } throw new ActionableError(`Device "${deviceId}" not found. Use the mobile_list_available_devices tool to see available devices.`); };