get_accessibility_tree
Retrieve the raw accessibility tree of a web page as structured JSON, optionally filtered by a CSS selector.
Instructions
Get the raw accessibility tree as structured JSON. Companion to browser_snapshot which returns formatted text. Optionally filter to a subtree with a selector.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| selector | No | CSS selector to filter to a subtree | |
| tabId | No | Target tab ID (defaults to currently active tab) | |
| apiKey | No | API key for authentication if enabled |
Implementation Reference
- src/tools/accessibility.ts:124-145 (registration)Registration of the 'get_accessibility_tree' tool on the MCP server. It registers using server.tool() with name 'get_accessibility_tree', description, Zod schema (selector, tabId, apiKey), and an async handler that delegates to bridge.sendCommand.
server.tool( 'get_accessibility_tree', 'Get the raw accessibility tree as structured JSON. Companion to browser_snapshot which returns formatted text. Optionally filter to a subtree with a selector.', { selector: z.string().optional().describe('CSS selector to filter to a subtree'), tabId: z.number().optional().describe('Target tab ID (defaults to currently active tab)'), apiKey: z.string().optional().describe('API key for authentication if enabled'), }, async ({ selector, tabId, apiKey }) => { const result = await bridge.sendCommand({ command: 'get_accessibility_tree', params: { selector }, tabId, apiKey, timeout: LONG_TIMEOUT, }); if (!result.success) { return { content: [{ type: 'text', text: `Error: ${result.error?.message}` }], isError: true }; } return { content: [{ type: 'text', text: JSON.stringify(result.data, null, 2) }] }; } ); - src/tools/accessibility.ts:132-144 (handler)Handler function for 'get_accessibility_tree'. It sends a command with name 'get_accessibility_tree' and an optional 'selector' parameter via the WebSocket bridge, then returns the result as formatted JSON.
async ({ selector, tabId, apiKey }) => { const result = await bridge.sendCommand({ command: 'get_accessibility_tree', params: { selector }, tabId, apiKey, timeout: LONG_TIMEOUT, }); if (!result.success) { return { content: [{ type: 'text', text: `Error: ${result.error?.message}` }], isError: true }; } return { content: [{ type: 'text', text: JSON.stringify(result.data, null, 2) }] }; } - src/tools/accessibility.ts:127-131 (schema)Input schema for 'get_accessibility_tree': optional 'selector' (CSS selector string), optional 'tabId' (number), and optional 'apiKey' (string).
{ selector: z.string().optional().describe('CSS selector to filter to a subtree'), tabId: z.number().optional().describe('Target tab ID (defaults to currently active tab)'), apiKey: z.string().optional().describe('API key for authentication if enabled'), }, - src/websocket-bridge.ts:63-103 (helper)WebSocketBridge.sendCommand() which forwards the command (including 'get_accessibility_tree') to the connected Chrome extension via WebSocket and resolves with the response.
async sendCommand(cmd: BridgeCommand): Promise<BridgeResponse> { if (!this.isConnected()) { return { success: false, error: { code: 'NOT_CONNECTED', message: 'Chrome extension is not connected. Ensure the extension is installed, enabled, and the browser is running.', }, }; } const id = crypto.randomUUID(); const timeout = cmd.timeout ?? DEFAULT_TIMEOUT; return new Promise<BridgeResponse>((resolve, reject) => { const timer = setTimeout(() => { this.pending.delete(id); resolve({ success: false, error: { code: 'TIMEOUT', message: `Command '${cmd.command}' timed out after ${timeout}ms`, }, }); }, timeout); this.pending.set(id, { resolve, reject, timer }); const message = { id, type: 'request', command: cmd.command, params: cmd.params, tabId: cmd.tabId, apiKey: cmd.apiKey, timestamp: Date.now(), }; this.client!.send(JSON.stringify(message)); }); } - src/tools/index.ts:18-18 (registration)Import of registerAccessibilityTools from ./accessibility.js which registers 'get_accessibility_tree' among other tools.
import { registerAccessibilityTools } from './accessibility.js';