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;
    }
Behavior3/5

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

The annotations already declare readOnlyHint=true, indicating this is a safe read operation. The description adds useful behavioral context beyond annotations by specifying 'Do not cache this result,' which informs the agent about data freshness expectations. However, it does not describe other behavioral traits like performance characteristics, error conditions, or output format details.

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 extremely concise and front-loaded, consisting of just two sentences that directly convey the tool's purpose and a key behavioral instruction ('Do not cache this result'). Every word earns its place with no redundant or vague phrasing.

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?

Given the tool's moderate complexity (listing UI elements), the presence of annotations (readOnlyHint=true), and the lack of an output schema, the description is mostly complete. It clearly states what the tool does and adds a behavioral note, but it does not describe the structure or format of the returned element list, which could be helpful for an agent to interpret results.

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 has 100% description coverage, with the device parameter fully documented in the schema itself. The description does not add any additional meaning or details about the device parameter beyond what the schema provides, so it meets the baseline of 3 for high schema coverage without compensating value.

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 specific action ('List elements on screen'), the resource ('elements'), and the output details ('coordinates, with display text or accessibility label'). It distinguishes from siblings like mobile_click_on_screen_at_coordinates (which interacts with elements) and mobile_get_screen_size (which provides screen dimensions only).

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

Usage Guidelines4/5

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

The description provides clear context for when to use this tool ('List elements on screen and their coordinates'), and the input schema's device parameter description explicitly references the sibling tool mobile_list_available_devices for finding devices. However, it does not explicitly state when NOT to use this tool or compare it to all alternatives like mobile_take_screenshot for visual inspection.

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/EmpathySlainLovers/MCP'

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