Skip to main content
Glama

get-element-properties

Retrieve properties and state information from DOM elements using CSS selectors to inspect values, checked status, text content, and other attributes during development.

Instructions

Retrieves properties and state information of a specific element

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
selectorYesCSS selector of the element to inspect
propertiesYesArray of property names to retrieve (e.g., ['value', 'checked', 'textContent'])

Implementation Reference

  • The handler function for the 'get-element-properties' tool. It validates browser context, waits for the element, uses page.evaluate to extract specified properties from the DOM element, and returns a JSON-formatted result with checkpoint ID.
    server.tool(
      'get-element-properties',
      'Retrieves properties and state information of a specific element',
      {
        selector: z.string().describe('CSS selector of the element to inspect'),
        properties: z.array(z.string()).describe("Array of property names to retrieve (e.g., ['value', 'checked', 'textContent'])")
      },
      async ({ selector, properties }) => {
        try {
          // Check browser status
          const browserStatus = getContextForOperation();
          if (!browserStatus.isStarted) {
            return browserStatus.error;
          }
    
          // Get current checkpoint ID
          const checkpointId = await getCurrentCheckpointId(browserStatus.page);
    
          // Check if element exists
          await browserStatus.page.waitForSelector(selector, { state: 'visible', timeout: 5000 });
    
          // Retrieve element properties
          const elementProperties = await browserStatus.page.evaluate(({ selector, propertiesToGet }: { selector: string; propertiesToGet: string[] }) => {
            const element = document.querySelector(selector);
            if (!element) return null;
    
            const result: Record<string, unknown> = {};
            propertiesToGet.forEach((prop: string) => {
              result[prop] = (element as unknown as Record<string, unknown>)[prop];
            });
            return result;
          }, { selector, propertiesToGet: properties });
    
          if (!elementProperties) {
            return {
              content: [
                {
                  type: 'text',
                  text: `Element with selector "${selector}" not found`
                }
              ],
              isError: true
            };
          }
    
          // Result message construction
          const resultMessage = {
            selector,
            properties: elementProperties,
            checkpointId
          };
    
          return {
            content: [
              {
                type: 'text',
                text: JSON.stringify(resultMessage, null, 2)
              }
            ]
          };
        } catch (error) {
          const errorMessage = error instanceof Error ? error.message : String(error);
          Logger.error(`Failed to get element properties: ${errorMessage}`);
          return {
            content: [
              {
                type: 'text',
                text: `Failed to get element properties: ${errorMessage}`
              }
            ],
            isError: true
          };
        }
      }
    );
  • Input schema for the get-element-properties tool using Zod validation: requires 'selector' (CSS selector) and 'properties' (array of property names).
    {
      selector: z.string().describe('CSS selector of the element to inspect'),
      properties: z.array(z.string()).describe("Array of property names to retrieve (e.g., ['value', 'checked', 'textContent'])")
    },
  • Registration of the 'get-element-properties' tool using server.tool() call within registerBrowserTools function, making it available to the MCP server.
    server.tool(
      'get-element-properties',
      'Retrieves properties and state information of a specific element',
      {
        selector: z.string().describe('CSS selector of the element to inspect'),
        properties: z.array(z.string()).describe("Array of property names to retrieve (e.g., ['value', 'checked', 'textContent'])")
      },
      async ({ selector, properties }) => {
        try {
          // Check browser status
          const browserStatus = getContextForOperation();
          if (!browserStatus.isStarted) {
            return browserStatus.error;
          }
    
          // Get current checkpoint ID
          const checkpointId = await getCurrentCheckpointId(browserStatus.page);
    
          // Check if element exists
          await browserStatus.page.waitForSelector(selector, { state: 'visible', timeout: 5000 });
    
          // Retrieve element properties
          const elementProperties = await browserStatus.page.evaluate(({ selector, propertiesToGet }: { selector: string; propertiesToGet: string[] }) => {
            const element = document.querySelector(selector);
            if (!element) return null;
    
            const result: Record<string, unknown> = {};
            propertiesToGet.forEach((prop: string) => {
              result[prop] = (element as unknown as Record<string, unknown>)[prop];
            });
            return result;
          }, { selector, propertiesToGet: properties });
    
          if (!elementProperties) {
            return {
              content: [
                {
                  type: 'text',
                  text: `Element with selector "${selector}" not found`
                }
              ],
              isError: true
            };
          }
    
          // Result message construction
          const resultMessage = {
            selector,
            properties: elementProperties,
            checkpointId
          };
    
          return {
            content: [
              {
                type: 'text',
                text: JSON.stringify(resultMessage, null, 2)
              }
            ]
          };
        } catch (error) {
          const errorMessage = error instanceof Error ? error.message : String(error);
          Logger.error(`Failed to get element properties: ${errorMessage}`);
          return {
            content: [
              {
                type: 'text',
                text: `Failed to get element properties: ${errorMessage}`
              }
            ],
            isError: true
          };
        }
      }
    );
  • Helper utility getContextForOperation used by get-element-properties to retrieve the active browser page context or return an error response if no suitable browser available.
    const getContextForOperation = (contextId?: string): BrowserStatus => {
      let contextInstance;
      
      if (contextId) {
        contextInstance = contextManager.getContext(contextId);
        if (!contextInstance) {
          return {
            isStarted: false,
            error: {
              content: [
                {
                  type: 'text',
                  text: `Browser '${contextId}' not found. Use 'list-browsers' to see available browsers or 'start-browser' to create one.`
                }
              ],
              isError: true
            }
          };
        }
      } else {
        contextInstance = contextManager.getMostRecentContext();
        if (!contextInstance) {
          return {
            isStarted: false,
            error: {
              content: [
                {
                  type: 'text',
                  text: 'No active browsers found. Use \'start-browser\' to create a browser first.'
                }
              ],
              isError: true
            }
          };
        }
      }
    
      // Note: contextInstance.page is now always defined (never null)
    
      return { isStarted: true, page: contextInstance.page };
    };
  • Helper utility getCurrentCheckpointId used to extract the current checkpoint ID from a meta tag in the page for including in tool responses.
    const getCurrentCheckpointId = async (page: Page) => {
      const checkpointId = await page.evaluate(() => {
        const metaTag = document.querySelector('meta[name="__mcp_checkpoint"]');
        return metaTag ? metaTag.getAttribute('data-id') : null;
      });
      return checkpointId;
    };
