query_selector_all
Find all HTML elements matching a CSS selector to inspect and analyze webpage structure for debugging and testing purposes.
Instructions
Busca todos os elementos que correspondem ao seletor CSS
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Limitar número de resultados | |
| selector | Yes | Seletor CSS |
Implementation Reference
- src/browserTools.ts:395-432 (handler)The handler function that performs querySelectorAll on the current page using Puppeteer, limits results, summarizes elements (tag, class, id, text, outerHTML), and returns JSON with count and elements list.export async function handleQuerySelectorAll( args: unknown, currentPage: Page ): Promise<ToolResponse> { const typedArgs = args as unknown as QuerySelectorAllArgs; const { selector, limit = 100 } = typedArgs; const elements = await currentPage.evaluate( (sel: string, lim: number): ElementSummary[] => { const elements = Array.from(document.querySelectorAll(sel)); return elements.slice(0, lim).map((el) => ({ tagName: el.tagName, className: (el as HTMLElement).className || '', id: (el as HTMLElement).id || '', textContent: (el.textContent || '').substring(0, 100), outerHTML: el.outerHTML.substring(0, 200), })); }, selector, limit ); return { content: [ { type: 'text', text: JSON.stringify( { count: elements.length, elements: elements, }, null, 2 ), }, ], }; }
- src/tools.ts:165-182 (registration)Tool registration in the tools array, defining name, description, and input schema for MCP.{ name: 'query_selector_all', description: 'Busca todos os elementos que correspondem ao seletor CSS', inputSchema: { type: 'object', properties: { selector: { type: 'string', description: 'Seletor CSS', }, limit: { type: 'number', description: 'Limitar número de resultados', default: 100, }, }, required: ['selector'], },
- src/types.ts:70-73 (schema)TypeScript interface defining the input arguments for the query_selector_all tool.export interface QuerySelectorAllArgs { selector: string; limit?: number; }
- src/index.ts:95-98 (registration)Dispatch case in the main tool handler switch statement that initializes the browser page and calls the specific handler.case 'query_selector_all': { const currentPage = await initBrowser(); return await handleQuerySelectorAll(args, currentPage); }
- src/types.ts:150-156 (schema)TypeScript interface for the summarized element data returned by the handler.export interface ElementSummary { tagName: string; className: string; id: string; textContent: string; outerHTML: string; }