onyxweb-server 0.1.0__py3-none-any.whl
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/__init__.py +6 -0
- onyxweb_server/__main__.py +89 -0
- onyxweb_server/core.py +834 -0
- onyxweb_server/egress.py +310 -0
- onyxweb_server/http.py +322 -0
- onyxweb_server/mcp.py +826 -0
- onyxweb_server/py.typed +0 -0
- onyxweb_server-0.1.0.dist-info/METADATA +122 -0
- onyxweb_server-0.1.0.dist-info/RECORD +11 -0
- onyxweb_server-0.1.0.dist-info/WHEEL +4 -0
- onyxweb_server-0.1.0.dist-info/entry_points.txt +2 -0
|
@@ -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())
|