Skip to content

Commit 6e3ca36

Browse files
Add configurable Camofox browser MCP
1 parent 8105ac0 commit 6e3ca36

6 files changed

Lines changed: 256 additions & 23 deletions

File tree

‎.env.example‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,20 @@ SEARXNG_INSTANCE=http://localhost:8080
170170
# needed there.
171171
# ODYSSEUS_INPROCESS_TASKS=1
172172

173+
# Built-in browser MCP provider: playwright (upstream default), camofox,
174+
# disabled, or auto. `auto` selects Camofox only when CAMOFOX_URL is set.
175+
# Camofox MCP is a stdio adapter and still needs an independent
176+
# camofox-browser service (default http://127.0.0.1:9377).
177+
# ODYSSEUS_BROWSER_MCP_PROVIDER=playwright
178+
# CAMOFOX_URL=http://127.0.0.1:9377
179+
# CAMOFOX_API_KEY=
180+
# CAMOFOX_PROFILES_DIR=
181+
# CAMOFOX_VIEWPORT=1366x768
182+
# CAMOFOX_DEFAULT_USER_ID=
183+
# Set this to 1 to forbid npx from downloading the selected provider package
184+
# during application startup.
185+
# ODYSSEUS_BROWSER_MCP_REQUIRE_CACHE=0
186+
173187
# Host used by the built-in "run_script" scheduled-task action.
174188
# Empty/local/localhost runs scripts on the app host. Set to an SSH host alias
175189
# if you intentionally want scheduled scripts to run remotely.

‎docs/ULYSSES_DEPLOYMENT.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,23 @@ The runtime checkout never receives the production checkout's `.venv`,
1515
`Ulysses-state/ulysses.env`; that file sets `ODYSSEUS_DATA_DIR` to the external
1616
state tree. A runtime rebuild therefore cannot delete user data.
1717

18+
## Browser MCP selection
19+
20+
Browser automation is an explicit deployment choice, independent of any
21+
package left in an npx cache:
22+
23+
```dotenv
24+
ODYSSEUS_BROWSER_MCP_PROVIDER=camofox
25+
CAMOFOX_URL=http://127.0.0.1:9377
26+
```
27+
28+
This registers `camofox-mcp` as the Odysseus agent's built-in browser adapter.
29+
The separately managed `camofox-browser` service must be reachable at
30+
`CAMOFOX_URL`. A cached Playwright MCP cannot override `camofox`; use
31+
`ODYSSEUS_BROWSER_MCP_PROVIDER=disabled` to register no browser MCP at all.
32+
The upstream-compatible default remains `playwright` for installations that do
33+
not set the variable.
34+
1835
## Inspect without changing anything
1936

2037
From the clean source checkout:

‎docs/ULYSSES_ROADMAP.md‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ design skeleton:
5151
digest and retain one atomic rollback binary;
5252
- Hermes remains a separately installed agent. Its host runtime, updater
5353
integration, and MCP registry are managed without merging it with the
54-
Odysseus agent MCP registry.
54+
Odysseus agent MCP registry;
55+
- the Odysseus agent's built-in browser MCP is now an explicit provider
56+
selection. This host selects Camofox and a cached Playwright package cannot
57+
override it.
5558

5659
Remaining transition gates are deliberately hardware/stateful: build both
5760
Colibri source trees on the 5090, validate the completed model downloads, run
@@ -486,8 +489,9 @@ Service-specific caution:
486489
Playwright or Playwright's Chromium.
487490
- keep Firecrawl's browser automation encapsulated inside its own containers;
488491
it does not satisfy or create a general host-browser dependency.
489-
- an existing optional Odysseus Playwright MCP may be reported and disabled,
490-
but never removed or replaced without an explicit adoption plan.
492+
- report an existing optional Odysseus Playwright MCP separately from the
493+
selected provider. Its package and browser caches are removable only through
494+
an explicit maintenance action.
491495

492496
### 8. Native Services UI
493497

