Skip to content

Add SearXNG web search provider - #923

Open
mattezell wants to merge 2 commits into
mattermost:masterfrom
mattezell:feat/websearch-searxng-provider
Open

Add SearXNG web search provider#923
mattezell wants to merge 2 commits into
mattermost:masterfrom
mattezell:feat/websearch-searxng-provider

Conversation

@mattezell

@mattezell mattezell commented Jul 24, 2026

Copy link
Copy Markdown

Summary

Adds SearXNG as a third built-in web search provider, alongside Google Custom Search and Brave. SearXNG is the de-facto self-hosted metasearch engine; this gives the plugin's self-hosting audience agent web search with no API key, no external dependency, and no per-query cost.

  • websearch/searxng.go -- provider following the Google/Brave pattern: GET {baseURL}/search?q=...&format=json, results mapped to title/URL/snippet, trimmed and truncated to the configured limit. A 403 response carries a targeted hint that SearXNG only serves json when listed under search.formats in its settings (the most common misconfiguration).
  • config/config.go -- WebSearchSearXNGConfig (baseURL, resultLimit) on WebSearchConfig.
  • mmtools/web_search.go -- searxng case in the provider switch, the SourceTool credential check (base URL required), and the result-limit resolution.
  • System console -- provider option "SearXNG (self-hosted)" with Base URL and result limit; the Base URL help text points operators at AllowedUntrustedInternalConnections for instances on private/reserved addresses, since that guard otherwise blocks them silently.
  • webapp/src/i18n/en.json regenerated via make i18n-extract.

Built and verified against a live self-hosted SearXNG instance feeding a llama.cpp-backed agent.

QA steps

  1. System Console -> Agents -> Web Search: enable, provider "SearXNG (self-hosted)", Base URL of an instance with json in search.formats.
  2. Ask an agent something requiring current information.
  3. The agent's built-in web search returns SearXNG results; a wrong/format-restricted instance produces the hinted 403 error in logs.

Tests: websearch/searxng_test.go covers result mapping/trimming, limit truncation, trailing-slash tolerance, the 403 hint, non-200 errors, empty results, and the nil-client guard. go test ./websearch/ ./mmtools/ ./config/ all pass; eslint clean on touched webapp files.

Ticket Link

Fixes #922

Screenshots

N/A (new provider section follows the exact layout of the existing Google/Brave sections)

🤖 Generated with Claude Code

https://claude.ai/code/session_016e12GP7EHU2KeCGGYcfvBo

Summary by CodeRabbit

  • New Features
    • Added support for self-hosted SearXNG as a web search provider.
    • Added configuration fields for the SearXNG base URL and result limit.
    • Added SearXNG provider selection and setup options in the web search settings.
    • Search results now support configurable limits and clear error messages when JSON search responses are unavailable.
  • Bug Fixes
    • Improved handling of SearXNG URLs, empty responses, and non-successful requests.

Adds a third built-in web search provider for self-hosted SearXNG
metasearch instances: no API key, no external dependency, which fits the
self-hosted deployments that run this plugin against local
OpenAI-compatible backends.

Provider follows the Google/Brave pattern (GET /search?q=&format=json,
results mapped to title/url/snippet). A 403 gets a targeted hint that
SearXNG only serves json when it is listed under search.formats -- the
most common misconfiguration. System console gains the provider option
with Base URL and result limit; the base-URL help text points operators
at AllowedUntrustedInternalConnections for instances on private
addresses, since that guard silently blocks reserved ranges.

Tests cover result mapping and trimming, limit truncation, trailing
slash tolerance, the 403 hint, non-200 errors, empty results, and the
nil-client guard. websearch, mmtools, and config suites pass; en.json
regenerated via make i18n-extract.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016e12GP7EHU2KeCGGYcfvBo
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@mattezell, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 24 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 690735f5-db2b-4277-8000-75f12230da31

📥 Commits

Reviewing files that changed from the base of the PR and between 3a8ecfd and 96112f6.

📒 Files selected for processing (5)
  • mmtools/web_search.go
  • webapp/src/components/system_console/web_search/web_search_panel.tsx
  • webapp/src/i18n/en.json
  • websearch/searxng.go
  • websearch/searxng_test.go
📝 Walkthrough

Walkthrough

Adds self-hosted SearXNG web search support, including backend provider execution, configuration and tool wiring, result limits, system-console settings, translations, and automated provider tests.

Changes

SearXNG provider integration

