Skip to main content
Glama

android_install_apk

Install APK files on Android devices or emulators by specifying device serial and APK path, with options to replace existing apps or allow test APKs.

Instructions

Install an APK file to an Android device or emulator

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
serialYesDevice serial number
apkPathYesPath to APK file
optionsNo

Implementation Reference

  • The asynchronous handler function for the android_install_apk tool. It validates input using Zod schema, checks if the APK file exists and has correct extension, constructs ADB install command with optional flags, executes it via processExecutor, and returns success with output or throws error.
      handler: async (args: any) => {
        const validation = AndroidAdbInstallSchema.safeParse(args);
        if (!validation.success) {
          throw new Error(`Invalid request: ${validation.error.message}`);
        }
    
        const { serial, apkPath, options = {} } = validation.data;
    
        // Validate APK path
        if (!apkPath.endsWith('.apk')) {
          throw new Error(`File must have .apk extension. Invalid path: ${apkPath}`);
        }
    
        // Check if APK file exists
        try {
          await fs.access(apkPath);
        } catch {
          throw new Error(`APK file not found: ${apkPath}`);
        }
    
        const adb_args = ['-s', serial, 'install'];
        
        if (options.replace) {
          adb_args.push('-r');
        }
        
        if (options.test) {
          adb_args.push('-t');
        }
        
        adb_args.push(apkPath);
    
        const result = await processExecutor.execute('adb', adb_args, {
          timeout: 300000, // 5 minutes timeout for APK installation
        });
    
        if (result.exitCode !== 0) {
          throw new Error(`APK installation failed: ${result.stderr || result.stdout}`);
        }
    
        return {
          success: true,
          data: {
            serial,
            apkPath: path.basename(apkPath),
            output: result.stdout,
          },
        };
      }
    });
  • Zod validation schema defining the input parameters for the android_install_apk tool: required serial (device ID), apkPath (file path), and optional options for replace and test flags.
    const AndroidAdbInstallSchema = z.object({
      serial: z.string().min(1),
      apkPath: z.string().min(1),
      options: z.object({
        replace: z.boolean().optional(),
        test: z.boolean().optional(),
      }).optional(),
    });
  • Registration of the android_install_apk tool within the createAndroidTools factory function, including name, description, JSON schema for MCP protocol, and reference to the handler function.
    tools.set('android_install_apk', {
      name: 'android_install_apk',
      description: 'Install an APK file to an Android device or emulator',
      inputSchema: {
        type: 'object',
        properties: {
          serial: { type: 'string', minLength: 1, description: 'Device serial number' },
          apkPath: { type: 'string', minLength: 1, description: 'Path to APK file' },
          options: {
            type: 'object',
            properties: {
              replace: { type: 'boolean', description: 'Replace existing app if installed' },
              test: { type: 'boolean', description: 'Allow test APKs' }
            }
          }
        },
        required: ['serial', 'apkPath']
      },
      handler: async (args: any) => {
        const validation = AndroidAdbInstallSchema.safeParse(args);
        if (!validation.success) {
          throw new Error(`Invalid request: ${validation.error.message}`);
        }
    
        const { serial, apkPath, options = {} } = validation.data;
    
        // Validate APK path
        if (!apkPath.endsWith('.apk')) {
          throw new Error(`File must have .apk extension. Invalid path: ${apkPath}`);
        }
    
        // Check if APK file exists
        try {
          await fs.access(apkPath);
        } catch {
          throw new Error(`APK file not found: ${apkPath}`);
        }
    
        const adb_args = ['-s', serial, 'install'];
        
        if (options.replace) {
          adb_args.push('-r');
        }
        
        if (options.test) {
          adb_args.push('-t');
        }
        
        adb_args.push(apkPath);
    
        const result = await processExecutor.execute('adb', adb_args, {
          timeout: 300000, // 5 minutes timeout for APK installation
        });
    
        if (result.exitCode !== 0) {
          throw new Error(`APK installation failed: ${result.stderr || result.stdout}`);
        }
    
        return {
          success: true,
          data: {
            serial,
            apkPath: path.basename(apkPath),
            output: result.stdout,
          },
        };
      }
    });
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It states 'Install' which implies a write/mutation operation, but doesn't disclose critical behavioral aspects: whether this requires device permissions, if it's destructive to existing apps, what happens on failure, or any rate limits. The description is minimal and lacks operational context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that gets straight to the point with zero wasted words. It's appropriately sized for a tool with this level of complexity and is perfectly front-loaded with the core functionality.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a mutation tool with no annotations and no output schema, the description is inadequate. It doesn't cover what happens after installation (success/failure indicators), doesn't mention dependencies like ADB availability, and provides minimal context about the three parameters. Given the complexity of device operations, more completeness is needed.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 67% (2 of 3 parameters documented), so the baseline is 3. The description mentions 'APK file' which aligns with the 'apkPath' parameter, but adds no additional semantic context beyond what the schema provides for any parameters. It doesn't explain the significance of device serial numbers or option behaviors.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Install') and target ('APK file to an Android device or emulator'), which is specific and unambiguous. However, it doesn't differentiate from sibling tools like 'native_run_install_app' or 'flutter_run', which might have overlapping functionality in mobile app deployment contexts.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. With siblings like 'native_run_install_app' and 'flutter_run' that might handle app installation in different ways, there's no indication of prerequisites, target scenarios, or exclusions for this Android-specific APK installer.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/cristianoaredes/mcp-mobile-server'

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