@@ -613,6 +617,8 @@ corresponding rollback has been tested.
613617
production-state capture and canonical uv environment workflow.
614618
10. [x] Surface `liburing-dev` as a first-class native Cookbook dependency for
615619
the Colibri Hy3 `IOURING=1` build.
616-
11. [ ] During the maintenance window, capture final production state, create
620+
11. [x] Make the built-in browser MCP provider explicit and configure the
621+
candidate for the existing Camofox backend without Playwright fallback.
622+
12. [ ] During the maintenance window, capture final production state, create
617623
the candidate venv, validate CUDA/ONNX and Colibri, then benchmark before
618624
any port cutover.

‎docs/setup.md‎

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -517,17 +517,45 @@ Key settings:
517517

518518
All upload-limit vars are validated (must be a positive integer) and optional; an invalid value fails fast at startup.
519519

520-
### Built-in MCP servers (optional setup)
520+
### Built-in MCP servers and browser provider
521521

522-
Odysseus auto-registers a few built-in MCP servers at startup. The npx-based ones (currently the browser server, `@playwright/mcp`) only start when their npm package is already in the local npx cache. If a package isn't cached, that server is skipped with a startup log message explaining what to do, so a fresh install does not block on a multi-minute npm download or hang if Playwright system deps are missing.
522+
Odysseus auto-registers its Python built-in MCP servers at startup. Browser
523+
automation is a separately selectable npx-based MCP provider:
523524

524-
To enable the browser MCP (page navigation, screenshots, vision), run once:
525+
```dotenv
526+
# Backward-compatible upstream default
527+
ODYSSEUS_BROWSER_MCP_PROVIDER=playwright
528+
529+
# Existing external camofox-browser service
530+
# ODYSSEUS_BROWSER_MCP_PROVIDER=camofox
531+
# CAMOFOX_URL=http://127.0.0.1:9377
532+
533+
# No built-in browser MCP (does not uninstall either package)
534+
# ODYSSEUS_BROWSER_MCP_PROVIDER=disabled
535+
```
536+
537+
`auto` selects Camofox only when `CAMOFOX_URL` is explicitly configured;
538+
otherwise it selects Playwright. A cached Playwright package never overrides an
539+
explicit `camofox` or `disabled` selection.
540+
541+
To install the Playwright MCP package once:
525542

526543
```bash
527544
npx -y @playwright/mcp@latest --version
528545
```
529546

530-
That installs `@playwright/mcp` plus Playwright (~300MB total). Restart Odysseus and the server will register at startup.
547+
To install Camofox MCP and start its required independent browser service:
548+
549+
```bash
550+
npx -y camofox-mcp@latest --version
551+
npx camofox-browser@latest
552+
```
553+
554+
Camofox MCP uses stdio for Odysseus while calling the browser service at
555+
`CAMOFOX_URL` (default `http://127.0.0.1:9377`). Set `CAMOFOX_API_KEY` when that
556+
service requires authentication. Set `ODYSSEUS_BROWSER_MCP_REQUIRE_CACHE=1` to
557+
forbid npx package downloads during Odysseus startup; a missing selected package
558+
is then reported and skipped.
531559

