Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion hermes_cli/mcp_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,47 @@
_ENV_VAR_NAME_RE = re.compile(r"^[A-Za-z_][A-Za-z0-9_]*$")


_MCP_PRESETS: Dict[str, Dict[str, Any]] = {}
def _playwright_mcp_args() -> list:
"""Build @playwright/mcp args with root-safe flags and chromium fallback.

On Linux root (VPS/Docker), Chrome refuses to start without --no-sandbox.
When system Chrome is absent, fall back to the bundled chromium channel.
"""
import os as _os
args = ["-y", "@playwright/mcp@latest", "--headless"]

# Detect missing system Chrome and fall back to bundled chromium
if not _os.path.exists("/opt/google/chrome/chrome"):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This checks only one Linux Chrome path, so it classifies normal PATH installs, /usr/bin installs, macOS, and Windows browsers as absent. Please use a platform-aware resolver (or avoid overriding Playwright MCP's default browser choice) and add coverage for a system browser outside /opt.

args += ["--browser", "chromium"]

# Inject --no-sandbox when running as root or AppArmor userns restricted
_needs_sandbox_bypass = False
if hasattr(_os, "geteuid") and _os.geteuid() == 0:
_needs_sandbox_bypass = True
else:
try:
with open("/proc/sys/kernel/apparmor_restrict_unprivileged_userns") as _f:
if _f.read().strip() == "1":
_needs_sandbox_bypass = True
except OSError:
pass
if _needs_sandbox_bypass:
args.append("--no-sandbox")

return args


_MCP_PRESETS: Dict[str, Dict[str, Any]] = {
"playwright": {
"command": "npx",
"args": _playwright_mcp_args(),
"description": (
"Playwright MCP browser automation — auto-detects root/AppArmor "
"sandbox restrictions and falls back to bundled Chromium when "
"system Chrome is absent."
),
},
}


# ─── UI Helpers ───────────────────────────────────────────────────────────────
Expand Down
Loading