Skip to main content
Glama
rahulkr
by rahulkr

read_file

Retrieve text file contents from Android devices to access logs, configuration files, or application data for debugging and analysis.

Instructions

Read a text file from the device

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
remote_pathYes
device_serialNo

Implementation Reference

  • The handler function for the MCP tool 'read_file'. Decorated with @mcp.tool() which registers the tool and automatically generates input/output schema from type hints. Executes 'adb shell cat' on the remote_path to read the file content.
    @mcp.tool()
    def read_file(remote_path: str, device_serial: str | None = None) -> str:
        """Read a text file from the device"""
        return run_adb(["shell", "cat", remote_path], device_serial)
  • Supporting utility function that runs ADB commands with optional device serial and timeout handling. Called by read_file to execute the 'adb shell cat' command.
    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)}"
  • Creation of the FastMCP server instance to which all tools including 'read_file' are registered via decorators.
    mcp = FastMCP("adb-dev-server")

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