adb_list_files
Retrieve a list of files from a specified directory on an Android device using remote path and optional device ID for targeted access.
Instructions
List files in a directory on the device
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| deviceId | No | Device ID (optional) | |
| remotePath | Yes | Remote directory path on device |
Implementation Reference
- src/tools/file.ts:88-144 (handler)Core handler function for adb_list_files tool. Checks device connection, runs 'adb shell ls -la' on the remote path, parses output into structured file list with permissions, size, date, and name.async listFiles(remotePath: string, deviceId?: string) { try { const connected = await this.adbClient.isDeviceConnected(deviceId); if (!connected) { return { success: false, error: 'Device not connected', message: 'Cannot list files - device is not connected' }; } const command = `shell ls -la "${remotePath}"`; const result = await this.adbClient.executeCommand(command, deviceId); if (!result.success) { return { success: false, error: result.error, message: 'Failed to list files' }; } const files = result.output .split('\n') .slice(1) // Skip the first line (total) .map(line => { const parts = line.trim().split(/\s+/); if (parts.length >= 9) { return { permissions: parts[0], size: parts[4], date: `${parts[5]} ${parts[6]} ${parts[7]}`, name: parts.slice(8).join(' ') }; } return null; }) .filter(file => file !== null); return { success: true, data: { path: remotePath, files, count: files.length, deviceId: deviceId || this.adbClient.getDefaultDevice() }, message: `Listed ${files.length} files in ${remotePath}` }; } catch (error: any) { return { success: false, error: error.message, message: 'Failed to list files' }; } }
- src/index.ts:339-352 (schema)Input schema definition for the adb_list_files tool, specifying remotePath as required string and optional deviceId.inputSchema: { type: 'object', properties: { remotePath: { type: 'string', description: 'Remote directory path on device', }, deviceId: { type: 'string', description: 'Device ID (optional)', }, }, required: ['remotePath'], },
- src/index.ts:469-470 (registration)Registers the tool handler by dispatching calls to FileTools.listFiles method in the main switch statement.case 'adb_list_files': return await this.handleToolCall(this.fileTools.listFiles(args?.remotePath as string, args?.deviceId as string));
- src/index.ts:336-353 (registration)Tool registration in the ListTools response, including name, description, and schema.{ name: 'adb_list_files', description: 'List files in a directory on the device', inputSchema: { type: 'object', properties: { remotePath: { type: 'string', description: 'Remote directory path on device', }, deviceId: { type: 'string', description: 'Device ID (optional)', }, }, required: ['remotePath'], }, },