list_files
Retrieve file listings from Android device directories to manage storage, locate files, and verify content during development and testing workflows.
Instructions
List files in a directory on the device
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| remote_path | No | /sdcard/ | |
| device_serial | No |
Implementation Reference
- src/adb_mcp_server/server.py:971-974 (handler)The list_files tool handler function. Decorated with @mcp.tool() for automatic registration in FastMCP. Executes 'adb shell ls -la' on the specified remote path to list files and directories with details.@mcp.tool() def list_files(remote_path: str = "/sdcard/", device_serial: str | None = None) -> str: """List files in a directory on the device""" return run_adb(["shell", "ls", "-la", remote_path], device_serial)
- src/adb_mcp_server/server.py:24-39 (helper)Utility function used by list_files (and other tools) to run ADB commands safely, handling device serial, timeouts, and errors.def run_adb(args: list[str], device_serial: str | None = None, timeout: int = 30) -> str: """Run an ADB command and return output""" cmd = ["adb"] if device_serial: cmd.extend(["-s", device_serial]) cmd.extend(args) try: result = subprocess.run(cmd, capture_output=True, text=True, timeout=timeout) if result.returncode != 0 and result.stderr: return f"Error: {result.stderr}" return result.stdout except subprocess.TimeoutExpired: return "Error: Command timed out" except Exception as e: return f"Error: {str(e)}"