Skip to main content
@mcp-b/smart-dom-reader extracts DOM structure optimized for AI/LLM consumption. It provides stable CSS selectors, interactive element maps, and semantic page structure while minimizing token usage. Zero runtime dependencies.

Installation

Minimal example

Two extraction approaches

Full extraction (SmartDOMReader)

Single-pass extraction of all elements. Use when you need everything upfront.
Instance-based usage with options:

Progressive extraction (ProgressiveExtractor)

Step-by-step extraction for token-sensitive AI workflows.
extractStructure accepts a Document or an Element to scope the extraction.

Extraction modes

Options

Output structure

SmartDOMResult

ExtractedElement

Interaction flags are only present when true, saving tokens.

Selector ranking

Selectors are ranked by stability (higher score = more reliable):

Exported modules

Bundle string export

A self-contained IIFE bundle is available for injection into pages (e.g. via chrome.userScripts.execute):
The bundle contains guarded fallbacks for non-browser environments and has no runtime imports.

MCP server

An optional MCP server returns XML-wrapped Markdown. Output format:
Server tools: Golden path sequence:
  1. dom_extract_structure to get the page outline
  2. dom_extract_region to get selectors for a target area
  3. Write a script using those selectors
  4. Optionally dom_extract_content for readable text