Skip to main content
Glama

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
NameRequiredDescriptionDefault
amCommandYesActivity Manager subcommand, e.g. 'start', 'broadcast', 'force-stop', etc.
amArgsNoArguments for the am subcommand, e.g. '-a android.intent.action.VIEW'
deviceNoSpecific device ID (optional)

Implementation Reference

  • 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");
    },
  • 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 }
    );
  • Export of the AdbActivityManagerSchema, which is used in the tool registration in src/index.ts.
    export const AdbActivityManagerSchema = adbActivityManagerSchema;
  • 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;
    }

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/srmorete/adb-mcp'

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