adb_activity_manager
Execute Android Activity Manager commands to start apps, send broadcasts, or force-stop processes on connected devices via ADB.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| amCommand | Yes | Activity Manager subcommand, e.g. 'start', 'broadcast', 'force-stop', etc. | |
| amArgs | No | Arguments for the am subcommand, e.g. '-a android.intent.action.VIEW' | |
| device | No | Specific device ID (optional) |
Implementation Reference
- src/index.ts:727-742 (handler)The handler function for the 'adb_activity_manager' tool. It validates the input, builds device-specific arguments, splits additional am arguments, and executes the 'adb shell am [command] [args]' command using the shared executeAdbCommand helper.async (args: z.infer<typeof AdbActivityManagerSchema>, _extra: RequestHandlerExtra) => { log(LogLevel.INFO, `Executing Activity Manager command: am ${args.amCommand} ${args.amArgs || ''}`); const deviceArgs = buildDeviceArgs(args.device); const amCommand = args.amCommand.trim(); if (!amCommand) { const message = "Activity Manager command must not be empty"; log(LogLevel.ERROR, message); return { content: [{ type: "text" as const, text: message }], isError: true }; } const additionalArgs = args.amArgs ? splitCommandArguments(args.amArgs) : []; return executeAdbCommand([...deviceArgs, "shell", "am", amCommand, ...additionalArgs], "Error executing Activity Manager command"); },
- src/types.ts:86-90 (schema)Zod schema definition for the input parameters of the adb_activity_manager tool: amCommand (required), amArgs (optional), device (optional).export const adbActivityManagerSchema = z.object({ amCommand: z.string().describe("Activity Manager subcommand, e.g. 'start', 'broadcast', 'force-stop', etc."), amArgs: z.string().optional().describe("Arguments for the am subcommand, e.g. '-a android.intent.action.VIEW'"), device: z.string().optional().describe("Specific device ID (optional)") });
- src/index.ts:724-744 (registration)Registration of the 'adb_activity_manager' tool on the MCP server using server.tool(), providing the tool name, input schema, inline handler function, and description.server.tool( "adb_activity_manager", AdbActivityManagerSchema.shape, async (args: z.infer<typeof AdbActivityManagerSchema>, _extra: RequestHandlerExtra) => { log(LogLevel.INFO, `Executing Activity Manager command: am ${args.amCommand} ${args.amArgs || ''}`); const deviceArgs = buildDeviceArgs(args.device); const amCommand = args.amCommand.trim(); if (!amCommand) { const message = "Activity Manager command must not be empty"; log(LogLevel.ERROR, message); return { content: [{ type: "text" as const, text: message }], isError: true }; } const additionalArgs = args.amArgs ? splitCommandArguments(args.amArgs) : []; return executeAdbCommand([...deviceArgs, "shell", "am", amCommand, ...additionalArgs], "Error executing Activity Manager command"); }, { description: ADB_ACTIVITY_MANAGER_TOOL_DESCRIPTION } );
- src/types.ts:110-110 (schema)Export of the AdbActivityManagerSchema, which is used in the tool registration in src/index.ts.export const AdbActivityManagerSchema = adbActivityManagerSchema;
- src/index.ts:289-338 (helper)Helper function splitCommandArguments used in the handler to parse the amArgs string into an array of arguments, handling quotes and escapes.function splitCommandArguments(value: string): string[] { const args: string[] = []; let current = ""; let inSingleQuote = false; let inDoubleQuote = false; let escapeNext = false; for (const char of value) { if (escapeNext) { current += char; escapeNext = false; continue; } if (char === "\\") { escapeNext = true; continue; } if (char === "'" && !inDoubleQuote) { inSingleQuote = !inSingleQuote; continue; } if (char === '"' && !inSingleQuote) { inDoubleQuote = !inDoubleQuote; continue; } if (/\s/.test(char) && !inSingleQuote && !inDoubleQuote) { if (current.length > 0) { args.push(current); current = ""; } continue; } current += char; } if (escapeNext) { current += "\\"; } if (current.length > 0) { args.push(current); } return args; }