Skip to main content
Glama
yashpreetbathla

MCP Accessibility Bridge

Query Accessibility Tree

query_accessibility_tree

Search browser accessibility trees by ARIA role or element name to identify components for testing and auditing. Returns matching nodes with their properties to support framework-agnostic test automation.

Instructions

Search the accessibility tree by ARIA role and/or accessible name. Returns matching nodes with their properties. Example: role="button", accessibleName="Submit" finds all Submit buttons.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
roleNoARIA role to filter by (e.g. "button", "textbox", "link", "heading"). Case-insensitive.
accessibleNameNoAccessible name to match (partial or exact). Case-insensitive.
backendNodeIdNoDOM backend node ID to start search from (narrows scope).

Implementation Reference

  • The queryAccessibilityTreeHandler function implements the core logic: validates that at least role or accessibleName is provided, builds CDP parameters, sends Accessibility.queryAXTree command, filters non-ignored nodes, converts them to summaries using cdpAXNodeToSummary, and returns results.
    export async function queryAccessibilityTreeHandler(args: {
      role?: string;
      accessibleName?: string;
      backendNodeId?: number;
    }): Promise<ReturnType<typeof toolSuccess | typeof toolError>> {
      try {
        const { cdpSession } = browserManager.requireConnection();
    
        if (!args.role && !args.accessibleName) {
          return toolError(
            'At least one of "role" or "accessibleName" must be provided.'
          );
        }
    
        const params: Record<string, unknown> = {};
        if (args.role) params['role'] = args.role;
        if (args.accessibleName) params['accessibleName'] = args.accessibleName;
        if (args.backendNodeId !== undefined) params['backendNodeId'] = args.backendNodeId;
    
        const result = await cdpSession.send(
          'Accessibility.queryAXTree',
          params
        ) as QueryAXTreeResponse;
    
        const nodes = result.nodes ?? [];
        const summaries = nodes
          .filter((n) => !n.ignored)
          .map(cdpAXNodeToSummary);
    
        return toolSuccess({
          query: {
            role: args.role,
            accessibleName: args.accessibleName,
            backendNodeId: args.backendNodeId,
          },
          count: summaries.length,
          nodes: summaries,
        });
      } catch (error) {
        return toolError(error);
      }
    }
  • The queryAccessibilityTreeSchema defines input validation using Zod with three optional parameters: role (ARIA role string, case-insensitive), accessibleName (partial/exact name match, case-insensitive), and backendNodeId (DOM node ID to narrow search scope).
    export const queryAccessibilityTreeSchema = {
      role: z
        .string()
        .optional()
        .describe(
          'ARIA role to filter by (e.g. "button", "textbox", "link", "heading"). ' +
          'Case-insensitive.'
        ),
      accessibleName: z
        .string()
        .optional()
        .describe('Accessible name to match (partial or exact). Case-insensitive.'),
      backendNodeId: z
        .number()
        .int()
        .optional()
        .describe('DOM backend node ID to start search from (narrows scope).'),
    };
  • src/index.ts:76-88 (registration)
    Tool registration with MCP server under the name 'query_accessibility_tree', including title, description explaining it searches by ARIA role/accessible name, and wiring up the schema and handler.
    // ── query_accessibility_tree ─────────────────────────────────────────────────
    server.registerTool(
      'query_accessibility_tree',
      {
        title: 'Query Accessibility Tree',
        description:
          'Search the accessibility tree by ARIA role and/or accessible name. ' +
          'Returns matching nodes with their properties. ' +
          'Example: role="button", accessibleName="Submit" finds all Submit buttons.',
        inputSchema: queryAccessibilityTreeSchema,
      },
      queryAccessibilityTreeHandler
    );
  • The cdpAXNodeToSummary helper function converts raw CDP AX nodes into cleaner AXNodeSummary objects, extracting role, name, description, value, and various boolean properties (focused, disabled, checked, expanded, required, level, backendDOMNodeId).
    export function cdpAXNodeToSummary(node: CdpAXNode): AXNodeSummary {
      const role = (node.role?.value as string) ?? 'unknown';
      const name = (node.name?.value as string) ?? '';
      const description = node.description?.value as string | undefined;
      const value = node.value?.value as string | undefined;
    
      const props = node.properties ?? [];
      const focused = getPropertyValue(props, 'focused') as boolean | undefined;
      const disabled = getPropertyValue(props, 'disabled') as boolean | undefined;
      const checked = getPropertyValue(props, 'checked') as boolean | 'mixed' | undefined;
      const expanded = getPropertyValue(props, 'expanded') as boolean | undefined;
      const required = getPropertyValue(props, 'required') as boolean | undefined;
      const level = getPropertyValue(props, 'level') as number | undefined;
    
      return {
        role,
        name,
        ...(description !== undefined && { description }),
        ...(value !== undefined && { value }),
        ...(focused !== undefined && { focused }),
        ...(disabled !== undefined && { disabled }),
        ...(checked !== undefined && { checked }),
        ...(expanded !== undefined && { expanded }),
        ...(required !== undefined && { required }),
        ...(level !== undefined && { level }),
        ...(node.backendDOMNodeId !== undefined && { backendDOMNodeId: node.backendDOMNodeId }),
        nodeId: node.nodeId,
      };
    }
  • Type definitions for the tool: QueryAXTreeResponse interface (lines 44-47) defines the CDP response with nodes array; AXNodeSummary interface (lines 68-83) defines the simplified output structure with role, name, and optional properties.
    // Accessibility.queryAXTree response
    export interface QueryAXTreeResponse {
      nodes: CdpAXNode[];
    }
    
    // DOM.describeNode response
    export interface DomDescribeNodeResponse {
      node: {
        nodeId: number;
        backendNodeId: number;
        nodeType: number;
        nodeName: string;
        localName: string;
        nodeValue: string;
        attributes?: string[];
        frameId?: string;
      };
    }
    
    // DOM.getOuterHTML response
    export interface DomGetOuterHtmlResponse {
      outerHTML: string;
    }
    
    // Summarized AX node used in tool responses
    export interface AXNodeSummary {
      role: string;
      name: string;
      description?: string;
      value?: string;
      focused?: boolean;
      disabled?: boolean;
      checked?: boolean | 'mixed';
      expanded?: boolean;
      required?: boolean;
      level?: number;
      backendDOMNodeId?: number;
      nodeId: string;
      children?: AXNodeSummary[];
    }
