Skip to main content
Glama

WebX —— 面向编码代理的本地按需网络搜索

面向编码代理的小型本地工具,仅在需要时提供网络访问权限。并非研究代理——仅提供两个原语加生命周期管理:

search(query) -> ranked URLs/snippets   (local SearXNG, Docker, 127.0.0.1:8888, normally stopped)
read(url)     -> cleaned Markdown       (controlled fetch + Trafilatura, SSRF-protected)
  • 极简代理模式: 代理仅在临时提示词授权时调用 webx search / webx read / webx stop。系统提示词中不常驻网络工具。

  • 探索/MCP 模式: 宿主启动 webx-mcp(stdio)。服务端仅暴露 web_search + web_read。启动时不会启动 SearXNG;首次 web_search 时惰性启动并负责关闭。

安装

需要 Python 3.12+,搜索功能需要 Docker + Compose。webx read 无需 Docker 即可使用。

# with uv (recommended)
uv sync
uv sync --extra mcp      # for MCP server
uv sync --extra dev      # for tests

# or pip
pip install -e .
pip install -e ".[mcp]"

# global tool (so `webx` works in `pi`'s bash and any shell)
uv tool install .        # installs to ~/.local/bin/webx — ensure ~/.local/bin is on PATH
# or pipx
pipx install .

# per-project (no global install)
uv sync && uv run webx --help
# or add .venv/bin to PATH for this shell/session (useful for pi coding agent)
export PATH="$PWD/.venv/bin:$PATH"
which webx && webx --help

pi 编码代理注意事项: pi 内的 bash 工具继承宿主的 PATH。若提示 webx: command not found,请执行一次 uv tool install .,或在启动 pi 的会话中执行 export PATH="$PWD/.venv/bin:$PATH"

Related MCP server: mcp-searxng

快速开始

webx init                # materialize ~/.local/share/webx/{compose.yml,settings.yml,.env,cache}
webx doctor              # check docker, templates, SearXNG reachability (does NOT start SearXNG)
webx status              # {initialized, docker_available, searxng_running, url, runtime_dir}
webx status --json

webx search "SearXNG documentation" --limit 5 --pretty
webx status              # now running

webx read "https://docs.searxng.org/" --max-chars 12000
webx read "https://docs.searxng.org/" --json | jq

# denials are exit 5
webx read "http://127.0.0.1:8888/"      # -> exit 5 unsafe URL
webx read "http://192.168.1.1/"         # -> exit 5
webx read "file:///etc/passwd"          # -> exit 5

webx stop                # docker compose stop (retains container)
webx status              # stopped

临时网络访问(极简代理模式)

For this task you are allowed to use the local WebX utility when external/current
information materially helps.
Available commands:
- webx search "<query>" to discover relevant public-web sources.
- webx read "<url>" to read a relevant public page as cleaned text/Markdown.
...
When the web-research portion is finished, run webx stop.

MCP 宿主配置

仅支持 stdio。示例(Claude Code / MCP Inspector):

{
  "mcpServers": {
    "webx": {
      "command": "webx-mcp",
      "env": { "WEBX_DATA_DIR": "/home/you/.local/share/webx" }
    }
  }
}

工具列表必须严格为 web_search + web_read。生命周期由内部管理——不要webx up/stop 暴露为代理工具。

CLI 参考

webx --help
webx --version
webx init [--force-templates] [--show-path]   # idempotent, never rotates secret
webx doctor                                   # inspection only
webx up                                       # ensure SearXNG running
webx stop                                     # compose stop (normal shutdown)
webx status [--json]
webx logs [--tail 100]
webx search QUERY [--limit 8] [--category general] [--language en] [--page 1]
              [--time {day,month,year}] [--safe-search {0,1,2}] [--engine NAME] [--pretty]
