Skip to main content

self-healing-browser-mcp

CI License: MIT Python MCP

An MCP server that hands an AI agent — Claude Desktop, Claude Code, Cursor, or anything that speaks MCP — a real browser to drive, with self-healing locators.

A locator hint surviving a refactor that deletes its data-testid — the engine heals to the role + accessible name and reports it

Why

The moment you let an agent automate a browser, brittle selectors bite: a data-testid gets renamed, the DOM is restructured, a button's markup changes — and the run dies on a locator not found. Agents burn tokens retrying, or just give up.

This server takes a different contract. You describe an element by whatever you know — a test id, a role + accessible name, a label, some text, a CSS selector — and it resolves the element using the most stable strategy that still works. If your preferred locator has drifted, it heals to a fallback and tells you so, instead of failing.

How the self-healing works

Each element tool accepts the same optional strategies. The resolver tries them in priority order and uses the first that matches exactly one visible element:

testid  →  role + name  →  label  →  placeholder  →  text  →  css  →  fuzzy (accessible-name match)
  • If your first-choice strategy resolves the element, great — no heal.
  • If it doesn't (renamed test id, changed structure) but a later strategy does, the result is flagged healed so you know the locator drifted and should be updated.
  • If only a name is known and its casing/wording shifted, a final fuzzy pass matches the accessible name across interactive roles.

The agent "sees" the page semantically via browser_snapshot (roles + accessible names from the accessibility tree), not raw HTML or screenshots.

Demo

See it heal live — the same locator hint keeps working after a refactor deletes the element's data-testid (examples/self_healing_demo.py):

$ python examples/self_healing_demo.py
1) Original app — the preferred data-testid resolves the button:
   -> resolved via 'testid'   healed=False

2) After a refactor removed the data-testid — SAME hint, no code change:
   -> resolved via 'role'       healed=True
   -> clicked the recovered element successfully

The data-testid the agent learned is gone, but because the hint also carried the button's role and accessible name, the engine recovered the element, flagged the heal, and the element stayed clickable — no test edit, no agent retry loop.

Tools

Tool What it does
browser_navigate(url) Open a URL in the shared page
browser_snapshot() List interactive elements as {role, name}
browser_click(...) Click an element (self-healing)
browser_fill(value, ...) Type into a field (self-healing)
browser_get_text(...) Read an element's text
browser_assert_visible(...) Assert an element is visible — PASS/FAIL
browser_close() Close the browser

The ... on element tools is the locator strategy set: testid, role, name, label, placeholder, text, css — all optional; pass as many as you know.

Install

Not on PyPI yet, so pip install self-healing-browser-mcp will not find it. Install from source into a virtual environment, then download the Chromium build Playwright drives:

python3 -m venv .venv
.venv/bin/pip install "git+https://github.com/RAJUSHANIGARAPU/self-healing-browser-mcp"
.venv/bin/python -m playwright install chromium

Or from a clone (editable, for development):

git clone https://github.com/RAJUSHANIGARAPU/self-healing-browser-mcp
cd self-healing-browser-mcp
python3 -m venv .venv
.venv/bin/pip install -e .
.venv/bin/python -m playwright install chromium

Either way, the server executable is .venv/bin/self-healing-browser-mcp (on Windows, .venv\Scripts\self-healing-browser-mcp.exe). It is only on your PATH while that venv is active, and MCP clients do not activate it, so point the client at the full path.

Use it from an MCP client

Option A — the venv you installed into. Replace /abs/path/to/.venv with the real path.

Claude Code:

claude mcp add self-healing-browser -- /abs/path/to/.venv/bin/self-healing-browser-mcp

Claude Desktop / Cursor (MCP servers config):

{
  "mcpServers": {
    "self-healing-browser": {
      "command": "/abs/path/to/.venv/bin/self-healing-browser-mcp"
    }
  }
}

Option B — no venv, with uv. uvx builds the package from GitHub into a cached environment and runs it. Download Chromium once with the same Playwright version:

uvx --from git+https://github.com/RAJUSHANIGARAPU/self-healing-browser-mcp playwright install chromium
{
  "mcpServers": {
    "self-healing-browser": {
      "command": "uvx",
      "args": [
        "--from",
        "git+https://github.com/RAJUSHANIGARAPU/self-healing-browser-mcp",
        "self-healing-browser-mcp"
      ]
    }
  }
}