Layer / File(s) Summary
Provider implementation and validation
websearch/searxng.go, websearch/searxng_test.go
Implements SearXNG JSON searches with response mapping, trimming, limits, telemetry, HTTP error handling, and test coverage.
Backend configuration and tool wiring
config/config.go, mmtools/web_search.go
Adds SearXNG configuration and connects provider initialization, availability checks, and configured result limits.
System-console settings
webapp/src/components/system_console/config.tsx, webapp/src/components/system_console/web_search/web_search_panel.tsx, webapp/src/i18n/en.json
Adds SearXNG defaults, typed settings, provider selection, Base URL and result-limit fields, and English translations.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant SearchTool
  participant SearXNGProvider
  participant SearXNGServer
  SearchTool->>SearXNGProvider: Submit query and result limit
  SearXNGProvider->>SearXNGServer: GET /search?q=query&format=json
  SearXNGServer-->>SearXNGProvider: Return JSON results or HTTP error
  SearXNGProvider-->>SearchTool: Return trimmed, limited SearchResponse
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes implement the requested self-hosted SearXNG provider, wiring, config, console support, and operator guidance from issue #922.
Out of Scope Changes check ✅ Passed The changes stay focused on SearXNG provider support and related configuration, UI, and tests without obvious unrelated additions.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding SearXNG as a web search provider.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@mmtools/web_search.go`:
- Around line 169-178: In Tool(), trim webCfg.SearXNG.BaseURL once before the
empty-value validation, validate the trimmed value, and pass that same value to
NewSearXNGProvider. Update SourceTool() to use the trimmed BaseURL for its empty
check as well, preserving the existing misconfiguration behavior.

In `@webapp/src/components/system_console/web_search/web_search_panel.tsx`:
- Line 91: Update the SearXNG option in the provider configuration to render its
“SearXNG (self-hosted)” label through react-intl’s FormattedMessage, matching
the surrounding translated labels, then rerun i18n-extract to add the message to
the catalog.

In `@websearch/searxng_test.go`:
- Around line 31-129: Convert TestSearXNGProvider into a table-driven test with
one case entry for each of the seven scenarios currently defined by t.Run.
Centralize provider creation, Search invocation, and common error/response
assertions where possible, while allowing each case to supply its own HTTP
handler and specialized expectations; preserve all existing request validation
and outcomes.

In `@websearch/searxng.go`:
- Around line 40-90: Update SearXNGProvider.Search so every early-return failure
records the error on the span, including request creation, missing HTTP client,
403, other non-OK responses, and response decoding. Add safe telemetry
attributes identifying the failure type and HTTP status code where available,
without including the search query; preserve the existing client.Do error
recording and avoid exposing sensitive data.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 6107e419-5376-486d-8e7d-49351e60a066

📥 Commits

Reviewing files that changed from the base of the PR and between 7e9a63e and 3a8ecfd.

📒 Files selected for processing (7)
  • config/config.go
  • mmtools/web_search.go
  • webapp/src/components/system_console/config.tsx
  • webapp/src/components/system_console/web_search/web_search_panel.tsx
  • webapp/src/i18n/en.json
  • websearch/searxng.go
  • websearch/searxng_test.go

Comment thread mmtools/web_search.go
Comment thread webapp/src/components/system_console/web_search/web_search_panel.tsx Outdated
Comment thread websearch/searxng_test.go
Comment thread websearch/searxng.go Outdated
…, i18n label

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016e12GP7EHU2KeCGGYcfvBo
@mattezell

Copy link
Copy Markdown
Author

All four review findings addressed:

  • Base URL trimming (mmtools/web_search.go): trimmed once in Tool() before validation and construction; SourceTool() uses the same trimmed-empty check.
  • Table-driven test (websearch/searxng_test.go): the seven cases are now a case table with shared server setup and per-case handlers, per the Go test guidelines.
  • Span coverage (websearch/searxng.go): every early-return path now records the error with a fail_stage attribute (create_request/nil_http_client/http_request/http_status/decode_response) plus http.response.status_code where available -- the query is never attached.
  • i18n (web_search_panel.tsx): the provider label is a FormattedMessage; make i18n-extract regenerated en.json.

go test ./websearch/ ./mmtools/ green; eslint clean on touched files.

@mattermost-build

Copy link
Copy Markdown
Collaborator

This PR has been automatically labelled "stale" because it hasn't had recent activity.
A core team member will check in on the status of the PR to help with questions.
Thank you for your contribution!

@mattezell

Copy link
Copy Markdown
Author

Bumping to clear the stale label — all four review findings were addressed back in July and coderabbit approved the follow-up. Ready for a core team review whenever someone has cycles; happy to rebase if needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: SearXNG web search provider (self-hosted, no API key)

2 participants