local-web-search-service

local-web-search-service

Self-hosted web search and page fetch service using SearXNG metasearch and Scrapling browser rendering, exposing MCP tools for direct agent use.

Category
访问服务器

README

local-web-search-service

Self-hosted web search + page fetch for LoreWeave's glossary deep-research feature:

  • Search — backed by SearXNG (OSS metasearch — no API key, no account, no per-query cost).
  • Fetch — backed by a Scrapling sidecar (browser rendering + anti-bot), with an in-process HTTP fallback.

Capabilities are exposed over two surfaces, both calling the same orchestrators:

Capability HTTP MCP tool
Search POST /search (Tavily-compatible) web_search
Fetch one page POST /fetch fetch_page
Fetch many pages POST /fetch/bulk fetch_pages

The HTTP POST /search is the LoreWeave contract; the MCP surface is a bonus for direct agent (Cursor/Claude) use. LoreWeave never uses MCP — it calls POST /search. (A web_fetch LoreWeave consumer is not built yet — fetch is used directly via HTTP/MCP for now.)

Contracts implemented: §3/§8 (search) and §10 (fetch) of lore-weave-security/docs/04_integration/2026-06-21-web-search-service-integration.md.


Architecture

LoreWeave ──BYOK──▶ provider-registry ──POST /search──▶┐
                                                        ├─▶ web-search shim (this repo)
Cursor/agent ── MCP /mcp · HTTP /search /fetch ────────▶┘     │
                                                              ├─▶ SearXNG       (search; always)
                                                              ├─▶ trafilatura   (search advanced-extract)
                                                              └─▶ Scrapling MCP (fetch: browser/stealth)
                                                                    └ http fallback when sidecar absent
  • app/service.py — search orchestrator: clamp → SearXNG → map → (advanced) enrich → answer.
  • app/searxng_client.py — SearXNG JSON client + mapping to the §3 shape (http-only URLs, deduped).
  • app/fetch_service.py — fetch orchestrator: mode dispatch (http/browser/stealth/auto) + auto-escalation.
  • app/scrapling_client.py — MCP client to the Scrapling sidecar.
  • app/api.pyPOST /search, POST /fetch, POST /fetch/bulk, GET /health, GET /ready.
  • app/mcp_server.py — FastMCP tools: web_search, fetch_page, fetch_pages (Streamable HTTP).
  • app/main.py — combines everything into one ASGI app (HTTP routes + mounted /mcp).

Run

Docker (recommended — ships SearXNG too)

copy .env.example .env      # optional: set WEB_SEARCH_SECRET, etc.
docker compose up -d --build
  • Shim: http://localhost:15487 (/search, /health, /ready, /mcp)
  • SearXNG: internal to the compose network (publish port 8080 only for debugging).

Local (Python) — SearXNG elsewhere

pip install -r requirements.txt
$env:SEARXNG_URL = "http://localhost:8080"   # a SearXNG with JSON format enabled
uvicorn app.main:app --host 0.0.0.0 --port 15487

Try it

.\scripts\smoke.ps1                              # health + a sample /search
curl -X POST http://localhost:15487/search \
  -H "Content-Type: application/json" \
  -d '{"query":"Nezha 哪吒 deity","max_results":5,"include_answer":true}'

Response (exact keys LoreWeave parses):

{
  "query": "Nezha 哪吒 deity",
  "answer": "Nezha is a protection deity ...",
  "results": [
    { "title": "Nezha — Wikipedia", "url": "https://en.wikipedia.org/wiki/Nezha",
      "content": "Nezha is a protection deity ...", "score": 0.95 }
  ]
}

Fetch a specific page

# auto = fast HTTP first, escalate to stealth (Cloudflare/anti-bot) if blocked
curl -X POST http://localhost:15487/fetch \
  -H "Content-Type: application/json" \
  -d '{"url":"https://en.wikipedia.org/wiki/Nezha","mode":"auto","format":"markdown","max_chars":8000}'
{
  "url": "https://en.wikipedia.org/wiki/Nezha",
  "final_url": "https://en.wikipedia.org/wiki/Nezha",
  "status": 200, "title": "Nezha", "content": "# Nezha\n\n...",
  "content_format": "markdown", "length": 5234, "engine": "http", "error": null
}
  • mode: http (fast) · browser (JS render) · stealth (anti-bot) · auto (default).
  • format: markdown (default) · text · html.
  • Bulk: POST /fetch/bulk with {"urls":[...]}{"results":[...]} (per-URL error isolation, capped at 10).

