Skip to main content
Glama

get_element

Inspect specific web elements using CSS selectors to retrieve computed styles, attributes, and DOM properties for debugging and analysis.

Instructions

Inspeciona um elemento específico usando seletor CSS

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
includeAttributesNoIncluir todos os atributos do elemento
includeStylesNoIncluir estilos computados do elemento
selectorYesSeletor CSS do elemento (ex: '#id', '.class', 'div.container')

Implementation Reference

  • The handler function that executes the get_element tool: queries the DOM for the selector, extracts tag, HTML, text, attributes, computed styles, and bounding box using page.evaluate, returns JSON or error.
    export async function handleGetElement(args: unknown, currentPage: Page): Promise<ToolResponse> {
      const typedArgs = args as unknown as GetElementArgs;
      const { selector, includeStyles = true, includeAttributes = true } = typedArgs;
    
      const elementInfo = await currentPage.evaluate(
        (sel: string, incStyles: boolean, incAttrs: boolean): ElementInfo | null => {
          const element = document.querySelector(sel);
          if (!element) return null;
    
          const info: ElementInfo = {
            tagName: element.tagName,
            innerHTML: element.innerHTML,
            outerHTML: element.outerHTML,
            textContent: element.textContent || '',
            boundingBox: { x: 0, y: 0, width: 0, height: 0 },
          };
    
          if (incAttrs) {
            info.attributes = {};
            for (let i = 0; i < element.attributes.length; i++) {
              const attr = element.attributes[i];
              info.attributes[attr.name] = attr.value;
            }
          }
    
          if (incStyles) {
            const styles = window.getComputedStyle(element);
            info.computedStyles = {};
            for (let i = 0; i < styles.length; i++) {
              const prop = styles[i];
              info.computedStyles[prop] = styles.getPropertyValue(prop);
            }
          }
    
          const rect = element.getBoundingClientRect();
          info.boundingBox = {
            x: rect.x,
            y: rect.y,
            width: rect.width,
            height: rect.height,
          };
    
          return info;
        },
        selector,
        includeStyles,
        includeAttributes
      );
    
      if (!elementInfo) {
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify({ error: `Elemento não encontrado: ${selector}` }, null, 2),
            },
          ],
        };
      }
    
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(elementInfo, null, 2),
          },
        ],
      };
    }
  • TypeScript interface defining the input parameters for the get_element tool.
    export interface GetElementArgs {
      selector: string;
      includeStyles?: boolean;
      includeAttributes?: boolean;
    }
  • src/tools.ts:42-63 (registration)
    MCP tool definition and input schema registration for get_element in the tools array.
    name: 'get_element',
    description: 'Inspeciona um elemento específico usando seletor CSS',
    inputSchema: {
      type: 'object',
      properties: {
        selector: {
          type: 'string',
          description: "Seletor CSS do elemento (ex: '#id', '.class', 'div.container')",
        },
        includeStyles: {
          type: 'boolean',
          description: 'Incluir estilos computados do elemento',
          default: true,
        },
        includeAttributes: {
          type: 'boolean',
          description: 'Incluir todos os atributos do elemento',
          default: true,
        },
      },
      required: ['selector'],
    },
  • src/index.ts:75-77 (registration)
    Dispatch/registration in the main switch case handler for calling the get_element tool handler.
    case 'get_element': {
      const currentPage = await initBrowser();
      return await handleGetElement(args, currentPage);
  • TypeScript interface for the output structure returned by the get_element handler.
    export interface ElementInfo {
      tagName: string;
      innerHTML: string;
      outerHTML: string;
      textContent: string;
      attributes?: Record<string, string>;
      computedStyles?: Record<string, string>;
      boundingBox: {
        x: number;
        y: number;
        width: number;
        height: number;
      };
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 the action ('inspeciona') but doesn't disclose behavioral traits like what information is returned, whether it waits for element existence, error handling for non-existent selectors, or performance characteristics. The description is minimal and lacks operational 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?

Single sentence, zero waste. Every word contributes to the core purpose. The description is 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?

For a tool with 3 parameters, no annotations, and no output schema, the description is insufficient. It doesn't explain what 'inspeciona' returns (element properties, HTML, etc.), doesn't mention the optional parameters' effects, and provides no context about the inspection scope or limitations.

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 all parameters are documented in the schema. The description doesn't add any parameter semantics beyond what's in the schema - it mentions CSS selectors but the schema already provides selector examples. Baseline 3 is appropriate when schema does the heavy lifting.

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 ('Inspeciona' - inspects/examines) and resource ('um elemento específico' - a specific element) with the method ('usando seletor CSS' - using CSS selector). It distinguishes from siblings like get_dom (entire DOM) and get_page_source (full HTML), but doesn't explicitly differentiate from query_selector_all (which likely returns multiple elements).

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 like query_selector_all, evaluate_xpath, or get_dom. The description implies it's for inspecting a single element with CSS selectors, but doesn't provide context about when this is preferable to other element retrieval methods.

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/EmmanuelBarbosaMonteiro/mcp-server-browser'

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