Relax! MCP DOM Intelligence
by jgauffin
README.md
# Relax! MCP DOM Intelligence
An MCP server that gives coding agents structured access to HTML and CSS files. Instead of reading raw source text, agents query parsed ASTs and get back only the specific information they need.
## Why not just read the files?
When an agent reads an HTML or CSS file with a generic `read_file` tool, it dumps the entire file into context. This is wasteful and error-prone:
- **Token cost** -- A 2000-line HTML file burns thousands of tokens even if the agent only needs to know what classes are on the nav bar.
- **Noise** -- Raw markup buries the structural information agents actually need (element hierarchy, which selectors exist, what rules apply to an element) inside a wall of content, attributes, and boilerplate.
- **No cross-file reasoning** -- Understanding which CSS rules apply to a given HTML element requires matching selectors across multiple files. A file-read tool can't do that; the agent has to load everything and figure it out manually, which is slow and unreliable.
- **Stale reads** -- Files change during development. This server watches loaded files and re-parses automatically, so agents always work with current state.
This server solves these problems by parsing files once, caching the ASTs in memory, and exposing targeted query tools that return compact, structured results.
## Tools
| Tool | What it does |
|---|---|
| `load_files` | Load HTML/CSS files into memory. Must be called first. Watches for changes. |
| `html_outline` | Compact tree showing tag names, ids, and classes -- like the DOM inspector sidebar. |
| `html_query` | Query elements by CSS selector. Returns structured info (tag, id, classes, attributes, text, children). |
| `css_outline` | List all selectors in a CSS file with line numbers and property counts. |
| `css_for_selector` | Find CSS rules matching a selector string (substring match). |
| `used_classes` | List all CSS classes used in an HTML file with frequency counts. |
| `element_styles` | Find all CSS rules that apply to a specific element -- inline styles, `<style>` blocks, and external CSS files. Like browser DevTools computed styles. |
## Installation
### Prerequisites
- Node.js 18+
### Build
```bash
git clone <repo-url>
cd relax-dom-intelligence
npm install
npm run build
```
### Add to Claude Code
For the **current project** (run from your project directory):
```bash
claude mcp add relax-dom -- node /absolute/path/to/relax-dom-intelligence/dist/index.js
```
For a **specific directory** (global use -- run multiple instances with distinct names):
```bash
claude mcp add relax-dom-mysite -s user -- node /absolute/path/to/relax-dom-intelligence/dist/index.js /path/to/mysite --name relax-dom-mysite
```
The `-s user` flag makes the server available across all your projects.
### Add to Claude Desktop
Add an entry to your `claude_desktop_config.json`:
```json
{
"mcpServers": {
"relax-dom": {
"command": "node",
"args": ["/absolute/path/to/relax-dom-intelligence/dist/index.js", "/path/to/project"]
}
}
}
```
## CLI options
```
node dist/index.js [directory] [--name <name>] [--description <desc>]
```
| Option | Default | Description |
|---|---|---|
| `directory` | Current working directory | Root directory for resolving relative file paths |
| `--name`, `-n` | `relax-dom-<dirname>` | Server name (use distinct names when running multiple instances) |
| `--description`, `-d` | `Relax! MCP DOM Intelligence for <dirname> (<path>)` | Server description shown to clients |
### Examples
Serve current directory (typical local project use):
```bash
node dist/index.js
```
Serve a specific project:
```bash
node dist/index.js /home/user/projects/my-website
```
Multiple instances for global access:
```bash
# In Claude Code config, register two servers:
claude mcp add relax-dom-docs -s user -- node /path/to/dist/index.js /sites/docs --name relax-dom-docs
claude mcp add relax-dom-blog -s user -- node /path/to/dist/index.js /sites/blog --name relax-dom-blog
```
## Running and debugging
### Run directly
```bash
npm start
# or with options:
node dist/index.js /path/to/project --name my-server
```
The server communicates over **stdio** (stdin/stdout). Diagnostic messages are written to **stderr**, so they won't interfere with the MCP protocol.
### Watch mode (development)
Rebuild on source changes in one terminal:
```bash
npm run dev
```
Then run/restart the server in another.
### Inspect with MCP Inspector
The [MCP Inspector](https://modelcontextprotocol.io/docs/tools/inspector) lets you interact with the server in a browser UI -- useful for testing tools without a full agent setup:
```bash
npx @modelcontextprotocol/inspector node dist/index.js /path/to/project
```
### Debug logging
All log output goes to stderr. You'll see messages like:
```
[relax-dom-mysite] Server started on stdio (root: /sites/mysite)
[relax-dom-mysite] Re-parsed: /sites/mysite/index.html
```
To capture logs while running through an MCP client, redirect stderr to a file:
```bash
node dist/index.js /path/to/project 2>server.log
```
### Tests
```bash
npm test
```
This server cannot be deployed
Maintenance
ActivityInactive
ResponsivenessNo recent community issues