Skip to main content
Glama

adb_list_files

List files in a directory on an Android device using ADB commands to view and manage device file systems.

Instructions

List files in a directory on the device

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
remotePathYesRemote directory path on device
deviceIdNoDevice ID (optional)

Implementation Reference

  • The listFiles method in the FileTools class that implements the tool logic: checks device connection, executes 'adb shell ls -la' command, parses the ls output into structured file information (permissions, size, date, name), and returns formatted result.
    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'
        };
      }
    }
  • Defines the tool metadata including name, description, and input schema for 'adb_list_files' in the ListTools response.
    {
      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'],
      },
    },
  • src/index.ts:469-470 (registration)
    Registers the tool handler by dispatching 'adb_list_files' calls to the FileTools.listFiles method in the CallToolRequest switch statement.
    case 'adb_list_files':
      return await this.handleToolCall(this.fileTools.listFiles(args?.remotePath as string, args?.deviceId as string));

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/richard0913/adb-mcp'

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