scorpiox-bot-plugin-websearch

scorpiox-bot-plugin-websearch

main1 branch · 0 tags
VS Code
HTTPS
ForkDelete
Recent Commits
README

plugin_websearch — SCORPIOX BOT multi-provider web search connector

A clean-room, zero-dependency pure C99 plugin_<name> for SCORPIOX BOT that gives

an agent one web_search tool across six backends, and gives you a page to pick the

backend, store keys and try a real search.

make               # -> ./plugin_websearch
make test          # the offline suite (no network, no credentials)
make e2e           # Playwright at 1440/1024/390, dark + light
make e2e --shots /tmp/shots   # ...without overwriting the committed docs/*.png

Every src/*.h, vendor/*.h and vendor/bearssl/*.h is a rebuild prerequisite: a

one-line edit to a header (a version bump, a provider id, a buffer size) forces a

rebuild, because make reporting "Nothing to be done" while the previous binary

stays in place is a success message about a stale artifact.

Slug / binary websearch / plugin_websearch (--meta name websearch, desc Web search MCP)
Kind mcp: true, daemon: false, menus: false, category network
verified mock — see Verification tier
Dist targets linux-x86_64, linux-x86_64-musl, linux-arm64-musl, macos-arm64, macos-x86_64, windows-x86_64
Runtime deps none — no libcurl, no OpenSSL, no system CA file, no curl binary
Source https://plugingit.scorpiox.net/scorpiox-bot-plugin-websearch.git
Artifacts https://dist.scorpiox.net/bot-plugins/websearch/

Backends

id Auth Endpoint Notes
duckduckgo none POST {base}/html/ the HTML result page is parsed; a GET gets DuckDuckGo's bot challenge, so the request is a form POST. Measured: DuckDuckGo rate-limits an IP after a handful of queries (HTTP 202 + anomaly-modal) and then keeps answering 202 for a while — the plugin reports that as a challenge with the alternatives named, never as "no results"
searxng none GET {base}/search?format=json your own instance; needs search.formats: [json] in its settings.yml
brave X-Subscription-Token GET {base}/res/v1/web/search supports country, language, freshness
tavily Authorization: Bearer POST {base}/search optional include_answer / search_depth: advanced
exa x-api-key POST {base}/search contents.highlights[0] becomes the snippet
perplexity Authorization: Bearer POST {base}/search the Search API (ranked sources), not chat completions

Every backend is normalised to the same result object, so the agent never learns a

vendor's field names:

{"title":"…","url":"https://…","snippet":"…","published":"2026-11-14","site":"example.com"}

provider is an argument on the tool and a saved default. With no key configured

the tool says exactly which variable to set, instead of returning "no results".

On the keyless default: DuckDuckGo is the only backend that needs nothing, and it

is also the only one that will rate-limit you — after a few queries from one IP it

serves its bot-detection page (202) and keeps doing so for a while. That is measured

behaviour on this fleet, not a maybe: tests/run.sh covers it by asserting the

challenge page becomes an error naming the alternatives, and the fix for a node that

searches a lot is a keyed provider or your own SearXNG instance.

MCP tools

Served over stdio JSON-RPC 2.0 from plugin_websearch --mcp, which is what the single

sx-connector-mcp router drives — so registering it costs no clang MCP slot and

no prompt tokens until a tool is actually called.

web_search

argument type
query string, required the search query
provider enum duckduckgo \searxng \brave \tavily \exa \perplexity — omit for the configured default
count integer 1–20 how many results (default 5)
country string two-letter code, Brave only (NZ, US, ALL)
language string ISO 639-1 (en, de, fr)
freshness enum day \week \month \year, Brave only

Returns structuredContent with ok, query, provider, count, took_ms,

results[], and answer/citations when a backend produces them. A failure is an

isError result whose text carries the provider's own message and its HTTP status.

web_search_providers

No arguments. Reports every backend with needs_key, needs_base, has_key and

ready, plus which one is the default. Never returns a key — only whether one is

present.

printf '%s\n' \
 '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"web_search","arguments":{"query":"rust async","provider":"brave","count":3}}}' \
 | ./plugin_websearch --mcp

Configuration

Resolution order, lowest priority first — the environment always wins:

  1. compiled defaults (https://api.search.brave.com, …)
  2. <connector dir>/config.json, written by the page, mode 0600
  3. the environment

The connector directory is deliberately outside the plugin's own directory, so a

plugin update can never take your keys with it:

$SWEBSEARCH_CONFIG_DIR                                        (tests)
/workspace/.scorpiox/connectors/plugin_websearch              (BotCloud: survives a rebuild)
~/.scorpiox/connectors/plugin_websearch                       (POSIX)
%LOCALAPPDATA%\scorpiox\connectors\plugin_websearch           (Windows)
env
BRAVE_API_KEY / TAVILY_API_KEY / EXA_API_KEY / PERPLEXITY_API_KEY the keys (also accepted: WEBSEARCH_<PROVIDER>_KEY)
WEBSEARCH_PROVIDER default backend id
WEBSEARCH_COUNT default result count (1–20)
WEBSEARCH_REGION DuckDuckGo kl (e.g. nz-en)
WEBSEARCH_SAFE strict \moderate \off
WEBSEARCH_LANGUAGE ISO 639-1
WEBSEARCH_SEARXNG_BASE (or SEARXNG_URL) your instance
WEBSEARCH_SEARXNG_CATEGORIES e.g. general, news
WEBSEARCH_{DDG,BRAVE,TAVILY,EXA,PPLX}_BASE override one provider's base URL
WEBSEARCH_TAVILY_ANSWER / WEBSEARCH_TAVILY_ADVANCED 1 / 0
WEBSEARCH_MOCK_BASE point every provider at one loopback mock (tests only)

The page

GET /plugin_websearch — bot theme tokens, dark and light, ?embed=1, &theme=, the

sx-theme postMessage handoff, zero <script src=>, fluid down to 390 px.

  • Backends — six cards with a READY / KEY SET / NO KEY pill; click one to make

it the default.

  • Search — the exact request the tool makes (same JSON API), so what you see is what

the agent gets: results, the Tavily answer block, the meta line, and the provider's

own error text (with its HTTP status) when something is wrong.

  • Keys & defaults — write-only key fields (leave blank to keep), a base URL per

self-hosted backend, safe search, region, language, categories.

Every action is behind node authentication (X-Bot-Password, Authorization: Bearer,

or ?pwd=, which is the form the bot's iframe uses). --meta and --mcp return before

the gate so discovery and the router keep working.

Layout

src/plugin_websearch.c   main(), --meta, --mcp loop, CGI dispatch, auth, tool schemas, HTML
src/ws_providers.c       the six backends, request builders and result normalisation
src/ws_config.c          connector dir, config.json at 0600, env resolution
src/ws_http.c            the one outbound call, over the vendored TLS transport
src/ws_buf.c             growable buffer, JSON escaping, HTML entity/tag handling, URL codec
src/ui.html              the page (compiled into src/ui_html.h by tools/gen_ui.py)
src/sx_http_tls.{c,h}    HTTP/1.1 + TLS client (SCORPIOX BOT Connector SDK)
src/ca_roots_pem.h       the compiled-in trust anchors
vendor/yyjson.c          JSON (MIT, ibireme)
vendor/bearssl/          TLS 1.2+ (MIT, Thomas Pornin)
tests/mockapi.py         a loopback mock of all six providers, recording every req