532560
## Architecture
533561
```

‎src/builtin_mcp.py‎

Lines changed: 83 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,76 @@ def _find_npx() -> str:
7676
"email": ("mcp_servers/email_server.py", "Built-in: Email"),
7777
}
7878

79-
# NPX-based built-in servers (run via npx, not Python)
80-
_BUILTIN_NPX_SERVERS = {
81-
"builtin_browser": {
82-
"name": "Built-in: Browser",
83-
"command": "npx",
84-
"args": ["-y", "@playwright/mcp@latest", "--headless", "--caps", "vision"],
85-
}
79+
# Browser MCP providers. Both use the canonical npx command, which may resolve
80+
# through Sandwich/Bun on a Node-free host. Camofox MCP is only the stdio MCP
81+
# adapter; its independent camofox-browser service must also be reachable.
82+
_PLAYWRIGHT_BROWSER_SERVER = {
83+
"name": "Built-in: Browser (Playwright)",
84+
"command": "npx",
85+
"args": ["-y", "@playwright/mcp@latest", "--headless", "--caps", "vision"],
86+
"provider": "playwright",
87+
}
88+
_CAMOFOX_BROWSER_SERVER = {
89+
"name": "Built-in: Browser (Camofox)",
90+
"command": "npx",
91+
"args": ["-y", "camofox-mcp@latest"],
92+
"provider": "camofox",
8693
}
8794

8895
# Global flag to disable MCP if there are compatibility issues
8996
MCP_DISABLED = os.environ.get("ODYSSEUS_DISABLE_MCP", "").lower() in ("1", "true", "yes")
9097
BROWSER_MCP_REQUIRE_CACHE = os.environ.get("ODYSSEUS_BROWSER_MCP_REQUIRE_CACHE", "").lower() in ("1", "true", "yes")
98+
_BROWSER_MCP_PROVIDERS = {"playwright", "camofox", "disabled", "auto"}
99+
100+
101+
def browser_mcp_provider() -> str:
102+
"""Resolve the explicitly selected browser MCP provider.
103+
104+
``playwright`` preserves the upstream default. ``auto`` chooses Camofox
105+
only when CAMOFOX_URL is explicitly configured; it never guesses from a
106+
cached npm package. ``disabled`` suppresses browser MCP registration while
107+
leaving packages and browser services untouched.
108+
"""
109+
configured = os.environ.get("ODYSSEUS_BROWSER_MCP_PROVIDER", "playwright")
110+
provider = configured.strip().lower()
111+
if provider not in _BROWSER_MCP_PROVIDERS:
112+
logger.warning(
113+
"Invalid ODYSSEUS_BROWSER_MCP_PROVIDER=%r; browser MCP is disabled",
114+
configured,
115+
)
116+
return "disabled"
117+
if provider == "auto":
118+
return "camofox" if os.environ.get("CAMOFOX_URL", "").strip() else "playwright"
119+
return provider
120+
121+
122+
def _browser_server_config() -> dict | None:
123+
provider = browser_mcp_provider()
124+
if provider == "disabled":
125+
return None
126+
source = _CAMOFOX_BROWSER_SERVER if provider == "camofox" else _PLAYWRIGHT_BROWSER_SERVER
127+
return {
128+
**source,
129+
"args": list(source["args"]),
130+
}
131+
132+
133+
def _camofox_mcp_env() -> dict[str, str]:
134+
"""Pass only the documented Camofox MCP settings into its subprocess."""
135+
env = {
136+
"CAMOFOX_URL": os.environ.get("CAMOFOX_URL", "http://127.0.0.1:9377").strip()
137+
or "http://127.0.0.1:9377",
138+
}
139+
for name in (
140+
"CAMOFOX_API_KEY",
141+
"CAMOFOX_PROFILES_DIR",
142+
"CAMOFOX_VIEWPORT",
143+
"CAMOFOX_DEFAULT_USER_ID",
144+
):
145+
value = os.environ.get(name)
146+
if value is not None:
147+
env[name] = value
148+
return env
91149

92150

93151
# Strong references to the fire-and-forget startup tasks scheduled below.
@@ -196,18 +254,26 @@ async def _connect_python_server(server_id: str, script_path: str, name: str):
196254
continue
197255
_spawn_bg(_connect_python_server(server_id, script_path, name))
198256

199-
# Register NPX-based servers in the background (they take longer to start)
257+
# Register the selected browser MCP in the background (it takes longer to
258+
# start than the Python servers). A cached Playwright package never wins
259+
# over an explicit Camofox/disabled selection.
260+
browser_server = _browser_server_config()
261+
if browser_server is None:
262+
logger.info(
263+
"Built-in browser MCP disabled via ODYSSEUS_BROWSER_MCP_PROVIDER"
264+
)
265+
return
200266
npx_path = _find_npx()
201267
logger.info(f"NPX binary resolved to: {npx_path}")
202268

203269
async def _start_npx_servers():
204270
await asyncio.sleep(3) # let Python servers finish first
205-
for server_id, cfg in _BUILTIN_NPX_SERVERS.items():
206-
# Browser automation is a shipped built-in, so the default path
207-
# lets `npx -y` install @playwright/mcp on first start. Locked-down
208-
# installs can opt back into the old no-network startup behavior
209-
# with ODYSSEUS_BROWSER_MCP_REQUIRE_CACHE=1.
210-
args = _browser_mcp_args(cfg["args"]) if server_id == "builtin_browser" else list(cfg["args"])
271+
for server_id, cfg in {"builtin_browser": browser_server}.items():
272+
args = (
273+
_browser_mcp_args(cfg["args"])
274+
if cfg["provider"] == "playwright"
275+
else list(cfg["args"])
276+
)
211277
pkg_spec = _npx_package_from_args(args)
212278
if BROWSER_MCP_REQUIRE_CACHE and pkg_spec and not await _is_npx_package_cached(npx_path, pkg_spec):
213279
logger.warning(
@@ -224,7 +290,7 @@ async def _start_npx_servers():
224290
logger.info(f"Starting NPX server: {cfg['name']} ({npx_path} {' '.join(args)})")
225291
try:
226292
env = None
227-
if server_id == "builtin_browser":
293+
if cfg["provider"] == "playwright":
228294
cache_home = os.environ.get(
229295
"ODYSSEUS_BROWSER_MCP_CACHE",
230296
os.path.join(base_dir, "data", "local", "playwright-mcp-cache"),
@@ -234,6 +300,8 @@ async def _start_npx_servers():
234300
"XDG_CACHE_HOME": cache_home,
235301
"PLAYWRIGHT_BROWSERS_PATH": os.path.join(cache_home, "browsers"),
236302
}
303+
elif cfg["provider"] == "camofox":
304+
env = _camofox_mcp_env()
237305
ok = await mcp_manager.connect_server(
238306
server_id=server_id,
239307
name=cfg["name"],

‎tests/test_builtin_mcp_npx_cache.py‎

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,106 @@ def test_browser_mcp_cache_requirement_can_be_enabled(monkeypatch):
5050
assert builtin_mcp.BROWSER_MCP_REQUIRE_CACHE is True
5151

5252

53+
def test_browser_provider_defaults_to_playwright_for_compatibility(monkeypatch):
54+
monkeypatch.delenv("ODYSSEUS_BROWSER_MCP_PROVIDER", raising=False)
55+
monkeypatch.delenv("CAMOFOX_URL", raising=False)
56+
builtin_mcp = _load_builtin_mcp(monkeypatch)
57+
58+
assert builtin_mcp.browser_mcp_provider() == "playwright"
59+
assert builtin_mcp._browser_server_config()["provider"] == "playwright"
60+
61+
62+
def test_browser_provider_can_select_camofox_without_playwright_args(monkeypatch):
63+
monkeypatch.setenv("ODYSSEUS_BROWSER_MCP_PROVIDER", "camofox")
64+
monkeypatch.setenv("CAMOFOX_URL", "http://127.0.0.1:9377")
65+
builtin_mcp = _load_builtin_mcp(monkeypatch)
66+
67+
config = builtin_mcp._browser_server_config()
68+
assert config["provider"] == "camofox"
69+
assert config["args"] == ["-y", "camofox-mcp@latest"]
70+
assert "@playwright/mcp" not in " ".join(config["args"])
71+
assert builtin_mcp._camofox_mcp_env() == {
72+
"CAMOFOX_URL": "http://127.0.0.1:9377"
73+
}
74+
75+
76+
def test_browser_provider_can_be_disabled_without_uninstalling(monkeypatch):
77+
monkeypatch.setenv("ODYSSEUS_BROWSER_MCP_PROVIDER", "disabled")
78+
builtin_mcp = _load_builtin_mcp(monkeypatch)
79+
80+
assert builtin_mcp._browser_server_config() is None
81+
82+
83+
def test_browser_provider_auto_requires_explicit_camofox_url(monkeypatch):
84+
monkeypatch.setenv("ODYSSEUS_BROWSER_MCP_PROVIDER", "auto")
85+
monkeypatch.delenv("CAMOFOX_URL", raising=False)
86+
builtin_mcp = _load_builtin_mcp(monkeypatch)
87+
assert builtin_mcp.browser_mcp_provider() == "playwright"
88+
89+
monkeypatch.setenv("CAMOFOX_URL", "http://localhost:9377")
90+
assert builtin_mcp.browser_mcp_provider() == "camofox"
91+
92+
93+
def test_invalid_browser_provider_fails_closed(monkeypatch):
94+
monkeypatch.setenv("ODYSSEUS_BROWSER_MCP_PROVIDER", "mystery")
95+
builtin_mcp = _load_builtin_mcp(monkeypatch)
96+
97+
assert builtin_mcp.browser_mcp_provider() == "disabled"
98+
assert builtin_mcp._browser_server_config() is None
99+
100+
101+
def test_register_builtin_browser_uses_camofox_command_and_env(monkeypatch):
102+
monkeypatch.setenv("ODYSSEUS_BROWSER_MCP_PROVIDER", "camofox")
103+
monkeypatch.setenv("CAMOFOX_URL", "http://127.0.0.1:9377")
104+
monkeypatch.delenv("ODYSSEUS_BROWSER_MCP_REQUIRE_CACHE", raising=False)
105+
builtin_mcp = _load_builtin_mcp(monkeypatch)
106+
scheduled = []
107+
calls = []
108+
109+
class Manager:
110+
async def connect_server(self, **kwargs):
111+
calls.append(kwargs)
112+
return True
113+
114+
async def no_sleep(_seconds):
115+
return None
116+
117+
monkeypatch.setattr(builtin_mcp, "_BUILTIN_SERVERS", {})
118+
monkeypatch.setattr(builtin_mcp, "_find_npx", lambda: "/sandwich/bin/npx")
119+
monkeypatch.setattr(builtin_mcp, "_spawn_bg", scheduled.append)
120+
monkeypatch.setattr(builtin_mcp.asyncio, "sleep", no_sleep)
121+
122+
async def run():
123+
await builtin_mcp.register_builtin_servers(Manager())
124+
assert len(scheduled) == 1
125+
await scheduled[0]
126+
127+
asyncio.run(run())
128+
129+
assert calls == [{
130+
"server_id": "builtin_browser",
131+
"name": "Built-in: Browser (Camofox)",
132+
"transport": "stdio",
133+
"command": "/sandwich/bin/npx",
134+
"args": ["-y", "camofox-mcp@latest"],
135+
"env": {"CAMOFOX_URL": "http://127.0.0.1:9377"},
136+
}]
137+
assert "@playwright/mcp" not in repr(calls)
138+
139+
140+
def test_register_builtin_browser_disabled_schedules_no_npx(monkeypatch):
141+
monkeypatch.setenv("ODYSSEUS_BROWSER_MCP_PROVIDER", "disabled")
142+
builtin_mcp = _load_builtin_mcp(monkeypatch)
143+
scheduled = []
144+
145+
monkeypatch.setattr(builtin_mcp, "_BUILTIN_SERVERS", {})
146+
monkeypatch.setattr(builtin_mcp, "_spawn_bg", scheduled.append)
147+
148+
asyncio.run(builtin_mcp.register_builtin_servers(object()))
149+
150+
assert scheduled == []
151+
152+
53153
def test_browser_mcp_args_use_configured_browser_executable(monkeypatch):
54154
monkeypatch.setenv("ODYSSEUS_BROWSER_EXECUTABLE", "/usr/bin/chromium")
55155
builtin_mcp = _load_builtin_mcp(monkeypatch)

0 commit comments

Comments
 (0)