Skip to main content
Glama

domdrift

PyPI CI Python 3.11+ License: MIT

Structural HTML and JSON contract guard for scrapers and agents — separates HTTP 200 challenge pages (exit 3) from real layout changes (exit 2) and emits <2KB redacted repair snapshots.

uvx domdrift diff yesterday.html today.html

domdrift terminal demo

Save a contract from a known-good response. Successful checks print nothing:

$ printf '<main><span class="price">$12</span></main>' > good.html
$ uvx domdrift init good.html --select 'price=main > .price' -o contract.json
$ uvx domdrift check -c contract.json good.html; echo $?
0
$ printf '<main><span class="sale-price">$10</span></main>' | uvx domdrift check -c contract.json --max-bytes 512 > repair.txt
$ echo $?
2
$ wc -c < repair.txt
256
$ cat repair.txt
DRIFT_DETECTED
violations: rule=price selector=main > .price reason=matched 0, need >= 1
survivors: selector=main count=1 broken=.price
candidates: selector=main > .sale-price count=1
candidates: selector=main > span count=1
  <main>
    <span.sale-price>
$ printf '<title>Just a moment...</title>' | uvx domdrift check -c contract.json
SOFT_BLOCK_DETECTED
Cloudflare: challenge page title. Keep existing selectors.
$ echo $?
3

For an MCP client that launches local stdio servers:

{
  "mcpServers": {
    "domdrift": { "command": "uvx", "args": ["domdrift", "mcp"] }
  }
}

domdrift_init takes baseline content or a public URL. Pass its contract to domdrift_check with the next response. domdrift_diff compares two content strings directly. Check and diff return status, exit_code and report.

Installation

Run without installing via uv:

uvx domdrift --version

Or install into a persistent environment:

uv tool install domdrift
# or
pip install domdrift

Requires Python 3.11+ and uses only the Python standard library (dependencies = []).

Related MCP server: websight

Contracts

init accepts a file path, an HTTP(S) URL or stdin. Without --select, it looks for landmarks, repeating HTML items and their fields, or infers JSON paths and types. Use --auto-landmarks to add automatic HTML rules to explicit selections.

uvx domdrift init catalog.json --select 'price=$.data.items[*].unit_price' -o catalog.contract
uvx domdrift check -c catalog.contract next.json --format json --max-bytes 1024

HTML rules support min_count, max_count, min_non_empty_ratio, required_attr and a Python regex pattern on the attribute or visible text. CSS supports groups, descendant, child and sibling combinators, attribute operators, :not, :has, :contains, and first/last/nth-child. The parser works on supplied markup; it does not execute JavaScript.

JSON paths start at $ and use .key and [*]. Inferred rules record types, nullability, field presence, non-empty ratios and minimum array sizes. A check permits value changes that satisfy those rules. A snapshot diff also reports inventory additions, removals, count changes, moves between HTML containers and type changes in optional JSON fields.

Exit codes and limits

Code

Meaning

0

Contract holds, or no structural change in a diff.

1

Invalid arguments, contract or input, or a read error.

2

Structural drift. Inspect the surviving prefix, candidate and skeleton.

3

Likely challenge, access gate, rate limit or empty hydration shell. Keep the current selectors.

Reports default to 2048 UTF-8 bytes. --max-bytes accepts budgets of 256 bytes or more. JSON output stays valid when details are trimmed. Evidence uses structural labels and JSON types rather than body text or JSON scalar values. Keep contracts from trusted sources: selectors and regexes are executable checks on incoming documents.

Input reads are capped at 10 MiB. URL connections use a 15-second socket timeout and check public addresses on each redirect and connection. --allow-private-net permits local HTTP fixtures on the CLI. MCP URL inputs always require public HTTP(S) addresses.

From a source checkout, run uv run domdrift --help. Python 3.11 or newer is required; the installed package uses only the standard library.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      A
      maintenance
      Web content extraction for AI agents. 10 tools: scrape, crawl, map, batch, extract, summarize, diff, brand, search, research. Uses TLS fingerprinting to bypass anti-bot without a headless browser. Outputs LLM-optimized markdown with 67% fewer tokens than raw HTML.
      10
      2,472
      AGPL 3.0
    • A
      license
      A
      quality
      B
      maintenance
      Enables AI agents to see, analyze, and visually verify web page changes through pixel-perfect diffing, theme extraction, layout analysis, and interactive element detection.
      1
      MIT