"CLI-Anything: Making ALL Software Agent-Native" -- CLI-Hub: https://clianything.cc/
Python
fix(browser): fix DOMShell MCP parameter mismatches and connection model
apirenobb941f2bb2a8
diff --git a/browser/agent-harness/cli_anything/browser/core/fs.py b/browser/agent-harness/cli_anything/browser/core/fs.pyindex cf3228ba9..6e1c55fd3 100644--- a/browser/agent-harness/cli_anything/browser/core/fs.py+++ b/browser/agent-harness/cli_anything/browser/core/fs.py@@ -111,6 +111,5 @@ def grep_elements(session: "Session", pattern: str, path: str = "") -> dict:>>> grep_elements(session, "Login"){"matches": ["/main/button[0]", "/main/link[1]"]}"""- target_path = path if path else session.working_diruse_daemon = session.daemon_mode- return backend.grep(pattern, target_path, use_daemon=use_daemon)+ return backend.grep(pattern, use_daemon=use_daemon)diff --git a/browser/agent-harness/cli_anything/browser/tests/test_core.py b/browser/agent-harness/cli_anything/browser/tests/test_core.pyindex ca0883fd9..f7137c559 100644--- a/browser/agent-harness/cli_anything/browser/tests/test_core.py+++ b/browser/agent-harness/cli_anything/browser/tests/test_core.py@@ -340,10 +340,10 @@ class TestFsModule:result = fs.grep_elements(sess, "Login")- mock_grep.assert_called_once_with("Login", "/", use_daemon=False)+ mock_grep.assert_called_once_with("Login", use_daemon=False)def test_grep_elements_with_path(self):- """Grepping with path uses that path."""+ """Grepping with path still calls backend (path not forwarded to DOMShell)."""sess = Session()with patch("cli_anything.browser.core.fs.backend.grep") as mock_grep:@@ -351,7 +351,7 @@ class TestFsModule:result = fs.grep_elements(sess, "Login", "/main")- mock_grep.assert_called_once_with("Login", "/main", use_daemon=False)+ mock_grep.assert_called_once_with("Login", use_daemon=False)# ── Daemon Mode Tests ────────────────────────────────────────────diff --git a/browser/agent-harness/cli_anything/browser/utils/domshell_backend.py b/browser/agent-harness/cli_anything/browser/utils/domshell_backend.pyindex 793bd8e6d..fe7d7a9d8 100644--- a/browser/agent-harness/cli_anything/browser/utils/domshell_backend.py+++ b/browser/agent-harness/cli_anything/browser/utils/domshell_backend.py@@ -13,6 +13,7 @@ Chrome Web Store: https://chromewebstore.google.com/detail/domshell-%E2%80%94-br"""import asyncio+import osimport subprocessimport shutilfrom typing import Any, Optional@@ -20,8 +21,17 @@ from mcp import ClientSession, StdioServerParametersfrom mcp.client.stdio import stdio_client# DOMShell MCP server command+# The harness connects to a running DOMShell server via domshell-proxy (stdio bridge).+# Configure via environment variables:+# DOMSHELL_TOKEN — auth token (required, must match the running server)+# DOMSHELL_PORT — MCP HTTP port of the running server (default: 3001)DEFAULT_SERVER_CMD = "npx"-DEFAULT_SERVER_ARGS = ["@apireno/domshell"]+DEFAULT_SERVER_ARGS = [+ "-p", "@apireno/domshell",+ "domshell-proxy",+ "--port", os.environ.get("DOMSHELL_PORT", "3001"),+ "--token", os.environ.get("DOMSHELL_TOKEN", ""),+]# Daemon mode: persistent MCP connection_daemon_session: Optional[ClientSession] = None@@ -217,7 +227,7 @@ def ls(path: str = "/", use_daemon: bool = False) -> dict:>>> ls("/"){"path": "/", "entries": [{"name": "main", "role": "landmark", ...}]}"""- result = asyncio.run(_call_tool("domshell_ls", {"path": path}, use_daemon))+ result = asyncio.run(_call_tool("domshell_ls", {"options": path}, use_daemon))return result@@ -253,16 +263,17 @@ def cat(path: str, use_daemon: bool = False) -> dict:>>> cat("/main/button[0]"){"name": "Submit", "role": "button", "text": "Submit", ...}"""- result = asyncio.run(_call_tool("domshell_cat", {"path": path}, use_daemon))+ result = asyncio.run(_call_tool("domshell_cat", {"name": path}, use_daemon))return result-def grep(pattern: str, path: str = "/", use_daemon: bool = False) -> dict:+def grep(pattern: str, use_daemon: bool = False) -> dict:"""Search for pattern in accessibility tree.+ Searches from the current working directory.+Args:pattern: Text pattern to search for- path: Root path for search (default: "/")use_daemon: Use persistent daemon connection if availableReturns:@@ -274,7 +285,7 @@ def grep(pattern: str, path: str = "/", use_daemon: bool = False) -> dict:"""result = asyncio.run(_call_tool("domshell_grep",- {"pattern": pattern, "path": path},+ {"pattern": pattern},use_daemon))return result@@ -294,7 +305,7 @@ def click(path: str, use_daemon: bool = False) -> dict:>>> click("/main/button[0]"){"action": "click", "path": "/main/button[0]", "status": "success"}"""- result = asyncio.run(_call_tool("domshell_click", {"path": path}, use_daemon))+ result = asyncio.run(_call_tool("domshell_click", {"name": path}, use_daemon))return result@@ -358,6 +369,9 @@ def forward(use_daemon: bool = False) -> dict:def type_text(path: str, text: str, use_daemon: bool = False) -> dict:"""Type text into an input element.+ Focuses the element first (via domshell_focus), then types. Both operations+ run in a single MCP session so that focus state is preserved.+Args:path: Path to input elementtext: Text to type@@ -366,12 +380,23 @@ def type_text(path: str, text: str, use_daemon: bool = False) -> dict:Returns:Dict with action result"""- result = asyncio.run(_call_tool(- "domshell_type",- {"path": path, "text": text},- use_daemon- ))- return result+ async def _focus_and_type():+ global _daemon_session+ if use_daemon and _daemon_session is not None:+ await _daemon_session.call_tool("domshell_focus", {"name": path})+ return await _daemon_session.call_tool("domshell_type", {"text": text})++ server_params = StdioServerParameters(+ command=DEFAULT_SERVER_CMD,+ args=DEFAULT_SERVER_ARGS+ )+ async with stdio_client(server_params) as (read, write):+ async with ClientSession(read, write) as session:+ await session.initialize()+ await session.call_tool("domshell_focus", {"name": path})+ return await session.call_tool("domshell_type", {"text": text})++ return asyncio.run(_focus_and_type())# ── Daemon control functions ───────────────────────────────────────────