Skip to main content
Glama
rahulkr
by rahulkr

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
NameRequiredDescriptionDefault
remote_pathNo/sdcard/
device_serialNo

Implementation Reference

  • 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)
  • 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)}"

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/rahulkr/r_adb_mcp_server'

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