playwright-grid-mcp
Extracts text and interactive elements from inline and embedded SVG content, and supports coordinate-based interaction with SVG document viewers.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
playwright-grid-mcp
A general-purpose Spatial Web & Document Viewer MCP Server built in strict TypeScript on top of Playwright and the Model Context Protocol (@modelcontextprotocol/sdk).
Designed for multimodal AI agents that need to read, ground, and interact with canvas applications, SVG/PDF document viewers, and authenticated SPAs where traditional DOM-only scrapers break down.
Why This Exists
Standard browser automation tools assume every interactive target is a semantic <input> or <button> in the light DOM. Real-world web applications frequently break that assumption:
Canvas & SVG Document Viewers: PDF viewers, whiteboards, CAD/diagram editors, and interactive worksheets render content into
<canvas>, inline<svg>, or embedded<object type="image/svg+xml">layers with zero semantic form fields.Pixel-Drift & Vision Hallucination: Asking a vision model to guess raw pixel coordinates on a
1920x1080screenshot leads to misclicks, while sending uncompressed full-resolution PNGs burns thousands of tokens per turn.Cold-Start Overhead & Auth Friction: Relaunching Chromium and re-authenticating behind SSO/MFA on every tool call slows multi-step workflows by 5x–10x.
playwright-grid-mcp solves all three with a persistent Playwright session, DOM + SVG text extraction, token-efficient JPEG screenshots overlaid with a 10%-interval spatial coordinate grid, and batch coordinate interactions with Range-based glyph centering.
Related MCP server: Charlotte
Architecture
MCP Client (LLM / Agent)
│ stdio (JSON-RPC 2.0 — logs isolated to stderr)
▼
src/index.ts Strict Zod schemas + MCP tool registration
│
▼
src/engine.ts SpatialBrowserEngine
├─ DOM + SVG Extractor Scrapes light DOM, inline <svg>, and same-origin <object *.svg> frames
├─ Form Inspector Resolves unique CSS selectors, ARIA labels & 0–100% bounding boxes
├─ Canvas Grid Renderer Downscales to ≤1100px JPEG (q=75) + draws 10% X/Y (0–100) grid & pills
└─ Spatial Actor Batch click/double-click/type + Range-based glyph centering
│
▼
src/browser.ts BrowserManager
└─ Mutex-serialized persistent Playwright Chromium context + reusable active Page (./.browser-session)Key Engineering Choices
Persistent Live Browser Context: Keeps one Playwright
BrowserContextand activePagealive across tool calls (supporting seamless headless ↔ headed transitions without tearing down tabs or losing session cookies).Zero-Dependency Offscreen
<canvas>Grid Overlay: Renders crisp red vertical (X: 0–100) and blue horizontal (Y: 0–100) 10% major lines, subtle 5% minor dashed guides, and high-contrast axis pills inside Chromium's native<canvas>encoder—compressing screenshots toimage/jpeg(quality: 75,maxWidth: 1100px) for ~5x–8x smaller payloads.Range-Based Glyph Centering: On positioned overlay text boxes (e.g., PDF/SVG markup tools), CSS
min-widthand padding often skew left-aligned short text when centering by container width. Measuring the rendered glyph bounds viadocument.createRange().selectNodeContents(...)centers the actual ink directly on(x_percent, y_percent).Strict TypeScript: Compiled with
strict,noImplicitAny,noUncheckedIndexedAccess,noImplicitOverride, and zeroanytypes across the entire codebase.
MCP Tools
Tool | Purpose |
| Opens a visible Chromium window to any |
| Navigates to a |
| Fills standard HTML inputs, selects, checkboxes, radios, and |
| Executes batch |
Quick Start
1. Install & Build
npm install
npx playwright install chromium
npm run typecheck
npm run build2. Configure in Your MCP Client
Add the server to your MCP client configuration (e.g., Claude Desktop, Cursor, or Antigravity CLI):
{
"mcpServers": {
"playwright-grid": {
"command": "node",
"args": ["/absolute/path/to/playwright-grid-mcp/dist/index.js"],
"env": {
"PLAYWRIGHT_GRID_SESSION_DIR": "/absolute/path/to/playwright-grid-mcp/.browser-session"
}
}
}
}3. Environment Variables (Optional)
Variable | Default | Description |
|
| Directory for persistent Chromium cookies and storage. |
| Playwright bundled | Custom Chromium/Chrome executable path. |
|
| Browser locale passed to Playwright. |
| System default | Optional IANA timezone ID (e.g., |
Typical Spatial Grounding Workflow
Authenticate (if needed): Call
browser_loginwith{ "url": "https://app.example.com/login", "success_url_pattern": "/workspace" }.Ground visually: Call
read_page_gridwith{ "url": "https://app.example.com/workspace/doc/1", "container_selector": "#document-canvas", "show_grid": true }.Read coordinates: Inspect the returned JPEG's red
X (0–100)and blueY (0–100)grid lines to locate exact target boxes or buttons.Act in a single batch: Call
click_or_type_at_coordinateswith{ "container_selector": "#document-canvas", "items": [{ "x_percent": 38.5, "y_percent": 22.0, "text": "A", "align": "center" }], "visible": true }and verify placement in the returned JPEG.
Security Notes
Session profiles (
.browser-session/) and.env*files are excluded via.gitignore. Never commit browser session directories.All logging is routed strictly to
stderrso the MCPstdioJSON-RPC channel stays clean.
License
MIT — see LICENSE.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Playwright browser automation — navigate, click, fill forms, extract, screenshot — 17 agent tools.
Give AI agents a real cloud Chrome: open sessions, navigate, read pages, click, type and screenshot.
Let your AI agent operate any website through a real, logged-in browser session.
Control a real browser from AI agents: navigate, click, type, screenshot, read the page.
Related MCP Servers
- AlicenseBqualityDmaintenanceEnables AI assistants to control a real Chromium browser through Playwright, allowing them to navigate pages, click elements, fill forms, extract text or HTML, and capture screenshots in a persistent session.6ISC
- AlicenseNot gradedqualityAmaintenanceGives AI agents token-efficient, structured access to web pages through a persistent headless browser session, returning a compact page orientation on arrival, targeted element queries, and full detail only when explicitly requested. Also enables navigation, iframe-aware interaction, form filling, screenshots, console/network monitoring, and scripted auditing of sites.4 npmMIT
- AlicenseNot gradedqualityAmaintenanceEnables AI agents to navigate, inspect, and interact with real websites via a persistent headless Chromium session, returning compact structured orientations, targeted element queries, and full detail only on request rather than dumping raw accessibility trees. This cuts token usage by roughly 10–140x on content-heavy pages while still supporting clicking, typing, form filling, screenshots, dialog handling, and multi-tab sessions.4 npmMIT
- AlicenseNot gradedqualityAmaintenanceEnables AI agents to browse and interact with web pages through a persistent headless Chromium session, returning compact structured page orientations and letting agents query specific elements, forms, and content only when needed. This keeps token usage far below full accessibility-tree snapshots while still supporting navigation, clicking, typing, screenshots, tabs, and network/console monitoring.4 npmMIT