Skip to main content
Glama

get-element-dimensions

Retrieve dimension and position data for web elements using CSS selectors to inspect layout and spacing in real-time development environments.

Instructions

Retrieves dimension and position information of a specific element

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
selectorYesCSS selector of the element to inspect

Implementation Reference

  • Registration of the 'get-element-dimensions' MCP tool using server.tool, including description, input schema, and handler function.
    server.tool(
      'get-element-dimensions',
      'Retrieves dimension and position information of a specific element',
      {
        selector: z.string().describe('CSS selector of the element to inspect')
      },
      async ({ selector }) => {
        try {
          // Check browser status
          const browserStatus = getContextForOperation();
          if (!browserStatus.isStarted) {
            return browserStatus.error;
          }
    
          // Get current checkpoint ID
          const checkpointId = await getCurrentCheckpointId(browserStatus.page);
    
          // Retrieve element dimensions and position information
          const dimensions = await browserStatus.page.evaluate((selector: string) => {
            const element = document.querySelector(selector);
            if (!element) return null;
    
            const rect = element.getBoundingClientRect();
            return {
              width: rect.width,
              height: rect.height,
              top: rect.top,
              left: rect.left,
              bottom: rect.bottom,
              right: rect.right,
              x: rect.x,
              y: rect.y,
              isVisible: !!(
                rect.width &&
                rect.height &&
                window.getComputedStyle(element).display !== 'none' &&
                window.getComputedStyle(element).visibility !== 'hidden'
              )
            };
          }, selector);
    
          if (!dimensions) {
            return {
              content: [
                {
                  type: 'text',
                  text: `Element with selector "${selector}" not found`
                }
              ],
              isError: true
            };
          }
    
          // Result message construction
          const resultMessage = {
            selector,
            dimensions,
            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 dimensions: ${errorMessage}`);
          return {
            content: [
              {
                type: 'text',
                text: `Failed to get element dimensions: ${errorMessage}`
              }
            ],
            isError: true
          };
        }
      }
    );
  • The core handler logic: validates browser context, evaluates getBoundingClientRect() on the element to get dimensions and position, checks visibility, and formats the response with checkpoint ID.
      async ({ selector }) => {
        try {
          // Check browser status
          const browserStatus = getContextForOperation();
          if (!browserStatus.isStarted) {
            return browserStatus.error;
          }
    
          // Get current checkpoint ID
          const checkpointId = await getCurrentCheckpointId(browserStatus.page);
    
          // Retrieve element dimensions and position information
          const dimensions = await browserStatus.page.evaluate((selector: string) => {
            const element = document.querySelector(selector);
            if (!element) return null;
    
            const rect = element.getBoundingClientRect();
            return {
              width: rect.width,
              height: rect.height,
              top: rect.top,
              left: rect.left,
              bottom: rect.bottom,
              right: rect.right,
              x: rect.x,
              y: rect.y,
              isVisible: !!(
                rect.width &&
                rect.height &&
                window.getComputedStyle(element).display !== 'none' &&
                window.getComputedStyle(element).visibility !== 'hidden'
              )
            };
          }, selector);
    
          if (!dimensions) {
            return {
              content: [
                {
                  type: 'text',
                  text: `Element with selector "${selector}" not found`
                }
              ],
              isError: true
            };
          }
    
          // Result message construction
          const resultMessage = {
            selector,
            dimensions,
            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 dimensions: ${errorMessage}`);
          return {
            content: [
              {
                type: 'text',
                text: `Failed to get element dimensions: ${errorMessage}`
              }
            ],
            isError: true
          };
        }
      }
    );
  • Input schema validation using Zod: requires a single 'selector' parameter (CSS selector).
    {
      selector: z.string().describe('CSS selector of the element to inspect')
    },
  • src/tools/index.ts:1-2 (registration)
    Re-export of browser-tools module, making the get-element-dimensions tool available for import and registration.
    export * from './browser-tools.js';
    export * from './log-manager.js';
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states what the tool does but lacks critical details: whether it requires an active browser session, if it returns specific metrics (e.g., pixels, percentages), potential errors (e.g., element not found), or performance implications. For a tool with no annotation coverage, this is a significant gap.

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 front-loads the core action ('retrieves') and target information. There is zero wasted verbiage, and every word earns its place by specifying the exact type of data returned. It's appropriately sized for a simple tool.

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 lack of annotations or output schema, the description is incomplete. It doesn't address behavioral aspects like session requirements, error handling, or return format. For a tool that likely interacts with a dynamic browser environment, more context is needed to ensure reliable use.

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 the single parameter 'selector' fully documented in the schema. The description adds no additional parameter semantics beyond implying the element must be locatable via CSS selector. Since the schema does the heavy lifting, the baseline score of 3 is appropriate.

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 ('dimension and position information of a specific element'), making the purpose immediately understandable. It distinguishes from siblings like get-element-html or get-element-styles by specifying the type of information retrieved. However, it doesn't explicitly contrast with all sibling tools, keeping it at 4 rather than 5.

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. It doesn't mention prerequisites (e.g., needing an active browser context), compare to similar tools like get-element-properties, or specify scenarios where this is preferred. Without any usage context, the agent must infer from the name alone.

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