mcpField
P
playwright-spatial-layout-mcp

playwright-spatial-layout-mcp

Local
github.com/vola-treblaDeveloper Tools0Updated 23w ago

About playwright-spatial-layout-mcp

playwright-spatial-layout-mcp is an MCP server for AI agents and browser test workflows that measures rendered page geometry with Playwright. It exposes coordinates and overlap checks beyond what DOM structure alone reveals.

Key features

  1. 01Read element bounds, z-index, and viewport visibility
  2. 02Detect overlap between target and overlay elements
  3. 03Validate spatial layout rules
  4. 04Compare layout changes across viewport sizes

Use cases

  1. 01Check whether a banner blocks a checkout button
  2. 02Verify navigation and content alignment
  3. 03Find elements that shift between mobile and desktop

MCP support

Exposes Playwright-based layout analysis tools to MCP clients, including bounds extraction, occlusion detection, spatial rule verification, and viewport reflow measurement.

Configuration

Local server config is the same for every client. Copy it into your client’s MCP config file.

mcp.json · Universal config
{
"mcpServers": {
"vola-trebla-playwright-spatial-layout": {
"command": "npx",
"args": [
"-y",
"playwright-spatial-layout-mcp"
]
}
}
}
Run commandnpx -y playwright-spatial-layout-mcp

Local servers need a runtime on your machine (e.g. Node.js 18+). Config file locations differ by client; see your client’s docs.

Packages
npmplaywright-spatial-layout-mcp0.2.0

Tools

6

Saved tool list · updated 2w ago

ParameterTypeRequiredDescription
urlstringYesURL of the page to analyze
viewportobjectNoViewport size (default: 1280×720)
viewport.widthintegerYesViewport width in px
viewport.heightintegerYesViewport height in px
selectorsarrayYesCSS selectors or Playwright locator strings

Details

From the project README

playwright-spatial-layout-mcp 🐸📐

npm version npm downloads CI License: MIT

An MCP server that gives AI agents geometric spatial awareness of web page layouts using Playwright.

AI agents can read the DOM and know a button exists — but they can't see that it's hidden under a sticky header, pushed off-screen by a broken CSS rule, or overlapping another element on mobile. This MCP fixes that by exposing real bounding box mathematics from a live browser.


🤔 The Problem

When an AI agent analyzes a Playwright test failure, it reads the accessibility tree:

"The Submit button exists in the DOM. It has role=button. It is visible."

What it cannot see:

  • 🙈 The button is at y: 1450px — below the fold on mobile
  • 🙈 A cookie banner overlaps it by 73%, making it unclickable
  • 🙈 On a 375px viewport the nav and hero section overlap each other
  • 🙈 An element shifted 200px to the right after a CSS refactor

playwright-spatial-layout-mcp gives the agent coordinates, intersection ratios, and layout shift data so it can reason about the rendered page — not just the markup.


🛠️ Tools

extract_bounding_boxes

Returns position, size, z-index, and viewport visibility for one or more elements.

{
  "url": "https://your-app.com",
  "selectors": ["header", ".hero-cta", "footer"],
  "viewport": { "width": 375, "height": 812 }
}
[
  {
    "selector": ".hero-cta",
    "box": { "x": 16, "y": 892, "width": 343, "height": 48 },
    "z_index": "auto",
    "is_visible": true,
    "is_in_viewport": false
  }
]

detect_visual_occlusion

Checks if one element physically overlaps another by computing bounding box intersection.

{
  "url": "https://your-app.com",
  "target_selector": ".checkout-button",
  "overlay_selector": ".cookie-banner"
}
{
  "is_occluded": true,
  "intersection_ratio": 0.61,
  "occluded_area_px": 4128
}

verify_spatial_relationships

Validates a set of layout rules and returns pass/fail with a human-readable reason per rule.

Supported rule types: left_of · right_of · above · below · contains · not_overlapping

{
  "url": "https://your-app.com",
  "rules": [
    { "type": "above", "element_a": "nav", "element_b": ".hero" },
    { "type": "not_overlapping", "element_a": ".sidebar", "element_b": ".main-content" }
  ]
}
{
  "passed": false,
  "results": [
    { "passed": true, "reason": "'nav' bottom (64px) is above '.hero' top (64px)" },
    { "passed": false, "reason": "'.sidebar' and '.main-content' overlap by 12%" }
  ]
}

compute_viewport_reflow

Measures how element positions and sizes change across multiple viewport sizes.

{
  "url": "https://your-app.com",
  "selectors": ["nav", ".hero", ".cta-button"],
  "viewports": [
    { "width": 375, "height": 812 },
    { "width": 768, "height": 1024 },
    { "width": 1280, "height": 720 }
  ]
}
[
  {
    "selector": ".cta-button",
    "shifted": true,
    "max_delta_x": 442,
    "max_delta_y": 318,
    "max_delta_width": 897,
    "max_delta_height": 0
  }
]

🚀 Installation

npx playwright-spatial-layout-mcp

Or install globally:

npm install -g playwright-spatial-layout-mcp
npx playwright install chromium
Claude Desktop config
{
  "mcpServers": {
    "playwright-spatial-layout-mcp": {
      "command": "npx",
      "args": ["-y", "playwright-spatial-layout-mcp"]
    }
  }
}

💡 Example Agent Prompts

"Check if the cookie banner is blocking the checkout button on mobile (375px viewport)"

"Verify that the navigation is above the hero section and the sidebar doesn't overlap the main content"

"Show me which elements shift the most when resizing from desktop to mobile"

"Is the promotional modal covering the primary CTA on iPad viewport?"


🔗 Related Projects


📄 License

MIT © vola-trebla

Comments

Markdown supported

New to MCP?

From what the protocol is to installing your first server, these answers cover most first questions.

An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.