@allansantos-dev/smart-tool 0.9.73 → 0.9.74

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.9.74 - beta
4
+
5
+ - The agent's browser (the Playwright MCP server Smart Tool registers) is marked by its User-Agent, which ends with
6
+ `SmartToolAgentBrowser`, instead of the `X-Smart-Tool-Agent-Browser` header. Any header added to every request made
7
+ each cross-origin `fetch` and every web font from another origin send a CORS preflight, and servers that do not allow
8
+ that header refused it: the product page showed 8 console errors in the agent's browser and lost its fonts. The browser
9
+ sets the User-Agent itself, so it reaches navigations, redirects and subresources without a preflight, and the daemon
10
+ still refuses the agent's browser on every path, `/setup` included. `--blocked-origins` was not used: Playwright MCP
11
+ documents that it does not apply to redirects. Test: `tests/test_browser_control.py` (a redirecting page that fetches
12
+ from another origin answered like a font CDN).
13
+
3
14
  ## 0.9.73 - beta
4
15
 
5
16
  - Once a day (first pass 10 minutes after the daemon starts) the daemon removes, in each registered project without a
package/README.md CHANGED
@@ -17,7 +17,7 @@ registered as the `playwright` server where this machine lets a browser be drive
17
17
  An optional hook routes the agent's native Grep/Glob/Read/Bash/WebSearch/WebFetch calls to these tools when they
18
18
  are cheaper, or just tells the agent what Smart Tool would do.
19
19
 
20
- **Status:** 0.9.73 beta. Windows only. What changed in each version: [CHANGELOG.md](CHANGELOG.md).
20
+ **Status:** 0.9.74 beta. Windows only. What changed in each version: [CHANGELOG.md](CHANGELOG.md).
21
21
 
22
22
  ## How it works
23
23
 
@@ -83,7 +83,7 @@ gateway such as Ollama, nothing about your code leaves the machine.
83
83
  ## Install
84
84
 
85
85
  ```powershell
86
- npx @allansantos-dev/smart-tool@0.9.73 install
86
+ npx @allansantos-dev/smart-tool@0.9.74 install
87
87
  ```
88
88
 
89
89
  Updates install themselves, on by default: the tray checks npm when it starts (at logon) and every 24 h, and when there
@@ -382,7 +382,7 @@ fails to load is listed in the setup screen with its error and does not affect t
382
382
  ## Uninstall
383
383
 
384
384
  ```powershell
385
- npx @allansantos-dev/smart-tool@0.9.73 uninstall [--target DIR] [--keep-data]
385
+ npx @allansantos-dev/smart-tool@0.9.74 uninstall [--target DIR] [--keep-data]
386
386
  ```
387
387
 
388
388
  It asks nothing and opens no window. It stops the tray and the daemon, removes the logon task, the hook entries of Smart
@@ -11,11 +11,11 @@ The registered command is lazy_mcp_proxy.py around the real server: every sessio
11
11
  a Node process kept idle in each session that never opens a browser cost about 97 MB of commit each. The proxy answers
12
12
  the handshake from the cache the probe writes (HANDSHAKE_PATH) and starts the real server on the first tool call.
13
13
 