The first launch downloads dependencies, so the client's first connection can take a few seconds longer.

Then ask your agent to, e.g., "open example.com, snapshot the page, and click the Sign in button." When a selector has drifted, the tool result will say it healed.

Configuration

Env var Default Purpose
SHBM_TESTID_ATTR data-testid The attribute testid maps to (e.g. data-test, data-cy)
SHBM_HEADED (unset) Set to 1 to watch the browser instead of running headless

How this differs from Microsoft's Playwright MCP

microsoft/playwright-mcp is the official, much broader server. Both drive Playwright and both let the agent read the page as an accessibility snapshot rather than screenshots. The differences:

This server Microsoft's Playwright MCP
Targeting an element Each element tool takes several optional hints (testid, role + name, label, placeholder, text, css) and falls back through them in order, then a fuzzy name match. A fallback is reported as healed. Each element tool takes one target: "an exact target element reference from the page snapshot, or a unique element selector". Its README documents no fallback between strategies.
Scope 7 tools: navigate, snapshot, click, fill, get text, assert visible, close. Around 70 tools, including tabs, network, storage, DevTools, and opt-in coordinate-based vision tools.
Browsers Chromium only. Chrome, Firefox, WebKit and Edge (--browser).
Runtime Python 3.10+. Node.js 18+ (npx @playwright/mcp@latest).
Default mode Headless (SHBM_HEADED=1 to watch). Headed (--headless to hide).

Both let you change the test-id attribute (SHBM_TESTID_ATTR here, --test-id-attribute there). If you need multiple browsers, tabs, network control or screenshots, use Microsoft's server. This one is for the narrower case where an agent reuses locators across runs and you want them to survive markup changes and tell you when they drifted.

Develop

pip install -e ".[dev]"
python -m playwright install chromium
pytest

The self-healing engine (src/self_healing_browser_mcp/engine.py) is decoupled from the MCP layer and tested deterministically against in-memory HTML — no external site, no flakiness.

Releasing

Publishing to PyPI is automated with GitHub Actions via PyPI Trusted Publishing (OIDC) — no API token is stored in the repo. Every push builds and twine checks the distribution in CI, so main is always release-ready.

To cut a release:

  1. One-time: on PyPI, create the self-healing-browser-mcp project's Trusted Publisher pointing at this repo, workflow publish.yml, and environment pypi.
  2. Bump version in pyproject.toml, commit, and tag (git tag v0.1.1 && git push --tags).
  3. Publish a GitHub Release for that tag — the Publish to PyPI workflow builds and uploads automatically. After that, pip install self-healing-browser-mcp works.

No release has been published yet, so the package is not on PyPI.

License

MIT — see LICENSE.

Metadata

Release files for self-healing-browser-mcp 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for self-healing-browser-mcp 0.1.0
File Size Uploaded
self_healing_browser_mcp-0.1.0.tar.gz 101.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for self-healing-browser-mcp 0.1.0
File Interpreter ABI Platform
self_healing_browser_mcp-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 112.7 kB

Release files / self_healing_browser_mcp-0.1.0.tar.gz

Download URL self_healing_browser_mcp-0.1.0.tar.gz
Size 101.8 kB
Tags Source
SHA-256 checksum
How to use checksums
1308acb774f738e4f55f0fc1f376e219ba449396df18c3158150e6d45ed8d908
BLAKE2b-256 checksum
How to use checksums
a15838d18cbace3249c1a10a64e5889452311118402cc5507bb8abbba793a077
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 3, 2026.

Transparency log

Release files / self_healing_browser_mcp-0.1.0-py3-none-any.whl

Download URL self_healing_browser_mcp-0.1.0-py3-none-any.whl
Size 11.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cd6b617ec1d7ff05cf1b7a9bf542fcb4a02daf0417c2a055ca97c1878c8d54d6
BLAKE2b-256 checksum
How to use checksums
9f143632abdee216feae372aadb4b9694e31ab79a386f2f5f0afe5ec7cf29463
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 3, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page