MCP client config

{
  "mcpServers": {
    "local-web-search": { "type": "http", "url": "http://localhost:15487/mcp" }
  }
}

Tools:

  • web_search(query, max_results=5, search_depth="basic", include_answer=false)
  • fetch_page(url, mode="auto", format="markdown", max_chars=8000, css_selector=None)
  • fetch_pages(urls, mode="auto", format="markdown", max_chars=8000, css_selector=None)

Configuration (env)

Var Default Meaning
WEB_SEARCH_SECRET (empty) Bearer required on /search. Empty ⇒ keyless (Authorization ignored).
SEARXNG_URL http://localhost:8080 SearXNG base URL (compose: http://searxng:8080).
SEARXNG_ENGINES (empty) Comma-separated engine subset; empty ⇒ SearXNG defaults.
SEARXNG_TIMEOUT_S 15 SearXNG request timeout.
ENABLE_EXTRACT true Full-page extract on search_depth="advanced".
EXTRACT_TOP_N 3 How many top results to extract.
EXTRACT_MAX_CHARS 4000 Cap on extracted content length.
ENABLE_FETCH true Enable the /fetch + /fetch/bulk API and fetch_* MCP tools.
SCRAPLING_MCP_URL http://scrapling:8000/mcp Scrapling sidecar MCP URL. Empty ⇒ disable Scrapling (http/auto via in-process fallback; browser/stealth → 502).
FETCH_DEFAULT_MODE auto Default fetch mode.
FETCH_MAX_CHARS 8000 Default cap on fetched content.
FETCH_BULK_MAX_URLS 10 Max URLs per /fetch/bulk.
PORT 15487 Host-published port (container-internal stays 8090 under compose).

SearXNG must have formats: [html, json] (set in searxng/settings.yml) — the shim calls /search?format=json. Without it you get an upstream error with a clear hint.


Register in LoreWeave (BYOK web_search)

  1. Provider credentialprovider_kind = web_search, endpoint_base_url = http://<host>:15487, secret = WEB_SEARCH_SECRET (empty for keyless).
  2. User modelprovider_model_name = searxng-default, capability_flags = {"web_search": true} (strict), pricing = {"input_per_mtok":0,"output_per_mtok":0}.
  3. is_active = true (+ is_favorite to make it the preferred web_search model).

Test

pip install -r requirements.txt pytest
pytest -q          # contract tests, no live SearXNG needed (SearXNG is mocked)

Troubleshooting: ERROR lines in the searxng container logs

Seeing things like SearxEngineCaptchaException, google ... IndexError, Too many request (suspended_time=180), or engine timeout? That's normal and not a fault in this service. They come from SearXNG's per-engine scrapers, not the shim (the web-search container logs stay clean).

  • Public engines (Google/DuckDuckGo/Brave/…) routinely block, CAPTCHA, or rate-limit a single server IP. SearXNG logs each failed engine at ERROR.
  • SearXNG queries many engines and merges whatever succeeds, so a few engines failing still returns a full result set — that's the resilience.
  • Don't disable engines to silence the logs — thinning the pool means a transient rate-limit on the survivors can yield zero results. Keep the broad set. We remove only the Tor engines (ahmia, torch), which can't load without a Tor proxy and never return anything (see searxng/settings.yml).
  • Bursty testing trips rate limits (engines auto-suspend ~180s then recover). At normal deep-research volume you'll rarely see them.

Notes

  • Returned text is untrusted. LoreWeave neutralizes it (INV-6) regardless; this service returns clean text but is never trusted.
  • Stateless — no GPU, no model lifecycle (unlike rerank/STT/TTS).
  • Graceful — backend down/slow ⇒ 502 {"error":"upstream"} / 429 {"error":"rate_limited"}; LoreWeave degrades the research turn to "search unavailable" and never blocks the chat.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选