onyxweb-server 0.1.0__tar.gz
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.
- onyxweb_server-0.1.0/.gitignore +33 -0
- onyxweb_server-0.1.0/CHANGELOG.md +29 -0
- onyxweb_server-0.1.0/PKG-INFO +122 -0
- onyxweb_server-0.1.0/README.md +95 -0
- onyxweb_server-0.1.0/onyxweb_server/__init__.py +6 -0
- onyxweb_server-0.1.0/onyxweb_server/__main__.py +89 -0
- onyxweb_server-0.1.0/onyxweb_server/core.py +834 -0
- onyxweb_server-0.1.0/onyxweb_server/egress.py +310 -0
- onyxweb_server-0.1.0/onyxweb_server/http.py +322 -0
- onyxweb_server-0.1.0/onyxweb_server/mcp.py +826 -0
- onyxweb_server-0.1.0/onyxweb_server/py.typed +0 -0
- onyxweb_server-0.1.0/pyproject.toml +98 -0
- onyxweb_server-0.1.0/tests/conftest.py +95 -0
- onyxweb_server-0.1.0/tests/test_c13_agent_tools.py +1192 -0
- onyxweb_server-0.1.0/tests/test_c14_server_core.py +813 -0
- onyxweb_server-0.1.0/tests/test_c15_http_api.py +589 -0
- onyxweb_server-0.1.0/tests/test_c16_server_cli.py +120 -0
- onyxweb_server-0.1.0/tests/test_c18_egress_guard.py +521 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Rust
|
|
2
|
+
/target/
|
|
3
|
+
|
|
4
|
+
# Python
|
|
5
|
+
__pycache__/
|
|
6
|
+
*.pyc
|
|
7
|
+
*.pyo
|
|
8
|
+
*.egg-info/
|
|
9
|
+
dist/
|
|
10
|
+
*.so
|
|
11
|
+
*.pyd
|
|
12
|
+
|
|
13
|
+
# IDE
|
|
14
|
+
.idea/
|
|
15
|
+
|
|
16
|
+
# Env
|
|
17
|
+
.venv/
|
|
18
|
+
.env
|
|
19
|
+
|
|
20
|
+
# Maturin
|
|
21
|
+
*.whl
|
|
22
|
+
|
|
23
|
+
# OS
|
|
24
|
+
.DS_Store
|
|
25
|
+
|
|
26
|
+
# Ruff
|
|
27
|
+
.ruff_cache/
|
|
28
|
+
|
|
29
|
+
CLAUDE.md
|
|
30
|
+
|
|
31
|
+
# Bundled chromium binaries — populated at wheel build time (`uv run onyxweb-download-chrome`).
|
|
32
|
+
# Not committed to git (too large); maturin `include` picks them up from disk.
|
|
33
|
+
python/onyxweb/onyxweb/_binaries/
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to onyxweb-server. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
|
|
4
|
+
|
|
5
|
+
## [Unreleased]
|
|
6
|
+
|
|
7
|
+
## [0.1.0] - 2026-09-22
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
- A JSON body sent to an HTTP route without `Content-Type: application/json` is a 422 that names the fix, where `POST /fetch` read it anyway.
|
|
11
|
+
- The default engine is `full`, a real Chrome, and the server's own clients wait out bot-check pages unless a call passes `bypass_anti_bot: false`. On 22 popular sites the full engine passed 18 and the shell 10. `engine="shell"` is lighter and faster; `onyxweb --install` fetches both.
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
- The MCP server offers `screenshot` and `batch`, and `fetch` takes every option the core allows: `timeout_ms`, `wait_until`, `headers`, `block_urls`, `bypass_anti_bot`, and `screenshot` for an image from the same visit.
|
|
15
|
+
- An MCP image over 5 MB is refused by `screenshot` and left out of `fetch` with a note, since an image cannot be cut. `batch` fetches up to 50 URLs, holds each page and lists an id per URL, with a failure in its place.
|
|
16
|
+
- The core owns every policy, so MCP and HTTP refuse the same things: `FetchOptions` and `ShotOptions` allow only `engine`, `wait_ms`, `timeout_ms`, `wait_until`, headers, `block_urls`, `bypass_anti_bot` and the image options, each within a ceiling; `ServerCore.screenshot`, `fetch_all` and `batch` join `fetch`; every refusal is a `Refused`, whose subclasses `RefusedUrl`, `RefusedOption` and `TooLarge` carry the `code` a front-end maps (`refused_url`, `refused_option`, `too_large`), so a caller can catch one cause or all of them.
|
|
17
|
+
- `ONYXWEB_SERVER_*` limits: pages and bytes held, the largest page or image, batch size, wait and timeout ceilings, tabs per engine, and a queue timeout (10 s), so a saturated server answers `queue_timeout` instead of waiting forever.
|
|
18
|
+
- An egress proxy on 127.0.0.1 that the browser is pointed at. It refuses any private, loopback or link-local address at connect time, so a redirect, a DNS rebinding host or a page's own script cannot reach one. `ONYXWEB_SERVER_EGRESS=0` turns it off.
|
|
19
|
+
- A Chrome that dies mid-call is replaced and the call retried once. `ServerCore.stats()` and `GET /health` report requests, failures by kind, retries, restarts, pages held and egress refusals, and each call logs one line to the `onyxweb_server` logger without its query string.
|
|
20
|
+
- `POST /fetch` answers 413 with kind `too_large` for a page over the size limit.
|
|
21
|
+
- `POST /screenshot`, `POST /fetch_all` and `POST /batch`. `/screenshot` returns the image itself; `/fetch_all` returns the page and its image as base64 in one JSON object; `/batch` returns one NDJSON line per URL in the order given, with a URL that failed as an `error` line in its place. `/fetch` takes `timeout_ms`, `wait_until`, `headers`, `block_urls` and `bypass_anti_bot`.
|
|
22
|
+
- `ONYXWEB_SERVER_TOKEN` requires `Authorization: Bearer <token>` on every HTTP route but `/health`. `onyxweb-server http` exits 1 for a non-loopback `--host` unless it is set.
|
|
23
|
+
- `onyxweb-server http`, an HTTP front-end: `POST /fetch` returns the page as a snapshot (zstd when the caller accepts it), `GET /health` reports each engine's Chrome. It holds nothing between requests, refuses `scripts`, `post_load_scripts` and `actions` by name, and binds loopback by default. Install it with `pip install "onyxweb-server[http]"`.
|
|
24
|
+
- `onyxweb-server mcp`, an MCP server that lets an agent fetch a page, ask several questions of it in one `query` call, then find and read the details. Install it with `pip install "onyxweb-server[mcp]"`.
|
|
25
|
+
Pages stay in memory for the session, and every tool caps its output. It runs no caller-supplied scripts and never fetches a private, loopback or link-local address. Everything a page wrote, its title and URL included, appears below the untrusted label.
|
|
26
|
+
- `onyxweb_server.core.ServerCore`, the part every front-end shares: a guarded, stateless `fetch`, held pages, and a browser client per engine that is rebuilt after its Chrome dies. `ONYXWEB_SERVER_MAX_PAGES` (default 50) sets how many pages it holds.
|
|
27
|
+
|
|
28
|
+
[Unreleased]: https://github.com/ausmaster/onyxweb/compare/server-v0.1.0...HEAD
|
|
29
|
+
[0.1.0]: https://github.com/ausmaster/onyxweb/releases/tag/server-v0.1.0
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: onyxweb-server
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Serve onyxweb's browser to agents over MCP
|
|
5
|
+
Project-URL: Homepage, https://github.com/ausmaster/onyxweb
|
|
6
|
+
Project-URL: Repository, https://github.com/ausmaster/onyxweb
|
|
7
|
+
Project-URL: Issues, https://github.com/ausmaster/onyxweb/issues
|
|
8
|
+
Author-email: AusMaster <ausmasterproductions@gmail.com>
|
|
9
|
+
License: BSD-3-Clause
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: BSD License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Typing :: Typed
|
|
18
|
+
Requires-Python: >=3.11
|
|
19
|
+
Requires-Dist: onyxweb>=0.3.0
|
|
20
|
+
Provides-Extra: http
|
|
21
|
+
Requires-Dist: fastapi>=0.115; extra == 'http'
|
|
22
|
+
Requires-Dist: uvicorn>=0.30; extra == 'http'
|
|
23
|
+
Requires-Dist: zstandard>=0.23; extra == 'http'
|
|
24
|
+
Provides-Extra: mcp
|
|
25
|
+
Requires-Dist: mcp<2,>=1.2; extra == 'mcp'
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# onyxweb-server
|
|
29
|
+
|
|
30
|
+
Serves [onyxweb](https://github.com/ausmaster/onyxweb)'s browser to agents over MCP and to programs over HTTP.
|
|
31
|
+
|
|
32
|
+
Requires Python 3.11+ and the browsers from `onyxweb --install`, which fetches both the headless shell and full Chrome. The default engine is the full Chrome; `engine="shell"` is lighter and faster, and many sites block it. Running in Docker, or as BBOT does, needs `sandbox=False`: see "Docker and BBOT" in the [onyxweb README](../../README.md).
|
|
33
|
+
|
|
34
|
+
## HTTP
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
uv tool install "onyxweb-server[http]" # or: pip install "onyxweb-server[http]"
|
|
38
|
+
onyxweb-server http --port 8000 # binds 127.0.0.1
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
| Route | Returns |
|
|
42
|
+
|---|---|
|
|
43
|
+
| `POST /fetch` | the whole page as `RenderResult.snapshot()` JSON; `RenderResult.load` rebuilds it |
|
|
44
|
+
| `POST /screenshot` | the image itself, as `image/png`, `image/jpeg` or `image/webp` |
|
|
45
|
+
| `POST /fetch_all` | `{"snapshot": {...}, "image": "<base64>", "format": "png"}`: the page and its image from one visit |
|
|
46
|
+
| `POST /batch` | NDJSON in the order given, one line per URL: `{"url", "snapshot"}`, or `{"url", "error"}` for a URL that failed |
|
|
47
|
+
| `GET /health` | `{"status": "ok", "engines": {"full": true}, "stats": {...}}`: each engine built so far and whether its Chrome is alive, plus counters (requests, failures by kind, retries, restarts, pages held, egress refusals) |
|
|
48
|
+
|
|
49
|
+
Every body is a JSON object sent with `Content-Type: application/json`. A route accepts the fields below and refuses any other by name:
|
|
50
|
+
|
|
51
|
+
| Route | Fields |
|
|
52
|
+
|---|---|
|
|
53
|
+
| `/fetch` | `url`, `engine`, `wait_ms`, `timeout_ms`, `wait_until`, `headers`, `block_urls`, `bypass_anti_bot` |
|
|
54
|
+
| `/screenshot` | `url`, `engine`, `wait_ms`, `timeout_ms`, `wait_until`, `headers`, `full_page`, `format`, `quality`, `viewport` |
|
|
55
|
+
| `/fetch_all` | the `/fetch` fields, plus `full_page`, `format` and `quality` |
|
|
56
|
+
| `/batch` | `urls` in place of `url`, and the other `/fetch` fields, applied to every URL |
|
|
57
|
+
|
|
58
|
+
Send `Accept-Encoding: zstd` to get JSON compressed (about 9x on a 7 MB page). A batch is compressed as it is written, and an image never is. `scripts`, `post_load_scripts` and `actions` are refused with a 400, because the server never runs caller-supplied JavaScript, and so is a private, loopback or link-local address. The server holds nothing between requests.
|
|
59
|
+
|
|
60
|
+
A failure is `{"error": {"kind": ..., "message": ..., "url": ...}}` with a status from the kind:
|
|
61
|
+
|
|
62
|
+
| Status | Kinds |
|
|
63
|
+
|---|---|
|
|
64
|
+
| 400 | `invalid_url`, `invalid_config`, `post_load_script`, `invalid_request` (a refused option or URL), `refused_field` |
|
|
65
|
+
| 401 | `unauthorized` |
|
|
66
|
+
| 413 | `too_large` |
|
|
67
|
+
| 422 | `invalid_request` (a body that is not a JSON object, or a missing or unknown field) |
|
|
68
|
+
| 502 | `cdp`, `io` |
|
|
69
|
+
| 503 | `chrome_exited`, `queue_timeout`, `launch_failed`, `chrome_not_found` |
|
|
70
|
+
| 504 | `navigation_timeout`, `timeout` |
|
|
71
|
+
| 500 | `internal`, and any kind not listed |
|
|
72
|
+
|
|
73
|
+
One bad URL never fails a batch. Its line carries the same `error` object, with the same `kind`, and the status stays 200. A batch that is itself refused, with 0 URLs or more than `MAX_BATCH`, is a 400.
|
|
74
|
+
|
|
75
|
+
Set `ONYXWEB_SERVER_TOKEN` to require `Authorization: Bearer <token>` on every route but `/health`. Without a token, `onyxweb-server http` listens on loopback only and exits 1 for any other `--host`. The server has no other authentication, so put a reverse proxy in front before exposing it.
|
|
76
|
+
|
|
77
|
+
## Limits and egress
|
|
78
|
+
|
|
79
|
+
Both front-ends share one core, so they refuse the same things. `ONYXWEB_SERVER_*` variables set the limits:
|
|
80
|
+
|
|
81
|
+
| Variable | Default | Sets |
|
|
82
|
+
|---|---:|---|
|
|
83
|
+
| `MAX_PAGES` | 50 | pages held per session |
|
|
84
|
+
| `MAX_STORE_BYTES` | 268435456 | bytes of html held; the least recently used page goes first |
|
|
85
|
+
| `MAX_PAGE_BYTES` | 20971520 | largest page or image one call may return |
|
|
86
|
+
| `MAX_BATCH` | 50 | URLs in one batch |
|
|
87
|
+
| `MAX_WAIT_MS` | 30000 | longest settle after the page loads |
|
|
88
|
+
| `MAX_TIMEOUT_MS` | 60000 | longest navigation budget |
|
|
89
|
+
| `QUEUE_MS` | 10000 | longest a request waits for a free tab, then `queue_timeout` |
|
|
90
|
+
| `CONCURRENCY` | 4 | tabs per engine |
|
|
91
|
+
| `EGRESS` | 1 | `0` turns the egress proxy off |
|
|
92
|
+
|
|
93
|
+
A caller may set only `engine`, `wait_ms`, `timeout_ms`, `wait_until`, extra headers, `block_urls` and `bypass_anti_bot`, each within a ceiling. A Chrome that dies mid-call is replaced and the call retried once.
|
|
94
|
+
|
|
95
|
+
The browser reaches the network through a proxy the server runs on 127.0.0.1. It resolves every host itself, refuses the request unless every answer is a public address, and connects to the address it checked. So a redirect, a rebinding host, or a page's own script cannot reach a private, loopback or link-local address. A full Chrome opens one connection to `www.google.com` per tab when it starts. The proxy allows it, since the address is public. A refused navigation is refused like a private URL: a 400 over HTTP, a tool error over MCP. A screenshot of a refused plain-HTTP page shows the proxy's refusal text, because an image carries no status. The proxy adds no authentication of its own: it listens on loopback only, and it can reach only public addresses.
|
|
96
|
+
|
|
97
|
+
## MCP
|
|
98
|
+
|
|
99
|
+
`onyxweb-server mcp` lets an agent such as Claude Code fetch a page once, then look, find and read it in pieces, so a large page never floods its context. Pages stay in memory for the session.
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
uv tool install "onyxweb-server[mcp]" # or: pip install "onyxweb-server[mcp]"
|
|
103
|
+
claude mcp add onyxweb -- onyxweb-server mcp # register it, then restart the session
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
| Tool | Returns |
|
|
107
|
+
|---|---|
|
|
108
|
+
| `fetch` | an id, the final URL, status, title and an overview of the page; with `screenshot=true`, also an image of it from the same visit |
|
|
109
|
+
| `batch` | many URLs at once: an id per page in the order given, and a `FAILED` line for each URL that failed |
|
|
110
|
+
| `screenshot` | an image of the page, taking `full_page`, `format`, `quality` and `viewport` |
|
|
111
|
+
| `pages` | every page fetched this session, newest first |
|
|
112
|
+
| `overview` | the count and size of every bucket |
|
|
113
|
+
| `query` | several questions at once: each gets the best-matching passages of the page text; omit `id` to search all pages |
|
|
114
|
+
| `find` | where an exact string or a regex matches, in the page text and every bucket; omit `id` to search all pages |
|
|
115
|
+
| `read` | one record's whole content, in pieces of at most 6,000 characters |
|
|
116
|
+
| `page_text` | what the page displays, in pieces of at most 6,000 characters |
|
|
117
|
+
|
|
118
|
+
Fetch a page, then ask everything you need in one `query` call. Ranking counts word overlap, so it finds passages that use your words and misses ones that only mean the same thing, and it puts navigation, link lists and bare headings below prose ([Boilerpipe](https://dl.acm.org/doi/10.1145/1718487.1718542)'s link-density and word-count features). Use `find` for an exact string, a regex or a bucket. Every tool caps its output and names the `offset` to continue from. Each marks page text as untrusted, and puts that label above the page's title and URL, which the page chose. A page that comes back nearly empty gets a note suggesting `engine="full"` or a longer `wait_ms`.
|
|
119
|
+
|
|
120
|
+
`fetch` and `batch` take `engine`, `wait_ms`, `timeout_ms`, `wait_until`, `headers`, `block_urls` and `bypass_anti_bot`. `screenshot` takes the same except the last 2. The server checks each against its `ONYXWEB_SERVER_*` limits, and a value outside one fails with the limit named. Headers show in the conversation, so an agent sends only what the user gave it. An image cannot be cut, so `screenshot` refuses one over 5 MB and `fetch` leaves it out with a note. Ask for `jpeg` or a smaller `viewport`.
|
|
121
|
+
|
|
122
|
+
Two things are refused outright, with no setting to turn them on. The tools accept no `scripts`, `post_load_scripts` or `actions`. `fetch`, `batch` and `screenshot` refuse any URL whose host resolves to a private, loopback, link-local or otherwise non-public address, and the egress proxy above stops a redirect or a page's own request from reaching one. It speaks stdio only. `ONYXWEB_SERVER_MAX_PAGES` (default 50) sets how many pages it keeps.
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# onyxweb-server
|
|
2
|
+
|
|
3
|
+
Serves [onyxweb](https://github.com/ausmaster/onyxweb)'s browser to agents over MCP and to programs over HTTP.
|
|
4
|
+
|
|
5
|
+
Requires Python 3.11+ and the browsers from `onyxweb --install`, which fetches both the headless shell and full Chrome. The default engine is the full Chrome; `engine="shell"` is lighter and faster, and many sites block it. Running in Docker, or as BBOT does, needs `sandbox=False`: see "Docker and BBOT" in the [onyxweb README](../../README.md).
|
|
6
|
+
|
|
7
|
+
## HTTP
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
uv tool install "onyxweb-server[http]" # or: pip install "onyxweb-server[http]"
|
|
11
|
+
onyxweb-server http --port 8000 # binds 127.0.0.1
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
| Route | Returns |
|
|
15
|
+
|---|---|
|
|
16
|
+
| `POST /fetch` | the whole page as `RenderResult.snapshot()` JSON; `RenderResult.load` rebuilds it |
|
|
17
|
+
| `POST /screenshot` | the image itself, as `image/png`, `image/jpeg` or `image/webp` |
|
|
18
|
+
| `POST /fetch_all` | `{"snapshot": {...}, "image": "<base64>", "format": "png"}`: the page and its image from one visit |
|
|
19
|
+
| `POST /batch` | NDJSON in the order given, one line per URL: `{"url", "snapshot"}`, or `{"url", "error"}` for a URL that failed |
|
|
20
|
+
| `GET /health` | `{"status": "ok", "engines": {"full": true}, "stats": {...}}`: each engine built so far and whether its Chrome is alive, plus counters (requests, failures by kind, retries, restarts, pages held, egress refusals) |
|
|
21
|
+
|
|
22
|
+
Every body is a JSON object sent with `Content-Type: application/json`. A route accepts the fields below and refuses any other by name:
|
|
23
|
+
|
|
24
|
+
| Route | Fields |
|
|
25
|
+
|---|---|
|
|
26
|
+
| `/fetch` | `url`, `engine`, `wait_ms`, `timeout_ms`, `wait_until`, `headers`, `block_urls`, `bypass_anti_bot` |
|
|
27
|
+
| `/screenshot` | `url`, `engine`, `wait_ms`, `timeout_ms`, `wait_until`, `headers`, `full_page`, `format`, `quality`, `viewport` |
|
|
28
|
+
| `/fetch_all` | the `/fetch` fields, plus `full_page`, `format` and `quality` |
|
|
29
|
+
| `/batch` | `urls` in place of `url`, and the other `/fetch` fields, applied to every URL |
|
|
30
|
+
|
|
31
|
+
Send `Accept-Encoding: zstd` to get JSON compressed (about 9x on a 7 MB page). A batch is compressed as it is written, and an image never is. `scripts`, `post_load_scripts` and `actions` are refused with a 400, because the server never runs caller-supplied JavaScript, and so is a private, loopback or link-local address. The server holds nothing between requests.
|
|
32
|
+
|
|
33
|
+
A failure is `{"error": {"kind": ..., "message": ..., "url": ...}}` with a status from the kind:
|
|
34
|
+
|
|
35
|
+
| Status | Kinds |
|
|
36
|
+
|---|---|
|
|
37
|
+
| 400 | `invalid_url`, `invalid_config`, `post_load_script`, `invalid_request` (a refused option or URL), `refused_field` |
|
|
38
|
+
| 401 | `unauthorized` |
|
|
39
|
+
| 413 | `too_large` |
|
|
40
|
+
| 422 | `invalid_request` (a body that is not a JSON object, or a missing or unknown field) |
|
|
41
|
+
| 502 | `cdp`, `io` |
|
|
42
|
+
| 503 | `chrome_exited`, `queue_timeout`, `launch_failed`, `chrome_not_found` |
|
|
43
|
+
| 504 | `navigation_timeout`, `timeout` |
|
|
44
|
+
| 500 | `internal`, and any kind not listed |
|
|
45
|
+
|
|
46
|
+
One bad URL never fails a batch. Its line carries the same `error` object, with the same `kind`, and the status stays 200. A batch that is itself refused, with 0 URLs or more than `MAX_BATCH`, is a 400.
|
|
47
|
+
|
|
48
|
+
Set `ONYXWEB_SERVER_TOKEN` to require `Authorization: Bearer <token>` on every route but `/health`. Without a token, `onyxweb-server http` listens on loopback only and exits 1 for any other `--host`. The server has no other authentication, so put a reverse proxy in front before exposing it.
|
|
49
|
+
|
|
50
|
+
## Limits and egress
|
|
51
|
+
|
|
52
|
+
Both front-ends share one core, so they refuse the same things. `ONYXWEB_SERVER_*` variables set the limits:
|
|
53
|
+
|
|
54
|
+
| Variable | Default | Sets |
|
|
55
|
+
|---|---:|---|
|
|
56
|
+
| `MAX_PAGES` | 50 | pages held per session |
|
|
57
|
+
| `MAX_STORE_BYTES` | 268435456 | bytes of html held; the least recently used page goes first |
|
|
58
|
+
| `MAX_PAGE_BYTES` | 20971520 | largest page or image one call may return |
|
|
59
|
+
| `MAX_BATCH` | 50 | URLs in one batch |
|
|
60
|
+
| `MAX_WAIT_MS` | 30000 | longest settle after the page loads |
|
|
61
|
+
| `MAX_TIMEOUT_MS` | 60000 | longest navigation budget |
|
|
62
|
+
| `QUEUE_MS` | 10000 | longest a request waits for a free tab, then `queue_timeout` |
|
|
63
|
+
| `CONCURRENCY` | 4 | tabs per engine |
|
|
64
|
+
| `EGRESS` | 1 | `0` turns the egress proxy off |
|
|
65
|
+
|
|
66
|
+
A caller may set only `engine`, `wait_ms`, `timeout_ms`, `wait_until`, extra headers, `block_urls` and `bypass_anti_bot`, each within a ceiling. A Chrome that dies mid-call is replaced and the call retried once.
|
|
67
|
+
|
|
68
|
+
The browser reaches the network through a proxy the server runs on 127.0.0.1. It resolves every host itself, refuses the request unless every answer is a public address, and connects to the address it checked. So a redirect, a rebinding host, or a page's own script cannot reach a private, loopback or link-local address. A full Chrome opens one connection to `www.google.com` per tab when it starts. The proxy allows it, since the address is public. A refused navigation is refused like a private URL: a 400 over HTTP, a tool error over MCP. A screenshot of a refused plain-HTTP page shows the proxy's refusal text, because an image carries no status. The proxy adds no authentication of its own: it listens on loopback only, and it can reach only public addresses.
|
|
69
|
+
|
|
70
|
+
## MCP
|
|
71
|
+
|
|
72
|
+
`onyxweb-server mcp` lets an agent such as Claude Code fetch a page once, then look, find and read it in pieces, so a large page never floods its context. Pages stay in memory for the session.
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
uv tool install "onyxweb-server[mcp]" # or: pip install "onyxweb-server[mcp]"
|
|
76
|
+
claude mcp add onyxweb -- onyxweb-server mcp # register it, then restart the session
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
| Tool | Returns |
|
|
80
|
+
|---|---|
|
|
81
|
+
| `fetch` | an id, the final URL, status, title and an overview of the page; with `screenshot=true`, also an image of it from the same visit |
|
|
82
|
+
| `batch` | many URLs at once: an id per page in the order given, and a `FAILED` line for each URL that failed |
|
|
83
|
+
| `screenshot` | an image of the page, taking `full_page`, `format`, `quality` and `viewport` |
|
|
84
|
+
| `pages` | every page fetched this session, newest first |
|
|
85
|
+
| `overview` | the count and size of every bucket |
|
|
86
|
+
| `query` | several questions at once: each gets the best-matching passages of the page text; omit `id` to search all pages |
|
|
87
|
+
| `find` | where an exact string or a regex matches, in the page text and every bucket; omit `id` to search all pages |
|
|
88
|
+
| `read` | one record's whole content, in pieces of at most 6,000 characters |
|
|
89
|
+
| `page_text` | what the page displays, in pieces of at most 6,000 characters |
|
|
90
|
+
|
|
91
|
+
Fetch a page, then ask everything you need in one `query` call. Ranking counts word overlap, so it finds passages that use your words and misses ones that only mean the same thing, and it puts navigation, link lists and bare headings below prose ([Boilerpipe](https://dl.acm.org/doi/10.1145/1718487.1718542)'s link-density and word-count features). Use `find` for an exact string, a regex or a bucket. Every tool caps its output and names the `offset` to continue from. Each marks page text as untrusted, and puts that label above the page's title and URL, which the page chose. A page that comes back nearly empty gets a note suggesting `engine="full"` or a longer `wait_ms`.
|
|
92
|
+
|
|
93
|
+
`fetch` and `batch` take `engine`, `wait_ms`, `timeout_ms`, `wait_until`, `headers`, `block_urls` and `bypass_anti_bot`. `screenshot` takes the same except the last 2. The server checks each against its `ONYXWEB_SERVER_*` limits, and a value outside one fails with the limit named. Headers show in the conversation, so an agent sends only what the user gave it. An image cannot be cut, so `screenshot` refuses one over 5 MB and `fetch` leaves it out with a note. Ask for `jpeg` or a smaller `viewport`.
|
|
94
|
+
|
|
95
|
+
Two things are refused outright, with no setting to turn them on. The tools accept no `scripts`, `post_load_scripts` or `actions`. `fetch`, `batch` and `screenshot` refuse any URL whose host resolves to a private, loopback, link-local or otherwise non-public address, and the egress proxy above stops a redirect or a page's own request from reaching one. It speaks stdio only. `ONYXWEB_SERVER_MAX_PAGES` (default 50) sets how many pages it keeps.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"""onyxweb-server: serve onyxweb's browser to agents over MCP and to programs over HTTP.
|
|
2
|
+
|
|
3
|
+
``onyxweb_server.core`` holds the policy every front-end shares, ``onyxweb_server.egress`` the proxy
|
|
4
|
+
that keeps the browser off private addresses, and ``onyxweb_server.mcp`` and ``onyxweb_server.http``
|
|
5
|
+
the front-ends. Import them by full module path.
|
|
6
|
+
"""
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"""``onyxweb-server`` — serve onyxweb's browser to agents and programs. Commands: ``mcp``, ``http``.
|
|
2
|
+
|
|
3
|
+
onyxweb-server mcp # MCP over stdio, for Claude Code and other agents
|
|
4
|
+
onyxweb-server http --port 8000 # HTTP, for programs; loopback unless a token is set
|
|
5
|
+
|
|
6
|
+
Exit codes: 0 after a clean stop, 1 for a bad argument or a missing extra.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import argparse
|
|
12
|
+
import ipaddress
|
|
13
|
+
import os
|
|
14
|
+
import sys
|
|
15
|
+
from typing import NoReturn
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class _Parser(argparse.ArgumentParser):
|
|
19
|
+
"""Argument parser whose usage errors exit 1, as `onyxweb` does."""
|
|
20
|
+
|
|
21
|
+
def error(self, message: str) -> NoReturn:
|
|
22
|
+
self.print_usage(sys.stderr)
|
|
23
|
+
self.exit(1, f"{self.prog}: error: {message}\n")
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _build_parser() -> argparse.ArgumentParser:
|
|
27
|
+
p = _Parser(prog="onyxweb-server", description="Serve onyxweb's browser to agents.")
|
|
28
|
+
commands = p.add_subparsers(dest="command", required=True, metavar="command")
|
|
29
|
+
commands.add_parser(
|
|
30
|
+
"mcp",
|
|
31
|
+
help="serve MCP over stdio",
|
|
32
|
+
description=(
|
|
33
|
+
"Serve onyxweb to an agent over MCP (stdio): fetch a page, then look, find and "
|
|
34
|
+
"read it in pieces. Register it with: claude mcp add onyxweb -- onyxweb-server mcp"
|
|
35
|
+
),
|
|
36
|
+
epilog="ONYXWEB_SERVER_MAX_PAGES (default 50) sets how many fetched pages it keeps.",
|
|
37
|
+
)
|
|
38
|
+
http = commands.add_parser(
|
|
39
|
+
"http",
|
|
40
|
+
help="serve HTTP",
|
|
41
|
+
description=(
|
|
42
|
+
"Serve onyxweb over HTTP: POST /fetch, /screenshot, /fetch_all and /batch, "
|
|
43
|
+
"and GET /health for a status."
|
|
44
|
+
),
|
|
45
|
+
epilog=(
|
|
46
|
+
"Set ONYXWEB_SERVER_TOKEN to require 'Authorization: Bearer <token>' on every route "
|
|
47
|
+
"but /health. Without a token only a loopback address is served."
|
|
48
|
+
),
|
|
49
|
+
)
|
|
50
|
+
http.add_argument("--host", default="127.0.0.1", help="address to bind (default: 127.0.0.1)")
|
|
51
|
+
http.add_argument("--port", type=int, default=8000, help="port to listen on (default: 8000)")
|
|
52
|
+
return p
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def main(argv: list[str] | None = None) -> int:
|
|
56
|
+
"""Entry point for ``onyxweb-server``; returns the process exit code."""
|
|
57
|
+
parser = _build_parser()
|
|
58
|
+
args = parser.parse_args(argv)
|
|
59
|
+
if args.command == "mcp":
|
|
60
|
+
try:
|
|
61
|
+
from onyxweb_server.mcp import build_server
|
|
62
|
+
except ImportError as ie: # the extra isn't installed; the message names it
|
|
63
|
+
sys.stderr.write(f"onyxweb-server: {ie}\n")
|
|
64
|
+
return 1
|
|
65
|
+
# Nothing but the protocol may reach stdout until the client leaves.
|
|
66
|
+
build_server().run()
|
|
67
|
+
else:
|
|
68
|
+
try:
|
|
69
|
+
import uvicorn
|
|
70
|
+
|
|
71
|
+
from onyxweb_server.http import TOKEN_VAR, build_app
|
|
72
|
+
except ImportError as ie: # the extra isn't installed; the message names it
|
|
73
|
+
sys.stderr.write(f"onyxweb-server: {ie}\n")
|
|
74
|
+
return 1
|
|
75
|
+
try:
|
|
76
|
+
loopback = ipaddress.ip_address(args.host).is_loopback
|
|
77
|
+
except ValueError: # a name: only `localhost` is known to be local
|
|
78
|
+
loopback = args.host == "localhost"
|
|
79
|
+
if not loopback and not os.environ.get(TOKEN_VAR):
|
|
80
|
+
parser.error(
|
|
81
|
+
f"--host {args.host} is not a loopback address, so a token is required; "
|
|
82
|
+
f"set {TOKEN_VAR}, or bind 127.0.0.1 behind a reverse proxy."
|
|
83
|
+
)
|
|
84
|
+
uvicorn.run(build_app(), host=args.host, port=args.port)
|
|
85
|
+
return 0
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
if __name__ == "__main__":
|
|
89
|
+
sys.exit(main())
|