Skip to main content
Glama

adb_get_battery_info

Retrieve battery status and health data from Android devices through ADB for monitoring power levels and charging state.

Instructions

Get battery information from the device

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
deviceIdNoDevice ID (optional)

Implementation Reference

  • Main handler function for 'adb_get_battery_info' tool. Executes 'adb shell dumpsys battery', parses key battery properties using extractValue helper, and returns structured data.
    async getBatteryInfo(deviceId?: string) { try { const connected = await this.adbClient.isDeviceConnected(deviceId); if (!connected) { return { success: false, error: 'Device not connected', message: 'Cannot get battery info - device is not connected' }; } const command = 'shell dumpsys battery'; const result = await this.adbClient.executeCommand(command, deviceId); if (!result.success) { return { success: false, error: result.error, message: 'Failed to get battery info' }; } // Parse battery information const output = result.output; const batteryInfo = { level: this.extractValue(output, 'level'), scale: this.extractValue(output, 'scale'), status: this.extractValue(output, 'status'), health: this.extractValue(output, 'health'), present: this.extractValue(output, 'present'), plugged: this.extractValue(output, 'plugged'), voltage: this.extractValue(output, 'voltage'), temperature: this.extractValue(output, 'temperature'), technology: this.extractValue(output, 'technology') }; return { success: true, data: { ...batteryInfo, deviceId: deviceId || this.adbClient.getDefaultDevice() }, message: 'Battery information retrieved successfully' }; } catch (error: any) { return { success: false, error: error.message, message: 'Failed to get battery info' }; } }
  • Tool schema definition including name, description, and input schema (optional deviceId).
    { name: 'adb_get_battery_info', description: 'Get battery information from the device', inputSchema: { type: 'object', properties: { deviceId: { type: 'string', description: 'Device ID (optional)', }, }, required: [], }, },
  • src/index.ts:477-478 (registration)
    Switch case registration that maps tool name to the shellTools.getBatteryInfo handler.
    case 'adb_get_battery_info': return await this.handleToolCall(this.shellTools.getBatteryInfo(args?.deviceId as string));
  • Private helper method used by getBatteryInfo to parse key-value pairs from 'dumpsys battery' output.
    private extractValue(text: string, key: string): string { const regex = new RegExp(`${key}:\\s*(.+)`); const match = text.match(regex); return match ? match[1].trim() : 'N/A'; }

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

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