openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

feat(mcp): add SearXNG search tool

Open EvanWangZ opened this issue 6 months ago • 3 comments

Summary

  • Adds a config-gated searxng_search tool for private, self-hosted web search through SearXNG.
  • Exposes the search flow through the agent tool registry, JSON-RPC controller registry, and MCP tools/list / tools/call surfaces.
  • Adds SearXNG config/env support with safe defaults, request timeout handling, category validation, and normalized result output.
  • Updates docs, capability catalog metadata, feature IDs, and focused Rust tests for config, registry, RPC/MCP validation, and integration behavior.

Problem

  • OpenHuman has MCP and agent tooling for local/productivity tasks, but no native private web search option backed by a self-hosted engine.
  • Issue #1842 requests SearXNG as a native MCP tool so users can avoid hosted search providers while still giving agents web-search capability.

Solution

  • Added openhuman::integrations::searxng with a small HTTP client wrapper that calls SearXNG JSON search, enforces max result bounds, maps web to SearXNG general, skips invalid result rows, and logs grep-friendly checkpoints.
  • Added [searxng] config plus OPENHUMAN_SEARXNG_* / SEARXNG_* env overrides. The feature is disabled by default.
  • Registered searxng_search in optional agent tools, openhuman.tools_searxng_search in the controller registry, and MCP searxng_search as a config-gated tool.
  • Updated MCP docs, .env.example, the runtime capability catalog, feature IDs, and the coverage matrix.

Submission Checklist

If a section does not apply to this change, mark the item as N/A with a one-line reason. Do not delete items.

  • [x] Tests added or updated (happy path + at least one failure / edge case) per Testing Strategy
  • [x] Diff coverage ≥ 80% — focused Rust tests cover the changed core/MCP/config paths; full merged pnpm test:coverage was not run locally, and CI diff-cover remains authoritative.
  • [x] Coverage matrix updated — added 11.1.6 SearXNG MCP search to docs/TEST-COVERAGE-MATRIX.md.
  • [x] All affected feature IDs from the matrix are listed in the PR description under ## Related.
  • [x] No new external network dependencies introduced (mock backend used per Testing Strategy) — no mandatory dependency is added; the optional SearXNG HTTP endpoint is user-configured, disabled by default, and tested with a local mock.
  • [x] Manual smoke checklist updated if this touches release-cut surfaces (docs/RELEASE-MANUAL-SMOKE.md) — N/A: no release-cut manual smoke surface changed.
  • [x] Linked issue referenced without auto-closing; criteria 5-7 remain follow-up work.

Impact

  • Runtime/platform impact: Rust core, CLI/JSON-RPC controller registry, agent tool registry, and MCP server only. No React UI or Tauri shell behavior changed.
  • Security/privacy: SearXNG is disabled by default and only calls the configured base URL when explicitly enabled.
  • Compatibility: Existing MCP tools remain listed as before; searxng_search is omitted from tools/list unless enabled.
  • Performance: Search calls use a bounded timeout and bounded result count.

Related

  • Relates to #1842
  • Feature ID: 11.1.6
  • Follow-up PR(s)/TODOs: Agent routing, priority, and fallback acceptance criteria 5-7 remain follow-up work.

AI Authored PR Metadata (required for Codex/Linear PRs)

Keep this section for AI-authored PRs. For human-only PRs, mark each field N/A.

Linear Issue

  • Key: N/A — GitHub issue #1842
  • URL: N/A — https://github.com/tinyhumansai/openhuman/issues/1842

Commit & Branch

  • Branch: codex/OH-1842-searxng-mcp-tool
  • Commit SHA: 9e5d367cb39923131f436fb2735465d34ab1200f

Validation Run

  • [x] pnpm --filter openhuman-app format:check
  • [x] pnpm typecheck
  • [x] Focused tests: cargo test --manifest-path Cargo.toml searxng -- --nocapture; cargo test --manifest-path Cargo.toml mcp_server -- --nocapture; cargo test --manifest-path Cargo.toml all_tools_registers_optional_search_lsp_and_tool_stats_when_enabled -- --nocapture; cargo test --manifest-path Cargo.toml about_app::catalog -- --nocapture; pnpm debug rust searxng
  • [x] Rust fmt/check (if changed): cargo fmt --manifest-path Cargo.toml --all --check; cargo check --manifest-path Cargo.toml; cargo build --manifest-path Cargo.toml --bin openhuman-core
  • [x] Tauri fmt/check (if changed): pnpm --filter openhuman-app rust:check via pre-push hook; Tauri shell unchanged.

Validation Blocked

  • command: N/A
  • error: N/A
  • impact: N/A

Behavior Changes

  • Intended behavior change: OpenHuman can expose searxng_search as a config-gated agent/RPC/MCP tool backed by a private SearXNG instance.
  • User-visible effect: Users who enable [searxng] can let agents search their configured self-hosted SearXNG endpoint from MCP-compatible clients.

Parity Contract

  • Legacy behavior preserved: Existing MCP/base tools and controller dispatch behavior remain available; SearXNG is added only when enabled.
  • Guard/fallback/dispatch parity checks: MCP tools/list omits config-gated tools on disabled or failed config load; tools/call rejects unknown args/categories and validates result limits before RPC dispatch.

