DOMRay MCP Server
Officialby bishoku
README.md
# DOMRay β‘

> **The Missing Runtime Telemetry Bridge for AI Coding Agents.**
> Give your AI assistants (**Cursor, Claude Code, Antigravity, Windsurf**) real-time vision into active browser sessions β including web pages behind **SSO, 2FA, VPNs, and dynamic client-side state** β via standard **Model Context Protocol (MCP)**.
[](LICENSE)
[](https://www.typescriptlang.org/)
[](https://developer.chrome.com/docs/extensions/mv3/)
[](https://modelcontextprotocol.io/)
[](CONTRIBUTING.md)
---
## π The Problem: The Runtime Blindspot of AI Coding
AI coding agents have revolutionized software development. Tools like Cursor, Claude Code, Windsurf, and Copilot understand your static codebase, git history, syntax trees, and type definitions with astonishing precision.
**However, the moment your application runs in a browser, your AI coding agent becomes completely blind.**
```
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β THE RUNTIME GAP β
β β
β Static World (AI has 100% Context): β
β β Source Code & Git History β
β β Abstract Syntax Trees & Types β
β β Project Files & Dependencies β
β β
β =================== BLIND SPOT ===================== β
β β
β Runtime World (AI has 0% Context): β
β β Pages behind SSO, 2FA, VPNs, or Staging Auth β
β β Real-time React / Vue internal component state β
β β Causal user interaction sequences (Breadcrumbs) β
β β Failed API responses and HTTP 4xx/5xx payloads β
β β Console warnings and client storage (session/local) β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
```
### Where Current Practices Fail:
1. **The Authentication & Security Wall (SSO / 2FA / Staging):**
Autonomous headless agents (e.g. Puppeteer/Playwright scripts) cannot log into internal staging environments, corporate VPNs, or apps protected by Okta/Google 2FA without complex credential passing or unsafe cookie sharing.
2. **The "Manual Copy-Paste" Tax:**
When a bug occurs, developers waste time opening DevTools, copying messy stack traces, exporting HAR network logs, taking screenshots, and hand-crafting prompts for their AI. By the time the context is assembled, critical temporal details are lost.
3. **Silent State Bugs (No Errors Thrown):**
Many of the hardest frontend bugs don't throw an uncaught exception (e.g. *"The submit button is permanently stuck on 'Applying...', no error is in the console, and the cart total didn't change"*). Static code analysis cannot tell the AI whether `isSubmitting` in React Fiber or a Vue `ref` is currently stuck at `true`.
4. **The Automated Testing Disconnect:**
After discovering and manually reproducing a bug in the browser, translating that discovery into resilient, production-ready Playwright/Cypress E2E specs or MSW API mock handlers requires another round of manual, error-prone boilerplate coding.
---
## π‘ The Solution: DOMRay
**DOMRay bridges the gap between your active browser runtime and your AI coding agent.**
Instead of trying to automate a separate, detached browser instance, DOMRay connects directly to the **living, authenticated browser tab you are already using as a developer**.
Using the **Chrome DevTools Protocol (CDP)** and the open **Model Context Protocol (MCP)**, DOMRay securely streams structured runtime telemetry into your AI agent's tool context while providing you with 100% visibility through a native Chrome Side Panel.
```
+-----------------------------------------------------------------------------------------+
| DOMRay WORKFLOW |
| |
| 1. DEVELOPER INTERACTS 2. DOMRAY CAPTURES 3. AI AGENT REPAIRS |
| |
| ββββββββββββββββββββββββββ βββββββββββββββββββββ βββββββββββββββββββ |
| β Authenticated Browser β β DOMRay Extension β β AI Agent (MCP) β |
| β (SSO / 2FA Active) β ββββββ> β - User Actions β ββββββ> β Cursor / Claude β |
| β User clicks "Apply", β β - Failed Network β β Queries state, β |
| β button freezes! β β - Fiber State β β generates fix & β |
| ββββββββββββββββββββββββββ β - Edge Redaction β β E2E test specs! β |
| βββββββββββββββββββββ βββββββββββββββββββ |
+-----------------------------------------------------------------------------------------+
```
### What DOMRay Gives You & Your AI:
* π **Zero-Friction Context:** Your AI can inspect runtime exceptions, network request histories, and client storage on demand.
* π±οΈ **Causal Flow Reconstruction:** Replays the exact sequence of clicks, form entries, and SPA navigations that triggered an issue.
* βοΈ **Framework State X-Ray:** Traverses React 18/19 Fiber trees (hooks unrolled into `useState`, `useReducer`, props) and Vue 3 reactive `ref()` / `computed()` components.
* π¬ **Instant E2E Test Blueprints (`domray_get_test_blueprint`):** Converts recorded user actions and network events directly into runnable, resilient **Playwright** or **Cypress** test specs.
* π **Auto MSW Mock Handlers (`domray_get_mock_handlers`):** Automatically synthesizes Mock Service Worker v2 handlers from real failed HTTP 4xx/5xx network transactions.
* π **1-Click AI Context Capsule:** Copies an edge-redacted, Markdown-formatted diagnostic report to your clipboard for instant pasting into web ChatGPT, Claude, or GitHub Issues.
---
## ποΈ Architecture & Technology Stack
DOMRay is built as a lightweight, local-first monorepo designed for performance and zero cognitive overhead.
```
[Target Web Page (SSO / 2FA / Strict CSP)]
β
βββ User Interaction Tracker (Content Script)
β βββ Captures: clicks, inputs, submits, SPA route changes
β βββ W3C Accessible Name resolution (label[for], aria-labelledby)
β
β (Chrome DevTools Protocol - CDP via chrome.debugger)
βΌ
[Chrome Extension (Manifest V3)]
βββ Service Worker
β βββ CDP Client (Runtime.enable, Network.enable, consoleAPICalled)
β βββ In-Memory Ring Buffers (Errors, Network, Breadcrumbs, Console)
β βββ Edge Redaction Engine (Masks Authorization, Cookie, Passwords BEFORE dispatch)
β βββ WebSocket Client (Loopback with keepalive heartbeat)
βββ Popup UI (1-Click Auto-Pairing, Re-attach, Quick Actions)
βββ π₯οΈ Live Telemetry & AI Audit Side Panel (chrome.sidePanel)
βββ π€ Live AI Audit Feed (Watches agent tool queries in real time)
βββ π΄ Exceptions, Stack Traces & Live User Breadcrumbs
βββ π― Visual Element Inspector (Hover highlighter & component name)
βββ π§Ή 1-Click State & Buffer Reset Control
β
β Localhost Loopback (ws://127.0.0.1:9123)
β Auth: Origin Validation + Ephemeral Cryptographic Token
βΌ
[Local DOMRay MCP Server (Node.js/TypeScript)]
βββ Hybrid HTTP + WebSocket Bridge
β βββ POST /pair (Zero-config 1-click handshake & origin registration)
β βββ WS Inbound/Outbound (Telemetry streams + Bidirectional DOM/State queries)
βββ Session Store (Ring buffers, active tab tracking, callback registry)
βββ Semantic DOM Sanitizer & Token Pruner (-85% LLM token consumption)
βββ MCP stdio Transport (JSON-RPC 2.0 over stdin/stdout)
β
βΌ
[AI Coding Agent (Cursor / Claude Code / Antigravity / Windsurf)]
βββ Standard MCP Tools (10 specialized tools)
```
### Technologies Used:
* **Protocol Standard:** [Model Context Protocol (MCP)](https://modelcontextprotocol.io/) via `@modelcontextprotocol/sdk`.
* **Browser Automation & Telemetry:** Chrome DevTools Protocol (`chrome.debugger` API) under Manifest V3.
* **UI & Developer Experience:** Chrome native `chrome.sidePanel` for docked, persistent telemetry monitoring.
* **Testing & Mocks:** [Playwright](https://playwright.dev/) for resilient E2E automation and [MSW v2](https://mswjs.io/) for API mocking.
* **Core Languages:** 100% TypeScript with strict typing, bundled with `tsup` and `esbuild`.
---
## π‘οΈ Enterprise Security, Privacy & Zero-Data-Leak Guarantees
DOMRay was architected from day one for strict corporate environments, regulated data, and internal staging applications:
1. **π 100% Local-First (No Cloud, No Third Parties):**
DOMRay has **zero external servers**. Telemetry never leaves your local machine (`127.0.0.1`). There are no analytics, no tracking, and no external API dependencies.
2. **π‘οΈ Edge-Side Redaction Engine:**
Data masking occurs **inside the browser extension before dispatching** over the local WebSocket:
* Sensitive HTTP headers (`Authorization`, `Cookie`, `Set-Cookie`, `X-API-Key`) are replaced with `***MASKED***`.
* Sensitive URL query parameters (`token`, `password`, `secret`, `key`) are automatically scrubbed.
* Form inputs (`type="password"`, `data-private`, card numbers, CVVs) never leak their values into breadcrumbs.
3. **π Origin Validation & CSWSH Protection:**
The local WebSocket bridge rejects any connection whose `Origin` header is not an authorized `chrome-extension://<EXTENSION_ID>`. Regular web pages and external domains are immediately rejected with HTTP 403.
4. **π Ephemeral Cryptographic Tokens:**
Every time the MCP server starts, it generates a cryptographically random 32-byte session token validated via `crypto.timingSafeEqual`.
5. **ποΈ 100% Transparent AI Audit Feed:**
Through the native Chrome Side Panel, developers see a live feed of **every tool call the AI executes**, including tool parameters, timestamp, and returned payloads. You are never left wondering what data the AI requested.
---
## β‘ Quick Start
### 1. Clone and Build
```bash
# Clone the repository
git clone https://github.com/bishoku/domray.git
cd domray
# Install dependencies across monorepo workspaces
npm install
# Build both the MCP server and the Chrome Extension
npm run build
```
### 2. Load the Extension into Google Chrome
1. Navigate to `chrome://extensions` in Chrome.
2. Enable **Developer mode** (toggle in the top-right corner).
3. Click **Load unpacked** and select the directory:
```
domray/extension/dist/
```
4. The **DOMRay** icon will appear in your Chrome toolbar. Pin it for quick access.
### 3. Configure Your AI Coding Agent
Add DOMRay to your AI agent's MCP configuration:
#### For Cursor (`~/.cursor/mcp.json` or Cursor Settings > Features > MCP):
```json
{
"mcpServers": {
"domray": {
"command": "node",
"args": ["/ABSOLUTE/PATH/TO/domray/mcp-server/dist/index.js"]
}
}
}
```
#### For Claude Code (`claude_desktop_config.json` or project config):
```json
{
"mcpServers": {
"domray": {
"command": "node",
"args": ["/ABSOLUTE/PATH/TO/domray/mcp-server/dist/index.js"]
}
}
}
```
### 4. Connect & Trace
1. Open your web application (or run our example playground: `npm run dev:example`).
2. Click the **DOMRay** extension icon in Chrome and click **β‘ Auto-Connect** (connects in 1 click).
3. Click **Attach Debugger** to begin capturing runtime telemetry.
4. Click **π₯οΈ Open Side Panel** to watch live telemetry and the AI audit stream side-by-side with your app!
---
## π§° MCP Tools Reference (10 Tools)
DOMRay exposes 10 tools to connected AI coding agents:
| Tool | Description | Key Parameters |
| :--- | :--- | :--- |
| `domray_get_active_session` | Returns active tab URL, page title, uptime, and telemetry buffer counters. | None |
| `domray_get_latest_error` | Returns the latest unhandled runtime exception, call stack, and preceding causal breadcrumbs. | `include_breadcrumbs: boolean` |
| `domray_get_flow_timeline` | Interleaves user clicks, form submissions, network calls, and console logs into a unified chronological replay. | `limit: number`, `failed_network_only: boolean` |
| `domray_get_test_blueprint` | π¬ **Synthesizes runnable Playwright or Cypress E2E test specs** from recorded interactions and API calls. | `framework: "playwright" \| "cypress"`, `include_network_assertions: boolean` |
| `domray_get_mock_handlers` | π **Synthesizes MSW v2 mock request handlers** directly from recorded 4xx/5xx API transactions. | `format: "msw" \| "fetch-mock"`, `filter: "failed_only" \| "all"` |
| `domray_get_component_state` | Traverses React 18/19 Fiber or Vue 3 reactive trees to extract props and hooks (`useState`, etc.). | `selector: string` (e.g. `'#root'`, `'form#checkout'`) |
| `domray_get_scoped_dom` | Returns an intelligent, token-pruned (-85% tokens) HTML subtree for a given CSS selector. | `selector: string`, `max_depth: number` |
| `domray_get_network_timeline` | Returns recent HTTP transactions (status, duration, method, response bodies for errors). | `failed_only: boolean`, `limit: number` |
| `domray_get_console_logs` | Returns live browser console logs (`log`, `info`, `warn`, `error`) captured via CDP. | `level: "all" \| "error" \| "warn"`, `search?: string` |
| `domray_get_storage_state` | Reads `localStorage`, `sessionStorage`, or cookies with automatic secret masking. | `storage_type: "local" \| "session" \| "cookies"` |
---
## π Real-World Playground Example
We include a standalone React 18 application in `examples/checkout-app` simulating an enterprise checkout page behind SSO:
```bash
# Start the example checkout app (runs on http://localhost:5173)
npm run dev:example
# Run the DOMRay-generated Playwright E2E test suite
npm run test:example:e2e
```
* **The Scenario:** A checkout screen with simulated SSO 2FA session tokens.
* **The Bug:** Applying coupon `EXPIRED20` triggers an HTTP 422 error. Due to a state bug in `CouponForm.tsx`, `isSubmitting` never resets, permanently freezing the button without throwing an error in the console.
* **Try it with your AI:**
> *"The checkout apply button is permanently frozen. Can you inspect the active tab with DOMRay, diagnose the issue, and provide a fix and automated test?"*
---
## π€ Contributing to DOMRay
We believe that the future of software development lies in empowering AI assistants with **real, high-fidelity runtime awareness**βwithout sacrificing developer privacy or enterprise security.
DOMRay is an **open-source, community-driven project**, and we warmly welcome contributions from frontend developers, AI enthusiasts, and tool builders alike!
### How You Can Help:
* β **Star the Repository:** If DOMRay helps your daily workflow, star the repo to help other developers discover it!
* π§© **Expand Framework State Inspectors:** Help us build deeper extractors for **Svelte 5 runes**, **Angular signals**, **SolidJS stores**, or **Zustand / Redux** slices.
* π§ͺ **Improve Testing Blueprints:** Add support for Vitest Component Testing, Jest, or custom locator strategies.
* π **Report Issues & Ideas:** Found an edge case or have a vision for a new MCP tool? Open an [Issue](https://github.com/bishoku/domray/issues) or start a discussion.
* π **Submit Pull Requests:** Check out open issues, fork the repo, and submit your PRs. We strive to review and merge community contributions promptly.
Please feel free to explore the codebase, test it with your favorite coding agents, and share your thoughts. Let's make AI-assisted frontend development faster, smarter, and context-aware together!
---
## π License
DOMRay is open-source software licensed under the [MIT License](LICENSE).
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo issues