Skip to main content
Glama

safari_inspect_element

Inspect DOM elements and retrieve their properties using a CSS selector and session ID, enabling browser automation and development tasks with Safari MCP Server.

Instructions

Inspect a DOM element and get its properties

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
selectorYesCSS selector for the element
sessionIdYesSession identifier

Implementation Reference

  • Core handler implementation: Finds the DOM element using Selenium WebDriver's findElement with CSS selector, retrieves tag name, text content, attributes via executeScript, and bounding rectangle. Returns ElementInspectionResult.
    async inspectElement(sessionId: string, selector: string): Promise<ElementInspectionResult> { const session = this.getSession(sessionId); if (!session) { throw new Error(`Session ${sessionId} not found`); } try { const element = await session.driver.findElement(By.css(selector)); const [tagName, text, attributes, boundingRect] = await Promise.all([ element.getTagName(), element.getText(), session.driver.executeScript(` const el = arguments[0]; const attrs = {}; for (let attr of el.attributes) { attrs[attr.name] = attr.value; } return attrs; `, element), session.driver.executeScript(` const rect = arguments[0].getBoundingClientRect(); return { x: rect.x, y: rect.y, width: rect.width, height: rect.height }; `, element) ]); return { tagName, text: text.substring(0, 500), // Limit text length attributes, boundingRect }; } catch (error: unknown) { const errorMessage = error instanceof Error ? error.message : String(error); throw new Error(`Element inspection failed: ${errorMessage}`); } }
  • MCP server wrapper handler: Delegates to SafariDriverManager.inspectElement and formats the result as MCP text content.
    private async inspectElement(args: Record<string, any>): Promise<Array<{ type: string; text: string }>> { const { sessionId, selector } = args; const elementInfo = await this.driverManager.inspectElement(sessionId, selector); return [ { type: 'text', text: `Element inspection for selector '${selector}':\n\n${JSON.stringify(elementInfo, null, 2)}` } ]; }
  • Tool schema definition including input schema with sessionId and selector parameters.
    { name: 'safari_inspect_element', description: 'Inspect a DOM element and get its properties', inputSchema: { type: 'object', properties: { sessionId: { type: 'string', description: 'Session identifier' }, selector: { type: 'string', description: 'CSS selector for the element' } }, required: ['sessionId', 'selector'] } },
  • Tool registration in the handleToolCall switch statement, dispatching to the inspectElement handler.
    case 'safari_inspect_element': return await this.inspectElement(args);

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/lxman/safari-mcp-server'

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