self-healing-browser-mcp

self-healing-browser-mcp

Enables AI agents to control a browser with self-healing locators that automatically recover when selectors change, allowing reliable web automation through natural language.

Category
访问服务器

README

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.

<p align="center"> <img src="docs/demo.gif" alt="A locator hint surviving a refactor that deletes its data-testid — the engine heals to the role + accessible name and reports it" width="720"> </p>

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

# install straight from the repo (PyPI release coming)
pip install "git+https://github.com/RAJUSHANIGARAPU/self-healing-browser-mcp"
python -m playwright install chromium

Use it from an MCP client

Claude Code:

claude mcp add self-healing-browser -- self-healing-browser-mcp

Claude Desktop / Cursor — add to the MCP servers config:

{
  "mcpServers": {
    "self-healing-browser": {
      "command": "self-healing-browser-mcp"
    }
  }
}

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

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.

License

MIT — see LICENSE.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选