android_stop_emulator
Stop a running Android emulator by specifying its AVD name to free system resources and manage development environments.
Instructions
Stop a running Android emulator
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| avdName | Yes | AVD name to stop |
Implementation Reference
- src/tools/android.ts:635-677 (handler)The async handler function validates the input using AndroidEmulatorStopSchema, retrieves the PID of the running emulator from the global runningEmulators map, kills the process using process.kill(pid, 'SIGTERM'), removes it from tracking, and returns success status.handler: async (args: any) => { const validation = AndroidEmulatorStopSchema.safeParse(args); if (!validation.success) { throw new Error(`Invalid request: ${validation.error.message}`); } const { avdName } = validation.data; const pid = runningEmulators.get(avdName); if (!pid) { throw new Error(`Emulator is not running or not tracked by this server. No running emulator found for AVD: ${avdName}`); } try { // Kill the process process.kill(pid, 'SIGTERM'); // Remove from tracking runningEmulators.delete(avdName); return { success: true, data: { avdName, pid, status: 'stopped', }, }; } catch (killError) { // Process might already be dead runningEmulators.delete(avdName); return { success: true, data: { avdName, pid, status: 'already_stopped', message: 'Process was already terminated', }, }; } }
- src/tools/android.ts:135-137 (schema)Zod validation schema for the android_stop_emulator tool input, requiring a non-empty 'avdName' string.const AndroidEmulatorStopSchema = z.object({ avdName: z.string().min(1), });
- src/tools/android.ts:625-678 (registration)Registration of the 'android_stop_emulator' tool in the tools Map within createAndroidTools function, including name, description, inputSchema (JSON schema), and reference to the handler function.tools.set('android_stop_emulator', { name: 'android_stop_emulator', description: 'Stop a running Android emulator', inputSchema: { type: 'object', properties: { avdName: { type: 'string', minLength: 1, description: 'AVD name to stop' } }, required: ['avdName'] }, handler: async (args: any) => { const validation = AndroidEmulatorStopSchema.safeParse(args); if (!validation.success) { throw new Error(`Invalid request: ${validation.error.message}`); } const { avdName } = validation.data; const pid = runningEmulators.get(avdName); if (!pid) { throw new Error(`Emulator is not running or not tracked by this server. No running emulator found for AVD: ${avdName}`); } try { // Kill the process process.kill(pid, 'SIGTERM'); // Remove from tracking runningEmulators.delete(avdName); return { success: true, data: { avdName, pid, status: 'stopped', }, }; } catch (killError) { // Process might already be dead runningEmulators.delete(avdName); return { success: true, data: { avdName, pid, status: 'already_stopped', message: 'Process was already terminated', }, }; } } });