adb_get_battery_info
Retrieve detailed battery information from Android devices using the ADB MCP Server. Input the device ID optionally to fetch specific data for remote device management and diagnostics.
Instructions
Get battery information from the device
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| deviceId | No | Device ID (optional) |
Implementation Reference
- src/tools/shell.ts:109-160 (handler)The main handler function for 'adb_get_battery_info' that checks device connection, executes 'adb shell dumpsys battery', parses the output using extractValue helper, and returns structured battery information.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' }; } }
- src/index.ts:388-400 (schema)Input schema definition for the 'adb_get_battery_info' tool, specifying optional deviceId parameter.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)Registration of the tool handler in the switch statement within CallToolRequestSchema, dispatching calls to ShellTools.getBatteryInfo.case 'adb_get_battery_info': return await this.handleToolCall(this.shellTools.getBatteryInfo(args?.deviceId as string));
- src/tools/shell.ts:162-166 (helper)Helper function used by getBatteryInfo to extract specific values (e.g., level, status) from the raw 'dumpsys battery' output using regex.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'; }