Skip to main content
Glama

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
NameRequiredDescriptionDefault
limitNoLimitar número de resultados
selectorYesSeletor CSS

Implementation Reference

  • 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'], },
  • 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); }
  • TypeScript interface for the summarized element data returned by the handler.
    export interface ElementSummary { tagName: string; className: string; id: string; textContent: string; outerHTML: string; }

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/EmmanuelBarbosaMonteiro/mcp-server-browser'

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