125 lines
5.3 KiB
Markdown
125 lines
5.3 KiB
Markdown
# Local Web Search Stack (LWSS)
|
|
|
|
Self-hosted, private web search + page retrieval for local LLMs — a functional
|
|
replacement for Tavily/Serper/Firecrawl, exposed as an **MCP server**. No SaaS
|
|
in the request path, no per-call fees, no LLM anywhere in the stack (the calling
|
|
model does its own ranking/filtering; extraction is purely mechanical).
|
|
|
|
See [PRD.md](PRD.md) for full requirements and architecture.
|
|
|
|
## Install (VPS / LXC / any Linux or macOS host)
|
|
|
|
One command — installs Docker if missing, clones the repo, generates a strong
|
|
API key + SearXNG secret, and brings the stack up:
|
|
|
|
```bash
|
|
curl -fsSL https://git.neilbantoc.dev/pub/local-web-search/raw/branch/main/install.sh | bash
|
|
```
|
|
|
|
When it finishes it prints your MCP endpoint, the generated API key, and the
|
|
exact `claude mcp add` command to run on your client machine. Re-running the
|
|
installer updates the checkout and restarts the stack, preserving your `.env`
|
|
(and API key). Useful overrides: `LWSS_DIR`, `LWSS_PORT`, `LWSS_BIND`,
|
|
`LWSS_BRANCH` (see the top of [`install.sh`](install.sh)).
|
|
|
|
## Quick start (manual / development)
|
|
|
|
```bash
|
|
cp .env.example .env
|
|
# set LWSS_API_KEY to a strong value (or `openssl rand -hex 32`); empty disables auth
|
|
docker compose up --build
|
|
```
|
|
|
|
The orchestrator is the only exposed service, on port 8000.
|
|
|
|
### Authentication
|
|
|
|
If `LWSS_API_KEY` is set (the installer always sets it), every request to the
|
|
MCP and REST endpoints must carry `Authorization: Bearer <key>`. `/health` is
|
|
always exempt so healthchecks/monitors work. An empty key disables auth —
|
|
only do that on trusted/LAN networks.
|
|
|
|
### MCP (primary interface)
|
|
|
|
Streamable HTTP endpoint: `http://<host>:8000/mcp`
|
|
|
|
Claude Code:
|
|
|
|
```bash
|
|
claude mcp add --transport http local-web-search http://<host>:8000/mcp \
|
|
--header "Authorization: Bearer <your-api-key>"
|
|
```
|
|
|
|
Tools:
|
|
|
|
| Tool | Args | Returns |
|
|
|---|---|---|
|
|
| `web_search` | `query`, `max_results=5`, `include_content=true` | ranked results: url, title, snippet (+ cleaned page text) |
|
|
| `fetch_url` | `url` | cleaned text, title, metadata for one page |
|
|
|
|
### REST (debug / non-MCP clients)
|
|
|
|
```bash
|
|
AUTH='-H "Authorization: Bearer <your-api-key>"' # omit if auth is disabled
|
|
curl -X POST localhost:8000/search -d '{"query":"..."}' -H 'content-type: application/json' -H "Authorization: Bearer <key>"
|
|
curl -X POST localhost:8000/search/contents -d '{"query":"...","max_results":5}' -H 'content-type: application/json' -H "Authorization: Bearer <key>"
|
|
curl -X POST localhost:8000/scrape -d '{"url":"https://..."}' -H 'content-type: application/json' -H "Authorization: Bearer <key>"
|
|
curl localhost:8000/health # no auth needed
|
|
```
|
|
|
|
Every REST response includes a `trace`: per-stage timings, cache hit/miss, and
|
|
a `degraded` list naming stages that fell back or partially failed.
|
|
|
|
## Architecture
|
|
|
|
```
|
|
MCP client → orchestrator (REST+MCP) → searcher → searxng (local)
|
|
→ renderer (Playwright)
|
|
→ extractor (Trafilatura + readability)
|
|
redis: search / rendered-HTML / extracted-text caches
|
|
```
|
|
|
|
- **searcher** — queries the SearXNG pool (file-based list in
|
|
`config/instances.yml`, failover mode; add instances there for rotation
|
|
later), normalizes + dedups results.
|
|
- **renderer** — always renders via headless Chromium; single browser, pooled
|
|
contexts, concurrency cap + queue; per-domain rate limiting (Redis token
|
|
window); render retry with DNS-failure fast-fail; Redis HTML cache.
|
|
- **extractor** — mechanical extraction only: Trafilatura (precision → recall)
|
|
then readability-lxml fallback; flags thin content.
|
|
- **orchestrator** — sequencing, per-URL parallelism, partial-result
|
|
degradation, scrape-result cache, aggregated `/health`.
|
|
|
|
## Configuration
|
|
|
|
All knobs are env vars (see `.env.example`): cache TTLs, renderer concurrency
|
|
and timeouts, per-domain rate limit, stage timeouts, SearXNG secret. The
|
|
SearXNG instance pool lives in `config/instances.yml` (hand-editable; reloaded
|
|
on change without restart).
|
|
|
|
## Security notes
|
|
|
|
When exposed beyond a trusted LAN, the API key is the only thing gating your
|
|
renderer — anyone with the key (or with the port open and auth disabled) can
|
|
drive it to fetch arbitrary URLs. Guidance:
|
|
|
|
- **Always keep `LWSS_API_KEY` set** on any internet-reachable host.
|
|
- **Prefer a private tunnel.** Set `ORCHESTRATOR_BIND=127.0.0.1` and reach the
|
|
box over Tailscale / WireGuard / Cloudflare Tunnel rather than opening the
|
|
port. That keeps the endpoint off the public internet entirely.
|
|
- **Renderer SSRF surface:** `fetch_url` / `/scrape` will fetch any URL given to
|
|
it, including internal addresses reachable from the container. Don't run this
|
|
where it can reach sensitive internal services you wouldn't want proxied.
|
|
- Rotate the key by editing `.env` and `docker compose up -d orchestrator`.
|
|
|
|
## Development
|
|
|
|
Python services run directly with uvicorn (`--app-dir services/<name>`), the
|
|
renderer with `node services/renderer/src/server.js`. Everything degrades
|
|
gracefully without Redis (caching disabled). Each service is curl-able in
|
|
isolation on its own port: searcher 8001, renderer 8002, extractor 8003.
|
|
|
|
## License
|
|
|
|
[AGPL-3.0](LICENSE). If you run a modified version as a network service, the
|
|
license requires you to make your modified source available to its users.
|