Behavior3/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It describes what the tool does (search by criteria, return matching nodes with properties) and includes useful behavioral details like case-insensitive matching and partial name matching. However, it doesn't mention important aspects like whether all parameters are optional, search scope limitations, performance characteristics, or what specific properties are returned.

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 perfectly concise - two sentences that each earn their place. The first sentence states the core functionality, the second provides a concrete example that reinforces understanding. No wasted words, well-structured, and front-loaded with the essential information.

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

Completeness3/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 (3 parameters, no output schema, no annotations), the description is adequate but has gaps. It explains the search purpose well but doesn't describe the return format (what 'properties' includes), doesn't mention that all parameters are optional (though schema shows this), and doesn't provide context about search scope or limitations. For a search tool with no output schema, more detail about return values would be helpful.

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?

Schema description coverage is 100%, so the schema already documents all three parameters thoroughly. The description adds minimal value beyond the schema - it mentions the same two parameters (role and accessibleName) in the example but doesn't explain the backendNodeId parameter or provide additional semantic context. This meets the baseline expectation when schema coverage is complete.

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 purpose with specific verbs ('Search', 'Returns') and resources ('accessibility tree', 'matching nodes with their properties'). It distinguishes from siblings like 'get_accessibility_tree' (which presumably retrieves the entire tree) by emphasizing search/filtering capabilities. The example further clarifies the specific use case.

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: to search/filter the accessibility tree by ARIA role and/or accessible name. It doesn't explicitly state when NOT to use it or name specific alternatives, but the context implies it's for filtered searches rather than retrieving the full tree (which 'get_accessibility_tree' likely does). No misleading guidance is present.

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/yashpreetbathla/mcp-accessibility-bridge'

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