Skip to main content
Glama

ui-query

Query Android app UI elements using accessibility trees to dump, find, or check accessibility compliance for testing and debugging purposes.

Instructions

Query app UI. Accessibility-first.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
operationYes
selectorNo
debugNo
maxTierNoMax fallback tier (1-5). Use 3 to stop before visual/grid payloads.
gridCellNo
gridPositionNo
compactNoPaginated flat list (default: true). false for full tree.
limitNoDefault: 20
offsetNo

Implementation Reference

  • The main handler function for the "ui-query" tool, which routes the request to appropriate internal operations (dump, find, or accessibility-check).
    export async function handleUiQueryTool(
      input: UiQueryInput,
      context: ServerContext,
      uiConfig?: UiConfig,
    ): Promise<Record<string, unknown>> {
      const device = await context.deviceState.ensureDevice(context.adb);
      const config = uiConfig ?? DEFAULT_CONFIG.ui;
    
      const handler = operations[input.operation];
      if (!handler) {
        throw new ReplicantError(
          ErrorCode.INVALID_OPERATION,
          `Unknown operation: ${input.operation}`,
          "Valid operations: dump, find, accessibility-check",
        );
      }
      return handler(input, context, config, device.id);
    }
  • Zod schema defining the input structure for the "ui-query" tool.
    export const uiQueryInputSchema = z.object({
      operation: z.enum(["dump", "find", "accessibility-check"]),
      selector: z.object({
        resourceId: z.string().optional(),
        text: z.string().optional(),
        textContains: z.string().optional(),
        className: z.string().optional(),
        nearestTo: z.string().optional(),
      }).optional(),
      debug: z.boolean().optional(),
      maxTier: z.number().min(1).max(5).optional(),
      gridCell: z.number().min(1).max(24).optional(),
      gridPosition: z.number().min(1).max(5).optional(),
      compact: z.boolean().optional(),
      limit: z.number().min(1).max(100).optional(),
      offset: z.number().min(0).optional(),
    });
  • The definition of the "ui-query" tool, including its name, description, and JSON schema for input validation.
    export const uiQueryToolDefinition = {
      name: "ui-query",
      description: "Query app UI. Accessibility-first.",
      inputSchema: {
        type: "object",
        properties: {
          operation: {
            type: "string",
            enum: ["dump", "find", "accessibility-check"],
          },
          selector: {
            type: "object",
            properties: {
              resourceId: { type: "string" },
              text: { type: "string" },
              textContains: { type: "string" },
              className: { type: "string" },
              nearestTo: { type: "string", description: "Find elements nearest to this text (spatial proximity)" },
            },
          },
          debug: { type: "boolean" },
          maxTier: {
            type: "number",
            minimum: 1,
            maximum: 5,
            description: "Max fallback tier (1-5). Use 3 to stop before visual/grid payloads.",
          },
          gridCell: { type: "number", minimum: 1, maximum: 24 },
          gridPosition: { type: "number", minimum: 1, maximum: 5 },
          compact: { type: "boolean", description: "Paginated flat list (default: true). false for full tree." },
          limit: { type: "number", minimum: 1, maximum: 100, description: "Default: 20" },
          offset: { type: "number", minimum: 0 },
        },
        required: ["operation"],
      },
      annotations: {
        readOnlyHint: true,
        destructiveHint: false,
        idempotentHint: true,
        openWorldHint: false,
      },
    };
Behavior3/5

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

With no annotations, the description carries the full burden. 'Accessibility-first' provides some behavioral context (aligns with maxTier's mention of 'visual/grid payloads'), but it omits critical details: whether operations are read-only, what the tier system entails, or what the return format looks like.

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

Conciseness3/5

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

The description is terse and front-loaded with no wasted words, but it is inappropriately sized for a tool with 9 parameters and nested objects. The extreme brevity creates ambiguity rather than efficient communication.

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

Completeness2/5

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

Given the high complexity (9 params, nested selectors, three operation modes) and lack of output schema or annotations, the description is materially incomplete. It does not adequately prepare an agent to construct valid inputs or interpret results.

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

Parameters2/5

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

Schema coverage is low (~33%), requiring the description to compensate for undocumented parameters. It fails to do so, mentioning no parameters and providing no context for the operation enum values, selector object structure, or grid pagination system.

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

Purpose3/5

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

States the general action (Query) and resource (app UI), and 'Accessibility-first' hints at the domain. However, it fails to explain the three distinct operation modes (dump/find/accessibility-check) or what 'querying' specifically returns, making it vague given the schema complexity.

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?

Provides no guidance on when to use this tool versus siblings like ui-action or ui-capture, nor when to use specific operations (dump vs find). No mention of prerequisites or filtering strategies.

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/thecombatwombat/replicant-mcp'

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