14
- Pages the agent opens are untrusted input. The server never exposes tools a page registers (WebMCP); every request
15
- the browser makes carries AGENT_HEADER, which the daemon refuses, so a page cannot steer the agent into Smart Tool's
16
- own setup page and its token (redirects included); `browser_run_code_unsafe` (arbitrary JavaScript in the server
17
- process, outside any client sandbox) is denied in the client: Playwright MCP itself is not a security boundary and
18
- its documentation points to client-level permissions.
14
+ Pages the agent opens are untrusted input. The server never exposes tools a page registers (WebMCP); the User-Agent of
15
+ every request the browser makes ends with AGENT_UA_MARK, which the daemon refuses, so a page cannot steer the agent
16
+ into Smart Tool's own setup page and its token (redirects included); `browser_run_code_unsafe` (arbitrary JavaScript
17
+ in the server process, outside any client sandbox) is denied in the client: Playwright MCP itself is not a security
18
+ boundary and its documentation points to client-level permissions.
19
19
  """
20
20
  import json
21
21
  import os
@@ -43,26 +43,29 @@ OUTPUT_DIR = os.path.join(paths.DATA_DIR, "playwright-mcp")
43
43
  CONFIG_PATH = os.path.join(paths.DATA_DIR, "playwright-mcp.json")
44
44
  HANDSHAKE_PATH = os.path.join(paths.DATA_DIR, "playwright-mcp-handshake.json")
45
45
  PROXY = os.path.join(os.path.dirname(os.path.abspath(__file__)), "lazy_mcp_proxy.py")
46
- AGENT_HEADER = "X-Smart-Tool-Agent-Browser"
46
+ AGENT_UA_MARK = "SmartToolAgentBrowser"
47
47
  OUTPUT_MAX_BYTES = 100 * 1024 * 1024
48
48
  PROBE_TIMEOUT_S = 60
49
49
  DENIED_TOOLS = ("browser_run_code_unsafe",)
50
50
  _CODEX_TABLE_RE = re.compile(rf"^\[mcp_servers\.{SERVER}\][ \t]*\r?\n", re.M)
51
51
  _CHROMIUM_PROBE = ("from playwright.sync_api import sync_playwright\n"
52
- "with sync_playwright() as p: print(p.chromium.executable_path)")
52
+ "with sync_playwright() as p:\n"
53
+ " print(p.chromium.executable_path)\n"
54
+ " b = p.chromium.launch(headless=True); print(b.new_page().evaluate('navigator.userAgent')); b.close()")
53
55
 
54
56
 
55
- def chromium_executable():
56
- """The Chromium that `playwright install chromium` put in place for the browser venv; RuntimeError when absent."""
57
+ def chromium():
58
+ """The Chromium that `playwright install chromium` put in place for the browser venv and the User-Agent it sends
59
+ headless, as (path, user_agent); RuntimeError when absent or when it does not start."""
57
60
  if not install_runtime.BROWSER_PYTHON.is_file():
58
61
  raise RuntimeError(f"Browser runtime missing ({install_runtime.BROWSER_PYTHON}).")
59
62
  done = subprocess.run([str(install_runtime.BROWSER_PYTHON), "-c", _CHROMIUM_PROBE], capture_output=True,
60
63
  text=True, encoding="utf-8", errors="replace", timeout=60,
61
64
  creationflags=getattr(subprocess, "CREATE_NO_WINDOW", 0))
62
- path = (done.stdout.strip().splitlines() or [""])[-1]
63
- if done.returncode or not os.path.isfile(path):
64
- raise RuntimeError(f"Chromium not found: {(done.stderr or done.stdout).strip()[-300:] or path}")
65
- return path
65
+ lines = done.stdout.strip().splitlines()
66
+ if done.returncode or len(lines) < 2 or not os.path.isfile(lines[-2]):
67
+ raise RuntimeError(f"Chromium not found or not starting: {(done.stderr or done.stdout).strip()[-300:]}")
68
+ return lines[-2], lines[-1]
66
69
 
67
70
 
68
71
  def server_command():
@@ -72,9 +75,9 @@ def server_command():
72
75
  raise RuntimeError("Supported Node.js not found for Playwright MCP.")
73
76
  if not CLI.is_file():
74
77
  raise RuntimeError(f"Playwright MCP is not installed ({CLI}); reinstall Smart Tool.")
75
- return [node, str(CLI), "--isolated", "--headless", "--no-webmcp", "--caps=", "--config", write_config(),
76
- "--executable-path", chromium_executable(), "--output-dir", OUTPUT_DIR,
77
- "--output-max-size", str(OUTPUT_MAX_BYTES)]
78
+ executable, user_agent = chromium()
79
+ return [node, str(CLI), "--isolated", "--headless", "--no-webmcp", "--caps=", "--config", write_config(user_agent),
80
+ "--executable-path", executable, "--output-dir", OUTPUT_DIR, "--output-max-size", str(OUTPUT_MAX_BYTES)]
78
81
 
79
82
 
80
83
  def lazy_command(command):
@@ -86,11 +89,18 @@ def lazy_command(command):
86
89
  return [python, PROXY, "--handshake", HANDSHAKE_PATH, "--", *command]
87
90
 
88
91
 
89
- def write_config():
90
- """Writes the Playwright MCP config file that adds AGENT_HEADER to every request of the browser (navigations,
91
- redirects, subresources; measured: no CORS preflight is added) and returns its path."""
92
+ def is_agent_browser(headers):
93
+ """True when the request headers come from the agent's browser: its User-Agent carries AGENT_UA_MARK."""
94
+ return AGENT_UA_MARK in (headers.get("User-Agent") or "").split()
95
+
96
+
97
+ def write_config(user_agent):
98
+ """Writes the Playwright MCP config file that sends user_agent followed by AGENT_UA_MARK on every request of the
99
+ browser and returns its path. The browser sets User-Agent itself, on navigations, redirects and subresources, and
100
+ a CORS request does not count it as an author header, so no preflight is added; a header in extraHTTPHeaders
101
+ forced one on every cross-origin fetch and font."""
92
102
  os.makedirs(os.path.dirname(CONFIG_PATH), exist_ok=True)
93
- config = {"browser": {"contextOptions": {"extraHTTPHeaders": {AGENT_HEADER: "1"}}}}
103
+ config = {"browser": {"contextOptions": {"userAgent": f"{user_agent} {AGENT_UA_MARK}"}}}
94
104
  atomic_io.write_secret_text(CONFIG_PATH, json.dumps(config, indent=1))
95
105
  return CONFIG_PATH
96
106
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allansantos-dev/smart-tool",
3
- "version": "0.9.73",
3
+ "version": "0.9.74",
4
4
  "description": "Local MCP server that gives coding agents (Claude Code, Codex) cheaper, sharper tools than their built-in search. Windows.",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Smart Tool contributors",
@@ -4409,9 +4409,9 @@ class MCPHandler(BaseHTTPRequestHandler):
4409
4409
  return origin is None or _loopback_host(origin, require_port=True)
4410
4410
 
4411
4411
  def _reject_foreign_origin(self):
4412
- """The agent's browser (Playwright MCP marks every request with AGENT_HEADER) never reaches the daemon: a page
4412
+ """The agent's browser (Playwright MCP marks the User-Agent of every request) never reaches the daemon: a page
4413
4413
  it opens could otherwise steer the agent into /setup, whose token unlocks every setting."""
4414
- if self.headers.get(browser_control.AGENT_HEADER):
4414
+ if browser_control.is_agent_browser(self.headers):
4415
4415
  self._write_json(403, {"error": "Smart Tool's pages are not available to the agent's browser"})
4416
4416
  return True
4417
4417
  if self._origin_allowed():
package/version.py CHANGED
@@ -1,7 +1,7 @@
1
1
  """Single source of the Smart Tool version and of the User-Agent sent to public APIs."""
2
2
  import re
3
3
 
4
- VERSION = "0.9.73"
4
+ VERSION = "0.9.74"
5
5
  _CONTACT_RE = re.compile(r"^(?:[^\s@()<>;]+@[^\s@()<>;]+\.[^\s@()<>;]+|https?://[^\s()<>;]+)$")
6
6
 
7
7