Behavior2/5

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

No annotations are provided, so the description carries full burden. It states this is a retrieval operation, implying read-only behavior, but doesn't disclose important behavioral traits like whether it requires an active browser context, potential performance impacts, error handling, or what happens if the selector doesn't match. For a tool with zero annotation coverage, this leaves significant gaps.

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 that states the core purpose without unnecessary words. It's appropriately sized and front-loaded with the essential information.

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 the complexity of browser automation and the lack of both annotations and output schema, the description is insufficient. It doesn't explain what 'properties and state information' includes, what format the response takes, or any prerequisites (like needing an active browser session). For a tool in this domain with rich sibling tools, more context is needed.

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%, with both parameters clearly documented in the schema. The description adds no additional parameter semantics beyond what's already in the schema descriptions. This meets the baseline of 3 when schema coverage is high, but doesn't provide extra value.

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 ('Retrieves') and resource ('properties and state information of a specific element'), making the purpose understandable. However, it doesn't explicitly differentiate from sibling tools like 'get-element-dimensions' or 'get-element-styles', which likely retrieve different types of element information.

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?

The description provides no guidance on when to use this tool versus alternatives like 'get-element-dimensions' or 'get-element-styles'. It mentions retrieving 'properties and state information' but doesn't clarify what distinguishes this from other element inspection tools in the sibling list.

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/ESnark/blowback'

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