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
| Name | Required | Description | Default |
|---|---|---|---|
| remote_path | Yes | ||
| device_serial | No |
Implementation Reference
- src/adb_mcp_server/server.py:977-981 (handler)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)
- src/adb_mcp_server/server.py:24-39 (helper)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)}"
- src/adb_mcp_server/server.py:18-18 (registration)Creation of the FastMCP server instance to which all tools including 'read_file' are registered via decorators.mcp = FastMCP("adb-dev-server")