close_app
Force-stop an Android application by its package name to manage device resources and resolve unresponsive apps.
Instructions
Force-stop an Android application by its package name.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| package_name | Yes | Android package name to close | |
| device_id | No | Device serial number |
Implementation Reference
- src/adb/app-manager.ts:61-70 (handler)The core implementation of the close_app logic using adb shell am force-stop.
export async function closeApp(packageName: string, deviceId?: string): Promise<string> { const resolved = await deviceManager.resolveDeviceId(deviceId); validatePackageName(packageName); await adbShell(['am', 'force-stop', packageName], resolved); deviceManager.touchSession(resolved); log.info('App closed', { packageName, deviceId: resolved }); return packageName; } - src/controllers/app-tools.ts:84-115 (registration)MCP tool registration and handler wrapper for 'close_app'.
server.registerTool( 'close_app', { description: 'Force-stop an Android application by its package name.', inputSchema: { package_name: z.string().describe('Android package name to close'), device_id: z.string().optional().describe('Device serial number'), }, }, async ({ package_name, device_id }) => { return await metrics.measure('close_app', device_id || 'default', async () => { const resolved = await deviceManager.resolveDeviceId(device_id); const execCtx = executionEngine.preExecutionCheck('close_app', { package_name }, resolved); if (!execCtx.allowed) { return { content: [{ type: 'text' as const, text: JSON.stringify({ success: false, blocked: true, reason: execCtx.blockReason, _context: execCtx.recentContext }, null, 2), }], }; } const preHash = await capturePreActionState(resolved); const result = await closeApp(package_name, device_id); invalidateCaches(resolved); const verification = await verifyAction('close_app', resolved, preHash); return { content: [{ type: 'text' as const, text: JSON.stringify({