Duplicate / Superseded PR Handling

  • Duplicate PR(s): None found via gh pr list --repo tinyhumansai/openhuman --state open --search "searxng OR SearXNG OR 1842".
  • Canonical PR: This PR.
  • Resolution (closed/superseded/updated): N/A

Summary by CodeRabbit

  • New Features

    • Added SearXNG self‑hosted search integration with enable/disable env vars, configurable base URL, per‑query max results, default language, and request timeout. New MCP tool "searxng_search" appears when enabled.
  • Documentation

    • MCP docs and capability catalog updated with SearXNG usage, configuration examples, and test‑coverage matrix entry.
  • Tests

    • New unit and integration tests for config/env parsing, tool/schema parameters, and result normalization.
  • Chores

    • Added feature ID 11.1.6.

Review Change Stack

EvanWangZ avatar May 17 '26 06:05 EvanWangZ

[!NOTE]

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • [ ] ▶️ Resume reviews
  • [ ] 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a configurable SearXNG MCP tool: new config/schema with env overrides, a reqwest-based SearXNG client that normalizes results, MCP tool-specs and RPC handlers, orchestrator registration, tests, and documentation updates. The tool is listed and registered only when enabled.

Changes

SearXNG Self-Hosted Web Search Tool Integration

Layer / File(s) Summary
Configuration schema and environment loading
src/openhuman/config/schema/tools.rs, src/openhuman/config/schema/types.rs, src/openhuman/config/schema/mod.rs, src/openhuman/config/mod.rs, src/openhuman/config/schema/load.rs, src/openhuman/config/schema/load_tests.rs, .env.example
Adds SearxngConfig and root Config.searxng; env overlays for OPENHUMAN_SEARXNG_* (with aliases), validation/clamping, defaults, and unit tests for parsing and TOML alias timeout_seconds.
SearXNG HTTP client and result normalization
src/openhuman/integrations/searxng.rs, src/openhuman/integrations/mod.rs
Implements SearxngSearchTool (reqwest client, timeouts), raw JSON deserialization, category normalization, result normalization to {title,url,snippet,source}, argument parsing, helpers, and unit + async integration tests.
MCP tool registration and RPC dispatch
src/openhuman/mcp_server/tools.rs, src/openhuman/mcp_server/protocol.rs
Adds searxng_search tool spec and JSON-schema, tool_specs() now includes searxng, list_tools_result() is config-gated, build_rpc_params parses/validates params including optional_max_results, and tests validate listing and param behavior.
Orchestrator tool registration and execution
src/openhuman/tools/ops.rs, src/openhuman/tools/schemas.rs, src/openhuman/tools/ops_tests.rs
Registers searxng_search in runtime when enabled, implements tools_searxng_search controller and handle_searxng_search handler with input validation and invocation of SearxngSearchTool, adds optional_string_array helper and tests.
User-facing documentation and capability catalog
src/openhuman/about_app/catalog.rs, src/openhuman/about_app/catalog_tests.rs, gitbooks/developing/mcp-server.md, docs/TEST-COVERAGE-MATRIX.md, scripts/feature-ids.json, .env.example
Adds intelligence.searxng_search capability and privacy mapping, updates docs with config and env examples, updates test-coverage matrix (adds 11.1.6), and appends feature id 11.1.6.

Sequence Diagram

sequenceDiagram
  participant Client as Agent/MCP Client
  participant Protocol as tools_schemas / MCP call
  participant Tool as SearxngSearchTool
  participant Searxng as SearXNG Instance

  Client->>Protocol: tools_searxng_search {query,categories,language,max_results}
  Protocol->>Tool: parse args & call search()
  Tool->>Searxng: GET /search?format=json&q=...&categories=...&language=...
  Searxng-->>Tool: raw JSON response
  Tool->>Tool: parse & normalize results -> {title,url,snippet,source}[]
  Tool-->>Protocol: SearxngSearchResponse {query, results}
  Protocol-->>Client: JSON-RPC success

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • senamakel

Poem

🐰 I hopped to a SearXNG door,

Queries trimmed and quietly stored,
Results normalized, snippets neat,
Self-hosted answers, privacy sweet,
The rabbit dances — search complete.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 57.50% 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(mcp): add SearXNG search tool' accurately summarizes the main change—adding a SearXNG-backed search tool to the MCP server. It is concise, specific, and clearly indicates the primary feature addition.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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 and usage tips.

coderabbitai[bot] avatar May 17 '26 06:05 coderabbitai[bot]

Addressed @graycyrus review in 9e5d367c:

  • PR body now uses Relates to #1842 and calls out agent routing / priority / fallback criteria 5-7 as follow-up work instead of closing the issue.
  • RPC SearXNG calls now reuse a shared reqwest::Client; timeout stays per configured request.
  • SearXNG max-results cap is exported from the integration and reused by MCP/RPC surfaces.
  • MCP tools/list protocol test is strict again for the base tool set, with only config-gated searxng_search excluded from the base comparison.

Validated locally with:

  • cargo fmt --manifest-path Cargo.toml --all --check
  • cargo test --manifest-path Cargo.toml searxng --lib
  • cargo test --manifest-path Cargo.toml mcp_server --lib

Pre-push checks also passed.

EvanWangZ avatar May 18 '26 04:05 EvanWangZ

@graycyrus I addressed the requested changes and CI is now green. Could you please re-review when you have a chance?

EvanWangZ avatar May 18 '26 11:05 EvanWangZ