nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Feature] web_search: support SearXNG and other engines besides the Brave API

Open akramcodez opened this issue 3 weeks ago • 1 comments

Description

Let web_search use more than the Brave API: a keyless option and a self-hosted option (SearXNG), selectable in config.

Use Case

web_search only works after the user creates a Brave Search API key (nanocoderTools.webSearch.apiKey), and the formatter hard codes "Engine: Brave Search API". Nanocoder is local-first: many users run fully local or on a restricted network and will not sign up for a third party key, and some already run a SearXNG instance. Without a key the tool just throws "Brave Search API key not configured", so the model loses web access completely.

Proposed Solution

Add nanocoderTools.webSearch.engine with values brave (default), searxng (needs baseUrl, uses its JSON API) and optionally a keyless HTML endpoint. Keep the same result format so the formatter and token estimate work unchanged, show the real engine name in the preview, and make /doctor report which engine is configured. Apply the existing SSRF guard rules to a user supplied baseUrl only where it should not reach private addresses (a local SearXNG is a legitimate private target, so make that an explicit setting).

Alternatives Considered

Using the fetch_url tool on a search results page (fragile, often blocked) or configuring a search MCP server (works, but needs a separate setup per user).

Additional Context

  • [x] I have searched existing issues to ensure this is not a duplicate
  • [x] This feature aligns with the project's goals (local-first AI assistance)

Implementation Notes (optional)

executeWebSearch in source/tools/web-search.tsx is a single function; an engine map keyed by name with a shared result shape would keep it small.

akramcodez avatar Nov 10 '26 08:11 akramcodez

I'd like to pick this up, if nobody else has it. Here's the plan:

  • Add nanocoderTools.webSearch.engine (brave by default, or searxng) and baseUrl for SearXNG. executeWebSearch keeps one result shape and looks up the engine in a small map, so the markdown output and the formatter stay the same. The SearXNG request is GET {baseUrl}/search?q=...&format=json, with results capped at max_results.
  • The preview shows the configured engine, not the hard-coded "Brave Search API".
  • tool-manager.ts registers web_search when the selected engine is usable: a key for Brave, a baseUrl for SearXNG. Today it only checks for the Brave key.
  • /doctor and the settings panel show which engine is configured.

Two things I'd like your view on first:

  1. Private addresses. baseUrl comes from the user's config, not from the model, and a SearXNG on localhost or the LAN is the main use. My plan is to run assertPublicHttpUrl from fetch-url-guard.ts on it unless allowPrivateNetwork: true is set next to it. Does that match what you meant by an explicit setting, or would you rather trust a configured baseUrl as it is?
  2. The keyless HTML endpoint. Scraping something like DuckDuckGo's HTML page breaks whenever their markup changes. I'd leave it out of this PR and do Brave and SearXNG only, unless you'd like it included.

#2025 also touches web_search (it clamps max_results). I'll rebase on it if it lands first.

Purv-Kabaria avatar Nov 12 '26 09:11 Purv-Kabaria