resolve_uid_to_selector
Convert UIDs from browser snapshots into CSS selectors for automated testing and web scraping with Firefox DevTools.
Instructions
Resolve UID to CSS selector. Fails if stale.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| uid | Yes | UID from snapshot |
Implementation Reference
- src/tools/snapshot.ts:130-162 (handler)MCP tool handler: validates uid input, retrieves Firefox instance, calls resolveUidToSelector on it, returns selector or handles stale UID errors with user-friendly message.export async function handleResolveUidToSelector(args: unknown): Promise<McpToolResponse> { try { const { uid } = args as { uid: string }; if (!uid || typeof uid !== 'string') { throw new Error('uid parameter is required and must be a string'); } const { getFirefox } = await import('../index.js'); const firefox = await getFirefox(); try { const selector = firefox.resolveUidToSelector(uid); return successResponse(`${uid} → ${selector}`); } catch (error) { const errorMsg = (error as Error).message; // Concise error for stale UIDs if ( errorMsg.includes('stale') || errorMsg.includes('Snapshot') || errorMsg.includes('UID') || errorMsg.includes('not found') ) { throw new Error(`UID "${uid}" stale/invalid. Call take_snapshot first.`); } throw error; } } catch (error) { return errorResponse(error as Error); } }
- src/tools/snapshot.ts:37-50 (schema)MCP tool schema definition including name, description, and inputSchema requiring 'uid' string.export const resolveUidToSelectorTool = { name: 'resolve_uid_to_selector', description: 'Resolve UID to CSS selector. Fails if stale.', inputSchema: { type: 'object', properties: { uid: { type: 'string', description: 'UID from snapshot', }, }, required: ['uid'], }, };
- src/index.ts:126-128 (registration)Registration of the tool handler in the central toolHandlers Map used by the MCP server.['take_snapshot', tools.handleTakeSnapshot], ['resolve_uid_to_selector', tools.handleResolveUidToSelector], ['clear_snapshot', tools.handleClearSnapshot],
- src/index.ts:170-172 (registration)Inclusion of the tool definition in the allTools array returned by listTools.tools.takeSnapshotTool, tools.resolveUidToSelectorTool, tools.clearSnapshotTool,
- src/firefox/index.ts:325-330 (helper)FirefoxClient helper method delegated to by the tool handler, which forwards to SnapshotManager.resolveUidToSelector(uid: string): string { if (!this.snapshot) { throw new Error('Not connected'); } return this.snapshot.resolveUidToSelector(uid); }