Skip to main content
Glama

viewpo_get_layout_map

Extract the DOM layout tree with element hierarchy, bounding rects, and computed CSS styles from a URL at a specified viewport width to analyze page structure and identify layout issues.

Instructions

Extract the DOM layout tree of a URL at a given viewport width. Returns element hierarchy with tags, classes, bounding rects, and computed CSS styles. Use this to understand page structure and find layout issues.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesThe URL to inspect
viewportNoViewport width in CSS pixels (default: 1920)
selectorNoCSS selector to scope the layout map to a subtree (e.g. ".main-content", "#hero")

Implementation Reference

  • src/index.ts:98-143 (registration)
    MCP tool registration for viewpo_get_layout_map. This includes the tool schema definition (url, viewport, selector parameters with validation) and the async handler that calls client.layoutMap() and returns the JSON result.
    // --- Tool: viewpo_get_layout_map ---
    
    server.tool(
      "viewpo_get_layout_map",
      "Extract the DOM layout tree of a URL at a given viewport width. Returns element hierarchy with tags, classes, bounding rects, and computed CSS styles. Use this to understand page structure and find layout issues.",
      {
        url: z.string().url().describe("The URL to inspect"),
        viewport: z
          .number()
          .int()
          .min(100)
          .max(3840)
          .optional()
          .describe("Viewport width in CSS pixels (default: 1920)"),
        selector: z
          .string()
          .optional()
          .describe(
            'CSS selector to scope the layout map to a subtree (e.g. ".main-content", "#hero")'
          ),
      },
      async ({ url, viewport, selector }) => {
        try {
          const result = await client.layoutMap({ url, viewport, selector });
    
          return {
            content: [
              {
                type: "text" as const,
                text: JSON.stringify(result, null, 2),
              },
            ],
          };
        } catch (error) {
          return {
            content: [
              {
                type: "text" as const,
                text: `Layout map failed: ${error instanceof Error ? error.message : String(error)}`,
              },
            ],
            isError: true,
          };
        }
      }
    );
  • Tool handler function that executes the layout map logic. Calls client.layoutMap() with the provided parameters and returns the result as formatted JSON text with error handling.
    async ({ url, viewport, selector }) => {
      try {
        const result = await client.layoutMap({ url, viewport, selector });
    
        return {
          content: [
            {
              type: "text" as const,
              text: JSON.stringify(result, null, 2),
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text" as const,
              text: `Layout map failed: ${error instanceof Error ? error.message : String(error)}`,
            },
          ],
          isError: true,
        };
      }
    }
  • HTTP client method that makes a POST request to the Viewpo bridge API's /layout endpoint. Handles authentication and JSON serialization.
    async layoutMap(request: LayoutMapRequest): Promise<LayoutMapResponse> {
      return this.post<LayoutMapResponse>("/layout", request);
    }
  • Type definitions for the layout map API. Includes LayoutMapRequest (url, viewport, selector) and LayoutMapResponse with nested types for LayoutElement and ElementRect defining the DOM hierarchy structure.
    export interface LayoutMapRequest {
      url: string;
      viewport?: number;
      selector?: string;
    }
    
    export interface ElementRect {
      x: number;
      y: number;
      width: number;
      height: number;
    }
    
    export interface LayoutElement {
      tag: string;
      id?: string;
      classes?: string[];
      rect: ElementRect;
      styles: Record<string, string>;
      children: LayoutElement[];
    }
    
    export interface LayoutMapResponse {
      url: string;
      viewport: number;
      root: LayoutElement;
    }
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes the output ('Returns element hierarchy with tags, classes, bounding rects, and computed CSS styles') and purpose, but lacks details on performance, error handling, or authentication needs, which are relevant for a tool that likely involves network requests.

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 front-loaded with the core purpose in the first sentence, followed by a concise usage guideline. Every sentence earns its place by adding value, with no redundant or verbose language, making it highly efficient.

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

Completeness4/5

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

Given the tool's moderate complexity (3 parameters, no output schema, no annotations), the description is mostly complete. It explains what the tool does and its output format, but could benefit from mentioning potential limitations (e.g., timeouts, JavaScript-rendered content) to fully guide an 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?

The schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds no additional parameter semantics beyond what the schema provides, such as examples or edge cases, resulting in a baseline score of 3.

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

Purpose5/5

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

The description clearly states the specific action ('Extract the DOM layout tree'), target resource ('of a URL'), and scope ('at a given viewport width'), distinguishing it from sibling tools like viewpo_compare_viewports and viewpo_screenshot by focusing on structural analysis rather than comparison or visual capture.

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

Usage Guidelines4/5

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

The description provides clear context for when to use this tool ('to understand page structure and find layout issues'), but does not explicitly mention when not to use it or name alternatives among the sibling tools, such as using viewpo_screenshot for visual issues instead.

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/littlebearapps/viewpo-mcp'

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