Skip to main content
Glama

evaluate_xpath

Evaluate XPath expressions to locate and extract specific DOM elements from web pages for debugging, testing, and data extraction workflows.

Instructions

Avalia uma expressão XPath e retorna os elementos correspondentes

Input Schema

NameRequiredDescriptionDefault
xpathYesExpressão XPath

Input Schema (JSON Schema)

{ "properties": { "xpath": { "description": "Expressão XPath", "type": "string" } }, "required": [ "xpath" ], "type": "object" }

Implementation Reference

  • Main handler function that executes XPath evaluation on the current browser page using Puppeteer's evaluate method with document.evaluate. Returns count and summaries of matching elements (tagName, truncated textContent, outerHTML).
    export async function handleEvaluateXPath(args: unknown, currentPage: Page): Promise<ToolResponse> { const typedArgs = args as unknown as EvaluateXPathArgs; const { xpath } = typedArgs; const elements = await currentPage.evaluate((xp: string) => { const result = document.evaluate( xp, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null ); const nodes = []; for (let i = 0; i < result.snapshotLength; i++) { const node = result.snapshotItem(i) as Element; nodes.push({ tagName: node.tagName, textContent: (node.textContent || '').substring(0, 100), outerHTML: node.outerHTML.substring(0, 200), }); } return nodes; }, xpath); return { content: [ { type: 'text', text: JSON.stringify( { count: elements.length, elements: elements, }, null, 2 ), }, ], }; }
  • TypeScript interface defining the input arguments for the evaluate_xpath tool: requires 'xpath' string.
    export interface EvaluateXPathArgs { xpath: string; }
  • JSON schema definition for the tool's input in the tools registry, matching the TypeScript type.
    inputSchema: { type: 'object', properties: { xpath: { type: 'string', description: 'Expressão XPath', }, }, required: ['xpath'], },
  • src/tools.ts:250-263 (registration)
    Tool registration object in the exported tools array, including name, description, and inputSchema. Used by MCP listTools.
    { name: 'evaluate_xpath', description: 'Avalia uma expressão XPath e retorna os elementos correspondentes', inputSchema: { type: 'object', properties: { xpath: { type: 'string', description: 'Expressão XPath', }, }, required: ['xpath'], }, },
  • src/index.ts:119-122 (registration)
    Dispatch logic in the main MCP server request handler (CallToolRequestSchema) that initializes browser page and calls the handler for evaluate_xpath.
    case 'evaluate_xpath': { const currentPage = await initBrowser(); return await handleEvaluateXPath(args, currentPage); }

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