Skip to main content
Glama

List Screen Elements

mobile_list_elements_on_screen
Read-only

Identify and locate on-screen elements with their coordinates and text labels for mobile automation testing on iOS and Android devices.

Instructions

List elements on screen and their coordinates, with display text or accessibility label. Do not cache this result.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
deviceYesThe device identifier to use. Use mobile_list_available_devices to find which devices are available to you.

Implementation Reference

  • Full tool registration including inline handler function that fetches screen elements via Robot interface, formats them with coordinates and properties, and returns JSON string.
    tool(
    	"mobile_list_elements_on_screen",
    	"List elements on screen and their coordinates, with display text or accessibility label. Do not cache this result.",
    	{
    		noParams
    	},
    	async ({}) => {
    		requireRobot();
    		const elements = await robot!.getElementsOnScreen();
    
    		const result = elements.map(element => {
    			const out: any = {
    				type: element.type,
    				text: element.text,
    				label: element.label,
    				name: element.name,
    				value: element.value,
    				identifier: element.identifier,
    				coordinates: {
    					x: element.rect.x,
    					y: element.rect.y,
    					width: element.rect.width,
    					height: element.rect.height,
    				},
    			};
    
    			if (element.focused) {
    				out.focused = true;
    			}
    
    			return out;
    		});
    
    		return `Found these elements on screen: ${JSON.stringify(result)}`;
    	}
    );
  • Type definition for ScreenElement used in getElementsOnScreen response, defining structure with type, labels, text, rect coordinates, etc.
    export interface ScreenElement {
    	type: string;
    	label?: string;
    	text?: string;
    	name?: string;
    	value?: string;
    	identifier?: string;
    	rect: ScreenElementRect;
    
    	// currently only on android tv
    	focused?: boolean;
    }
  • src/server.ts:277-312 (registration)
    Registration of the tool using the 'tool' helper, with empty input schema (noParams), description, and handler callback.
    tool(
    	"mobile_list_elements_on_screen",
    	"List elements on screen and their coordinates, with display text or accessibility label. Do not cache this result.",
    	{
    		noParams
    	},
    	async ({}) => {
    		requireRobot();
    		const elements = await robot!.getElementsOnScreen();
    
    		const result = elements.map(element => {
    			const out: any = {
    				type: element.type,
    				text: element.text,
    				label: element.label,
    				name: element.name,
    				value: element.value,
    				identifier: element.identifier,
    				coordinates: {
    					x: element.rect.x,
    					y: element.rect.y,
    					width: element.rect.width,
    					height: element.rect.height,
    				},
    			};
    
    			if (element.focused) {
    				out.focused = true;
    			}
    
    			return out;
    		});
    
    		return `Found these elements on screen: ${JSON.stringify(result)}`;
    	}
    );
  • Android-specific implementation of getElementsOnScreen using UiAutomator XML dump parsing and collectElements helper.
    public async getElementsOnScreen(): Promise<ScreenElement[]> {
    	const parsedXml = await this.getUiAutomatorXml();
    	const hierarchy = parsedXml.hierarchy;
    	const elements = this.collectElements(hierarchy.node);
    	return elements;
    }
  • Helper function to recursively collect interactive screen elements from UiAutomator XML hierarchy in Android implementation.
    private collectElements(node: UiAutomatorXmlNode): ScreenElement[] {
    	const elements: Array<ScreenElement> = [];
    
    	if (node.node) {
    		if (Array.isArray(node.node)) {
    			for (const childNode of node.node) {
    				elements.push(...this.collectElements(childNode));
    			}
    		} else {
    			elements.push(...this.collectElements(node.node));
    		}
    	}
    
    	if (node.text || node["content-desc"] || node.hint) {
    		const element: ScreenElement = {
    			type: node.class || "text",
    			text: node.text,
    			label: node["content-desc"] || node.hint || "",
    			rect: this.getScreenElementRect(node),
    		};
    
    		if (node.focused === "true") {
    			// only provide it if it's true, otherwise don't confuse llm
    			element.focused = true;
    		}
    
    		const resourceId = node["resource-id"];
    		if (resourceId !== null && resourceId !== "") {
    			element.identifier = resourceId;
    		}
    
    		if (element.rect.width > 0 && element.rect.height > 0) {
    			elements.push(element);
    		}
    	}
    
    	return elements;
    }

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed4 schema fields changedv1.0.0
    • removedInput schema / additionalProperties
      Removed value: -false
    • addedInput schema / properties / device
      Added value: +{
      +  "description": "The device identifier to use. Use mobile_list_available_devices to find which devices are available to you.",
      +  "type": "string"
      +}
    • removedInput schema / properties / noParams
      Removed value: -{
      -  "additionalProperties": false,
      -  "properties": {},
      -  "type": "object"
      -}
    • changedInput schema / required
      Previous value: -[
      -  "noParams"
      -]New value: +[
      +  "device"
      +]
  2. First observed

TDQS

A3.8/5.0
Behavior4/5

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

Beyond the readOnlyHint, the description adds the specific instruction 'Do not cache this result,' indicating the output is dynamic. It also specifies the output content (coordinates, text/label), providing transparency about what to expect. However, it does not discuss potential failures, required permissions, or return structure, so it's not a 5.

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

Conciseness5/5

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

The description is two concise sentences, front-loaded with the primary action. Every word adds value, with no redundant or fluff content.

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

Completeness4/5

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

For a single-parameter read-only tool with no output schema, the description is fairly complete: it states what is listed (elements, coordinates, text/label) and adds a caching caution. It could benefit from clarifying what qualifies as an 'element' or whether the output is a list, but overall it covers the essential context.

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

Parameters3/5

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

The input schema already provides a complete description of the 'device' parameter, including a pointer to mobile_list_available_devices. The tool description adds no parameter-specific information, but since schema coverage is 100%, the baseline of 3 applies.

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

Purpose5/5

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

The description clearly states the tool's function: listing on-screen elements with coordinates and display text or accessibility label. It distinguishes from sibling tools like mobile_take_screenshot or mobile_get_screen_size by focusing on UI element hierarchy rather than images or dimensions.

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

Usage Guidelines2/5

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

The description does not explicitly state when to use this tool versus alternatives. It only includes 'Do not cache this result,' which is a usage caution, but there is no mention of alternatives or contextual triggers. The schema's parameter description references sibling tool mobile_list_available_devices, but that's for parameter resolution, not tool selection.

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