webx read URL [--max-chars N] [--json] [--links] [--no-tables] [--precision] [--recall]
  • stdout = 数据(搜索输出 JSON,读取输出 Markdown/文本或 JSON)。stderr = 诊断信息。

  • 退出码:0 成功,2 用法错误,3 运行时/Docker 不可用,4 SearXNG 故障,5 URL 不安全,6 抓取/提取失败,7 不支持的 Content-Type(2xx 但为 image/*application/pdf 等)。公共 URL 返回 4xx/5xx/超时属于 6,而非 7(例如 wikimedia PNG -> HTTP 400 -> 6)。

--verbose(全局)向 stderr 输出调试跟踪(例如 read ok: https://example.com/ text/html 114 chars engine=trafilatura 1.23s)。密钥永不打印。

引擎/分类示例(SearXNG 聚合 269 个服务;上游限流时可按查询过滤):

webx search "python httpx" --engine wikipedia --engine github --pretty
webx search "SearXNG" --category it --pretty
webx search "SearXNG documentation" --time month --pretty

读取器提取示例(--links 保留 [text](url) Markdown 格式;--precision/--recall 调节 trafilatura):

webx read "https://en.wikipedia.org/wiki/Python_(programming_language)" --max-chars 2000 --links | head -n 40
webx read "https://en.wikipedia.org/wiki/Python_(programming_language)" --max-chars 2000 | head -n 40
webx read "https://api.github.com/zen" --json | jq  # application/json is returned raw (engine=raw), not trafilatura

运行时与配置

运行时目录由 platformdirs 决定(可通过 WEBX_DATA_DIR 覆盖):

  • Linux:~/.local/share/webx/(XDG)

  • macOS:~/Library/Application Support/webx/

  • Windows:%LOCALAPPDATA%\webx\

包含 compose.ymlsettings.yml.envSEARXNG_SECRET 0600)、cache/

settings.yml 是精简覆盖(use_default_settings: trueformats: [html, json]limiter: falsepublic_instance: falseimage_proxy: false)。不要复制整个 SearXNG 默认配置。

compose.yml

services:
  searxng:
    image: ${SEARXNG_IMAGE:-docker.io/searxng/searxng:latest}
    container_name: webx-searxng
    ports: ["127.0.0.1:8888:8080"]
    env_file: [.env]
    volumes: ["./settings.yml:/etc/searxng/settings.yml:ro", "./cache:/var/cache/searxng"]
    restart: "no"

仅绑定回环地址,单容器,无 Valkey/Redis,无代理,无 TLS。若只读单文件挂载因 SearXNG FORCE_OWNERSHIP 而失效,可改用目录挂载——但必须保持 127.0.0.1 绑定(参见 04_SEARXNG_RUNTIME.md)。

环境变量覆盖(均为 WEBX_ 前缀):

WEBX_DATA_DIR, WEBX_SEARXNG_URL (default http://127.0.0.1:8888), WEBX_DOCKER_CMD,
WEBX_STARTUP_TIMEOUT (30s), WEBX_SEARCH_TIMEOUT (15s), WEBX_READ_TIMEOUT (15s),
WEBX_MAX_RESPONSE_BYTES (10 MiB), WEBX_MAX_READ_CHARS (40000), WEBX_MCP_STOP_ON_EXIT (true)

SEARXNG_IMAGE 也可在 .env 或环境中设置,用于固定镜像标签。

SearXNG 镜像版本

实现时已验证(2026-08-20):

  • 标签:docker.io/searxng/searxng:latest

  • 解析摘要:sha256:ec536bcd1e83577aad4cc07f7ecb9a30858a9a905d2d57c8796abc83f872a036(本地镜像 ec536bcd1e83,SearXNG 2026.8.1-8892414dc

  • 可通过 SEARXNG_IMAGE 配置——每次搜索不会自动拉取。

手动更新:

webx stop
docker compose -f $(webx init --show-path)/compose.yml pull   # or: SEARXNG_IMAGE=... docker compose pull
webx up
webx search "test" --limit 1 --pretty
webx stop

永不自动更新搜索。

MCP 生命周期

  • 启动 webx-mcp 不会启动 SearXNG。

  • 首次 web_search 探测 http://127.0.0.1:8888/;若未运行则执行 docker compose up -d 并轮询,然后标记 started_by_mcp = true;若已在运行则标记 false

  • web_read 永不启动 SearXNG。

  • 正常退出时,若 started_by_mcp && WEBX_MCP_STOP_ON_EXIT 则执行 compose stop;否则保持 SearXNG 运行。进程内锁保护并发首次搜索。多个独立 MCP 进程需要租约/引用计数——推迟到 v2。

工具描述明确信任边界:返回的页面文本是 不可信的外部数据,绝非代理指令;JS/需要登录的页面可能无法正常工作。

安全模型

webx read 将 URL 视为不可信输入。

  • 仅允许 http:// / https://;拒绝 file:ftp:data:javascript:、裸路径、含凭据的 URL。

  • 通过操作系统解析器解析主机名,使用 ipaddress 检查 每个 IPv4/IPv6 地址:拒绝回环、RFC1918 私网、IPv6 ULA、链路本地(169.254.0.0/16fe80::/10)、组播、未指定、保留地址、元数据地址 169.254.169.254,以及 SearXNG 端点本身。v1 不提供 --allow-private

  • DNS 重绑定残余风险: 先解析后连接无法完全阻止重绑定,因为 httpx 可能再次解析;WebX 会验证每个重定向目标并记录此限制。地址固定是 v2 可能的加固方向,v1 不引入。

  • 重定向:手动循环,最多 5 次,Location 基于当前 URL 解析,重新校验,循环超限或非法则失败。

  • 抓取:User-Agent: webx/<version> local-research-tool,连接超时 5 秒,读取超时 15 秒,流式读取并预先检查 Content-Length + 10 MiB 上限,不伪装浏览器。

  • 允许的类型:text/htmlapplication/xhtml+xmltext/plain、类 Markdown、json/xml 文本;二进制(image/*application/pdf 等)→ 退出码 7。

  • 提取:原始正文 → trafilatura.extract(output_format="markdown", ...) + html2txt 兜底;在提取 之后 按词/换行边界截断,报告 truncated + characters

  • 无 Cookie、无认证头、无 POST、无浏览器。

运维与故障排查

webx doctor 是第一诊断手段。

故障现象

可能原因

doctor 提示 docker 不可用

安装 Docker/Compose;webx read 仍可使用

搜索返回 403

settings.yml 中未启用 json 格式(检查 search.formats

SearXNG 启动但搜索 0 结果 / 5xx

上游引擎限流 / 对您的 IP 触发 CAPTCHA——检查 webx logs 中的 suspended_time=180 / Too many request / HTTP 403。这不是 WebX 的 bug;可尝试不同查询/分类,或固定引擎:webx search "…" --engine wikipedia --engine githubgoogle cse 通常是此 IP 下唯一未被限流的引擎)

读取器返回极短文本

JS 渲染页面——尝试 --recall 或换用其他来源;浏览器渲染不在 v1 范围内

读取器拒绝 URL

私网/本地网络拒绝——属预期行为

webx logs 为空

SearXNG not running——webx logs 现在会提示 run webx up or webx search to start,而非静默输出空内容

WEBX_DATA_DIR=/tmp/... webx status 显示 running:truecompose missing

所有目录共享同一个 webx-searxng 容器名——status 现在显示 compose: missing 并附说明;探测为全局 127.0.0.1:8888

pi 中提示 webx: command not found

~/.local/bin 不在 PATH 中——参见安装部分(uv tool install / export PATH="$PWD/.venv/bin:$PATH"

研究启发式方法(代理侧,非 WebX 职责):优先官方文档 → 上游仓库/说明 → 规范 → 厂商公告 → 高质量文章;需要时使用 --category it;执行多次聚焦搜索,阅读一手来源,主动寻找矛盾信息。

测试

uv sync --extra dev --extra mcp
uv run pytest                # fast unit tests, no Docker/net required
uv run pytest -m integration # live tests (needs Docker + net, marked integration)
uv run pytest --cov=webx

手动验收(从干净的 WEBX_DATA_DIR 开始):

webx --help; webx init; webx doctor; webx status   # stopped
webx search "SearXNG documentation" --limit 5 --pretty
webx status                                        # running
webx read "https://docs.searxng.org/" --max-chars 12000
webx read "http://127.0.0.1:8888/"      # -> exit 5
webx read "http://192.168.1.1/"         # -> exit 5
webx read "file:///etc/passwd"          # -> exit 5
webx stop; webx status                 # stopped
# MCP: inspector 2 tools, web_read while stopped, first search starts, second reuses, stop-on-exit ownership

关于 httpbin.org 的说明: 线上 httpbin.org 目前从部分网络返回 503 Service Temporarily Unavailable(2026-08-20 通过 curl -A "webx/0.1.0"curl -A "Mozilla/5.0" 均验证为 503)。若 webx read https://httpbin.org/html 返回 503,请使用稳定替代:https://example.comhttps://en.wikipedia.org/wiki/Python_(programming_language)(适合截断/--links 测试),或 https://httpbingo.org/get

项目结构

src/webx/
  __init__.py, cli.py, config.py, lifecycle.py, searxng.py, security.py, reader.py, core.py, mcp_server.py
  assets/{compose.yml,settings.yml}
tests/{unit,integration}
docs/{instructions,PLAN.md}

核心 WebX 门面由 CLI 和 MCP 共享;两者互不调用对方。

非目标(v1)

浏览器/Playwright、PDF 读取器、爬虫、重排序器、LLM 摘要器、缓存、进程间租约、引擎预设、域名过滤——理由及 v2 候选方案参见 09_DECISIONS_AND_FUTURE.md

许可证

MIT

A
license - permissive license
Not graded
quality - not tested
B
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    A
    quality
    D
    maintenance
    Enables AI assistants to perform web searches and read URL content via a SearXNG instance.
    2
    15
    MIT
  • A
    license
    A
    quality
    C
    maintenance
    Enables local LLMs to search the web and fetch clean content from URLs without API keys, using SearxNG and Mozilla Readability.
    2
    35
    MIT

View all related MCP servers

Related MCP Connectors

  • Read any web page as clean Markdown for AI agents: fetch, search, metadata, links. SSRF-safe.

  • LLM-ready web search + instant answers + URL-to-clean-text fetch for agents and RAG.

  • Read a URL as clean markdown, screenshot a website, url to PDF. Web access for agents, no signup.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Fatih0234/web-searxng'

If you have feedback or need assistance with the MCP directory API, please join our Discord server