Skip to main content
Glama

smart_click

Click Android UI elements using multiple strategies: UIAutomator, Accessibility, Vision, and coordinate fallback for reliable automation.

Instructions

Intelligently click an element using multiple strategies: UIAutomator → Accessibility → Vision → Coordinates fallback. This is the most reliable way to click elements.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
selectorYesElement selector criteria
fallback_xNoFallback X coordinate if all strategies fail
fallback_yNoFallback Y coordinate if all strategies fail
device_idNoDevice serial number

Implementation Reference

  • The core implementation of the `smart_click` tool, which attempts multiple strategies (UIAutomator, Accessibility, Vision, Coordinates) to click an element.
    export async function smartClick(
      selector: ElementSelector,
      fallbackCoordinates?: { x: number; y: number },
      deviceId?: string
    ): Promise<SmartClickResult> {
      const resolved = await deviceManager.resolveDeviceId(deviceId);
      deviceManager.checkRateLimit(resolved);
    
      const strategyChain: SmartClickResult['strategyChain'] = [];
    
      // Strategy 1: UIAutomator
      try {
        log.debug('Attempting UIAutomator click', { selector });
        const element = await clickElement(selector, resolved);
        strategyChain.push({ method: 'uiautomator', attempted: true, succeeded: true });
        return {
          success: true,
          method: 'uiautomator',
          element,
          coordinates: { x: element.bounds.centerX, y: element.bounds.centerY },
          requiresVerification: false,
          strategyChain,
        };
      } catch (uiError) {
        const reason = uiError instanceof Error ? uiError.message : String(uiError);
        strategyChain.push({ method: 'uiautomator', attempted: true, succeeded: false, failureReason: reason });
        log.debug('UIAutomator failed', { error: reason });
      }
    
      // Strategy 2: Accessibility fallback
      try {
        log.debug('Attempting Accessibility-based search', { selector });
        const accessibilityData = await getAccessibilityTree(resolved);
    
        const searchText = selector.text || selector.contentDesc || selector.textContains || '';
        if (searchText && accessibilityData.includes(searchText)) {
          await new Promise(resolve => setTimeout(resolve, 500));
          try {
            const element = await clickElement(selector, resolved);
            strategyChain.push({ method: 'accessibility', attempted: true, succeeded: true });
            return {
              success: true,
              method: 'accessibility',
              element,
              coordinates: { x: element.bounds.centerX, y: element.bounds.centerY },
              requiresVerification: false,
              strategyChain,
            };
          } catch {
            strategyChain.push({ method: 'accessibility', attempted: true, succeeded: false, failureReason: 'Element found in accessibility but UIAutomator retry failed' });
          }
        } else {
          strategyChain.push({ method: 'accessibility', attempted: true, succeeded: false, failureReason: 'Element not found in accessibility data' });
        }
      } catch (accError) {
        const reason = accError instanceof Error ? accError.message : String(accError);
        strategyChain.push({ method: 'accessibility', attempted: true, succeeded: false, failureReason: reason });
        log.debug('Accessibility failed', { error: reason });
      }
    
      // Strategy 3: Vision
      try {
        log.debug('Attempting Vision-based detection');
        const analysis = await analyzeScreen(resolved);
    
        if (analysis.uiSummary) {
          const searchText = selector.text || selector.contentDesc || selector.textContains || '';
          if (searchText && analysis.uiSummary.toLowerCase().includes(searchText.toLowerCase())) {
            try {
              const element = await clickElement(selector, resolved);
              strategyChain.push({ method: 'vision', attempted: true, succeeded: true });
              return {
                success: true,
                method: 'vision',
                element,
                coordinates: { x: element.bounds.centerX, y: element.bounds.centerY },
                requiresVerification: false,
                strategyChain,
              };
            } catch {
              strategyChain.push({ method: 'vision', attempted: true, succeeded: false, failureReason: 'Element visible in analysis but click failed' });
            }
          } else {
            strategyChain.push({ method: 'vision', attempted: true, succeeded: false, failureReason: 'Element not found in visual analysis' });
          }
        } else {
          strategyChain.push({ method: 'vision', attempted: true, succeeded: false, failureReason: 'No UI summary available' });
        }
      } catch (visionError) {
        const reason = visionError instanceof Error ? visionError.message : String(visionError);
        strategyChain.push({ method: 'vision', attempted: true, succeeded: false, failureReason: reason });
        log.debug('Vision failed', { error: reason });
      }
    
      // Strategy 4: Raw coordinates fallback
      if (fallbackCoordinates) {
        log.info('Using fallback coordinates', { fallbackCoordinates });
        await tap(fallbackCoordinates.x, fallbackCoordinates.y, resolved);
        strategyChain.push({ method: 'coordinates', attempted: true, succeeded: true });
        return {
          success: true,
          method: 'coordinates',
          coordinates: fallbackCoordinates,
          fallbackReason: 'All structured methods failed; used fallback coordinates',
          requiresVerification: true, // Coordinate clicks must be verified
          strategyChain,
        };
      }
    
      strategyChain.push({ method: 'coordinates', attempted: false, succeeded: false, failureReason: 'No fallback coordinates provided' });
    
      return {
        success: false,
        method: 'coordinates',
        fallbackReason: 'All strategies failed and no fallback coordinates provided',
        requiresVerification: false,
        strategyChain,
      };
    }
  • The type definition for the result returned by `smartClick`.
    export interface SmartClickResult {
      success: boolean;
      method: ExecutionMethod;
      element?: FoundElement;
      coordinates?: { x: number; y: number };
      fallbackReason?: string;
      /** Whether the result needs verification (true for coordinate-only clicks) */
      requiresVerification: boolean;
      /** Full strategy chain showing what was attempted and why each failed */
      strategyChain: Array<{
        method: ExecutionMethod;
        attempted: boolean;
        succeeded: boolean;
        failureReason?: string;
      }>;
    }
  • The automation controller where the `smart_click` tool is likely registered and invoked.
    return await metrics.measure('smart_click', device_id || 'default', async () => {
      const fallback = (fallback_x !== undefined && fallback_y !== undefined)
        ? { x: fallback_x, y: fallback_y }
        : undefined;
    
      const result = await smartClick(selector as ElementSelector, fallback, device_id);
      return {
Behavior4/5

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

Without annotations, the description carries the full burden and successfully discloses the internal strategy cascade (four fallback methods). However, it omits what happens if all strategies fail (error vs. silent failure) and whether the operation includes implicit waits or verification.

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 consists of two efficient sentences with zero waste. It front-loads the critical technical detail (the strategy cascade) in the first sentence and provides the value proposition ('most reliable') in the second.

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 complex multi-strategy tool with nested parameters and no output schema, the description adequately explains the mechanism. It could be improved by mentioning failure modes or timeout behavior, but the strategy disclosure provides sufficient context for an agent to understand the tool's robustness profile.

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?

With 100% schema coverage, the baseline is 3. The description mentions 'element' (mapping to selector) and 'Coordinates fallback' (mapping to fallback_x/y), but does not add semantic context beyond what the schema already provides for the eight selector sub-properties or device_id.

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 (click) and target (element), and distinguishes itself from sibling tools like click_element and tap by specifying the multi-strategy cascade (UIAutomator → Accessibility → Vision → Coordinates) and claiming it is 'the most reliable way to click elements.'

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

Usage Guidelines3/5

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

The description implies this tool should be used when reliability is needed ('most reliable way'), but lacks explicit guidance on when NOT to use it (e.g., when speed is prioritized over robustness) or when to prefer simpler alternatives like click_element or tap.

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/divineDev-dotcom/android_mcp'

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