Skip to main content
Glama
lxman

Safari MCP Server

by lxman

safari_inspect_element

Inspect DOM elements in Safari to retrieve their properties using CSS selectors, enabling browser automation and developer tool access for AI assistants.

Instructions

Inspect a DOM element and get its properties

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
sessionIdYesSession identifier
selectorYesCSS selector for the element

Implementation Reference

  • Core tool handler implementation: Finds DOM element by CSS selector using Selenium WebDriver, retrieves tag name, truncated text, attributes (via executeScript), and bounding rectangle.
    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 tool handler wrapper: Delegates to SafariDriverManager.inspectElement and formats the result as JSON 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 registration in the ListTools response, defining name, description, and input schema (requires sessionId and selector).
    {
      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']
      }
    },
  • Input schema definition for the tool: object with sessionId (string) and selector (string), both required.
    inputSchema: {
      type: 'object',
      properties: {
        sessionId: { type: 'string', description: 'Session identifier' },
        selector: { type: 'string', description: 'CSS selector for the element' }
      },
      required: ['sessionId', 'selector']
  • Dispatch case in handleToolCall switch statement routing to the inspectElement handler.
    case 'safari_inspect_element':
      return await this.inspectElement(args);
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full burden but provides minimal behavioral insight. It implies a read-only operation ('inspect and get') but doesn't disclose critical traits: whether it requires specific permissions, affects page state, has rate limits, returns structured data, or handles errors. This is inadequate for a tool with potential side effects in a browser context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero waste. It's front-loaded with the core action and outcome, making it easy to parse quickly without unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations and no output schema, the description is incomplete for a tool that interacts with browser sessions. It lacks details on return values (e.g., what properties are retrieved), error conditions, session management requirements, and how it fits within the sibling tool ecosystem, leaving significant gaps for an AI agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents both parameters ('sessionId' and 'selector'). The description adds no additional meaning beyond implying these are used for inspection, maintaining the baseline score of 3 where the schema handles parameter documentation effectively.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('inspect') and resource ('DOM element') with the outcome ('get its properties'). It distinguishes from most siblings (e.g., screenshot, navigation, logs) but doesn't explicitly differentiate from similar inspection tools like 'safari_get_page_info' or 'safari_execute_script', which might also retrieve element data.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use this tool versus alternatives is provided. It doesn't mention prerequisites (e.g., needing an active session), compare to siblings like 'safari_get_page_info' for broader page data, or specify contexts where element inspection is appropriate versus script execution.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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