Skip to main content
Glama

inspect_ui

Capture and analyze Android device UI hierarchy to identify elements, extract layout details, and enable automated testing or debugging of mobile applications.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
deviceNoSpecific device ID (optional)
outputPathNoCustom output path on device (default: /sdcard/window_dump.xml)
asBase64NoReturn XML content as base64 (default: false)

Implementation Reference

  • The core handler function implementing the inspect_ui tool. Dumps current UI hierarchy using ADB uiautomator dump, pulls the XML to local temp file, returns as base64 or plain text, with proper cleanup and error handling.
    async (args: z.infer<typeof AdbUidumpSchema>, _extra: RequestHandlerExtra) => {
      log(LogLevel.INFO, "Dumping UI hierarchy");
      
      const deviceArgs = buildDeviceArgs(args.device);
      const tempFilePath = createTempFilePath("adb-mcp", "window_dump.xml");
      const remotePath = args.outputPath && args.outputPath.trim()
        ? args.outputPath.trim()
        : "/sdcard/window_dump.xml";
      
      try {
        // Dump UI hierarchy on device
        await runAdb([...deviceArgs, "shell", "uiautomator", "dump", remotePath]);
        
        // Pull the UI dump from the device
        await runAdb([...deviceArgs, "pull", remotePath, tempFilePath]);
        
        // Clean up the remote file
        await runAdb([...deviceArgs, "shell", "rm", remotePath]);
        
        // Return the UI dump
        if (args.asBase64 !== false) {
          // Return as base64 (default)
          const xmlData = await readFilePromise(tempFilePath);
          const base64Xml = xmlData.toString('base64');
          
          log(LogLevel.INFO, "UI hierarchy dumped successfully as base64");
          return {
            content: [{ type: "text" as const, text: base64Xml }]
          };
        } else {
          // Return as plain text
          const xmlData = await readFilePromise(tempFilePath, 'utf8');
          
          log(LogLevel.INFO, "UI hierarchy dumped successfully as plain text");
          return {
            content: [{ type: "text" as const, text: xmlData }]
          };
        }
      } catch (error) {
        const errorMsg = error instanceof Error ? error.message : String(error);
        log(LogLevel.ERROR, `Error dumping UI hierarchy: ${errorMsg}`);
        return {
          content: [{ type: "text" as const, text: `Error dumping UI hierarchy: ${errorMsg}` }],
          isError: true
        };
      } finally {
        // Clean up the temporary file
        await cleanupTempFile(tempFilePath);
      }
    },
  • src/index.ts:421-475 (registration)
    The MCP server.tool registration for the inspect_ui tool, specifying name, input schema shape, handler function, and description.
    server.tool(
      "inspect_ui",
      AdbUidumpSchema.shape,
      async (args: z.infer<typeof AdbUidumpSchema>, _extra: RequestHandlerExtra) => {
        log(LogLevel.INFO, "Dumping UI hierarchy");
        
        const deviceArgs = buildDeviceArgs(args.device);
        const tempFilePath = createTempFilePath("adb-mcp", "window_dump.xml");
        const remotePath = args.outputPath && args.outputPath.trim()
          ? args.outputPath.trim()
          : "/sdcard/window_dump.xml";
        
        try {
          // Dump UI hierarchy on device
          await runAdb([...deviceArgs, "shell", "uiautomator", "dump", remotePath]);
          
          // Pull the UI dump from the device
          await runAdb([...deviceArgs, "pull", remotePath, tempFilePath]);
          
          // Clean up the remote file
          await runAdb([...deviceArgs, "shell", "rm", remotePath]);
          
          // Return the UI dump
          if (args.asBase64 !== false) {
            // Return as base64 (default)
            const xmlData = await readFilePromise(tempFilePath);
            const base64Xml = xmlData.toString('base64');
            
            log(LogLevel.INFO, "UI hierarchy dumped successfully as base64");
            return {
              content: [{ type: "text" as const, text: base64Xml }]
            };
          } else {
            // Return as plain text
            const xmlData = await readFilePromise(tempFilePath, 'utf8');
            
            log(LogLevel.INFO, "UI hierarchy dumped successfully as plain text");
            return {
              content: [{ type: "text" as const, text: xmlData }]
            };
          }
        } catch (error) {
          const errorMsg = error instanceof Error ? error.message : String(error);
          log(LogLevel.ERROR, `Error dumping UI hierarchy: ${errorMsg}`);
          return {
            content: [{ type: "text" as const, text: `Error dumping UI hierarchy: ${errorMsg}` }],
            isError: true
          };
        } finally {
          // Clean up the temporary file
          await cleanupTempFile(tempFilePath);
        }
      },
      { description: INSPECT_UI_TOOL_DESCRIPTION }
    );
  • Input schema object for inspect_ui tool parameters: optional device ID, output path on device, and flag for base64 encoding.
    export const inspectUiInputSchema = {
      device: z.string().optional().describe("Specific device ID (optional)"),
      outputPath: z.string().optional().describe("Custom output path on device (default: /sdcard/window_dump.xml)"),
      asBase64: z.boolean().optional().default(false).describe("Return XML content as base64 (default: false)")
    };
  • Zod schema object wrapping inspectUiInputSchema, used in tool registration as AdbUidumpSchema.shape.
    export const AdbUidumpSchema = z.object(inspectUiInputSchema);
  • Detailed tool description string used in the inspect_ui tool registration.
    const INSPECT_UI_TOOL_DESCRIPTION = 
      "Captures the complete UI hierarchy of the current screen as an XML document. " +
      "This provides structured XML data that can be parsed to identify UI elements and their properties. " +
      "Essential for UI automation, determining current app state, and identifying interactive elements. " +
      "Returns the UI structure including all elements, their IDs, text values, bounds, and clickable states. " +
      "This is significantly more useful than screenshots for AI processing and automation tasks.";
Behavior1/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Tool has no description.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness1/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Tool has no description.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness1/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Tool has no description.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Tool has no description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose1/5

Does the description clearly state what the tool does and how it differs from similar tools?

Tool has no description.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines1/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Tool has no description.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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

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