Skip to main content
Glama

agg-search

tests release license python

多引擎并行召回 + RRF 融合 + Jina 精排的搜索工具链:CLI + MCP server(stdio/HTTP)+ 分层抓取,宿主机零依赖(纯 Python 标准库)。

A multi-engine search stack for agents: parallel recall across fourteen engines (three platform-native sources through the optional Agent-Reach CLI, three keyless domain sources), RRF fusion, listwise reranking, domain profiles, a local feedback loop, plus a tiered fetcher. Ships as a CLI and an MCP server — stdio, or streamable HTTP — with standard library only on the host.

agg-search terminal demo

真实一次运行的输出:7 个引擎返回结果,DeepSeek 因余额不足进入冷却、被跳过;空结果不阻塞其余引擎。


为什么又一个搜索聚合器

同类项目不少,但多数是「多引擎 + 简单合并」或「零 key 依赖单一索引」。这个项目的差异在六件事:

  1. DeepSeek 搜索/抓取是一等公民 —— 官方 /v1/tools/search 自带 rerank_score,/v1/tools/fetch 服务端取页直接给 Markdown,省掉容器。

  2. 抓取是阶梯而不是一个函数 —— 平台 URL 先走 Agent-Reach 结构化读取,再 DeepSeek Fetch → 静态 → 动态 → 反爬,逐级升级,跑在隔离容器里,宿主机不装浏览器。

  3. 排序是两阶段 —— RRF 粗排前 15,再交给 Jina Reranker v3.5 listwise 精排;模型不可用链式回退 v3 → v2,全失败则保留 RRF 顺序,绝不阻塞。

  4. 韧性层是显式的 —— 5 分钟结果缓存 + 15 分钟页面缓存、按错误类型分级的冷却(额度 1h / 反爬 10min / 超时 90s)、引擎健康与延迟上报,缺 key 的引擎提前剔除不占线程。

  5. 面向 Agent 的协议面 —— MCP 双时代:无状态的 2026-07-28(server/discover、resultType、缓存提示)与走握手的 2025-11-25 及更早版本(含 outputSchema/structuredContent、tool annotations、按门户的 prompts)、stdio 与 streamable HTTP 两种传输、按调用计的硬超时与 notifications/cancelled、14 家客户端的配置生成器。

  6. 领域画像 + 本地反馈回路 —— --profile academic|code|news|platform 换的是引擎组合、RRF 权重、默认时效与摘要长度(数据驱动,不改代码);search 记录哪些引擎召回了结果、fetch 记录哪些被真正读过,agg-search-tune 据此调整引擎权重,越用越贴合本机习惯。

Related MCP server: jina-web-mcp

架构

flowchart LR
  subgraph clients[Agent clients]
    CC[Claude Code]
    CX[Codex]
    CU[Cursor]
    VS[VS Code]
    OC[OpenCode]
  end
  CC & CX & CU & VS & OC -->|stdio JSON-RPC| M[agg-search-mcp]
  CC & CU & VS -->|streamable HTTP| H[agg-search-http]
  M --> Q
  H --> Q[query expansion<br/>local ollama]
  Q --> A[exa]
  Q --> B[brave]
  Q --> C[serper]
  Q --> D[deepseek]
  Q --> E[firecrawl]
  Q --> F[anysearch]
  Q --> G[tavily]
  Q --> Hh[searxng]
  Q --> OA[openalex]
  Q --> HN[hn]
  Q --> ST[stack]
  Q --> AG[ar_github]
  Q --> AY[ar_youtube]
  Q --> AB[ar_bilibili]
  A & B & C & D & E & F & G & Hh & OA & HN & ST & AG & AY & AB --> R[RRF fusion<br/>profile weights ×<br/>learned multipliers]
  R --> J[jina rerank v3.5<br/>fallback v3 → v2]
  J --> O[top N results<br/>+ provenance + health]
  O --> AN[optional cited answer]

安装

# PyPI(0.2.0 起)
uvx --from agg-search agg-search-mcp          # 不落盘,直接跑

# 或者装成常驻命令(6 个入口:3 个 CLI + MCP stdio/HTTP + 安装器)
uv tool install agg-search

源码方式:

git clone https://github.com/TsukimioRinka/agg-search
cd agg-search
uv pip install -e .
# 或者完全不安装:
PYTHONPATH=src python3 -m agg_search.search "query"

下载入口(Agent × 领域)

入口

说明

docs/catalog.md

14 家 Agent × 5 个领域画像的完整入口表

catalog.json

同一份数据的机器可读版本(给脚本/目录站用)

docs/portals.md

70 个 agent × domain 门户隔离规格(工具子集/顺序、prompt、依赖与降级)

portals.json

机器可读门户注册表(与 catalog.json 严格同步)

Cursor / VS Code

表里是一键深链,直接带上 AGG_SEARCH_PORTAL / AGG_SEARCH_PROFILE

Claude Code / Codex

一条 mcp add 命令,含 --env

其他客户端

agg-search-install --portal <client>.<domain> --write

实测记录

docs/agent-tests.md:6 个 CLI 客户端的门户隔离实测

非 general 画像注册为独立的 server 名(agg-search-academic、agg-search-code、agg-search-news),可以和默认的 agg-search 并存。

agg-search-install --portals --markdown   # 重新生成 docs/portals.md
agg-search-install --portals              # 打印 portals.json
agg-search-install --catalog --markdown   # 重新生成 docs/catalog.md
agg-search-install --catalog              # 打印 catalog.json

使用

# 搜索
agg-search "rust async runtime comparison" --top-n 10 --recency month

# 域名过滤:只留 arxiv/.edu,去掉 reddit
agg-search "speculative decoding" --include-domains arxiv.org,.edu \
  --exclude-domains reddit.com

# 机器可读输出(含引擎状态、延迟、冷却与过滤计数)
agg-search "MCP server examples" --json

# RAG-Fusion 查询扩展(需要本地 ollama)
agg-search "vector database tradeoffs" --expand 3

# 带引用的答案段(auto:先本地 ollama,失败可落 DeepSeek API,会产生计费;
# 想完全避免费用用 --answer local)
agg-search "what changed in Python 3.13" --answer local

# 快速模式:单池扇出,最早两个有结果的引擎就返回
agg-search "breaking news" --fast --budget-secs 20

# 诊断:打印生效配置(密钥只显示布尔值),或列出可用引擎
agg-search --show-config
agg-search --help

# 抓取正文:DeepSeek Fetch 优先,失败落容器阶梯
crawl-fetch --url https://example.com/post --tier auto --out md

密钥只从环境变量读(也兼容 ~/.config/agent-env、~/.config/ai-keys.env 的 KEY= 行)。缺失的引擎会被跳过,不会让整次搜索失败。常用默认值可用 AGG_SEARCH_ENGINES、AGG_SEARCH_TOP_N、AGG_SEARCH_PER_ENGINE、AGG_SEARCH_SNIPPET_CHARS、AGG_SEARCH_FAST、AGG_SEARCH_NO_JINA、AGG_SEARCH_PROFILE、AGG_SEARCH_NO_LEARN 覆盖,命令行显式传参优先。完整变量表见 docs/environment.md。

MCP server

暴露工具按门户隔离(默认 search + fetch;academic 门户按 search -> fetch -> answer 暴露三件套):

工具

主要参数

说明

search

query、top_n、recency、engines、portal、profile、include_domains、exclude_domains、snippet_chars、expand、answer、answer_fetch、fast、budget_secs、engine_timeout、no_jina

并行召回 + 内容去重 + 权威先验 RRF + 精排;返回文本内容 + structuredContent

fetch

urls、tier、out、text_limit

分层抓取正文(SSRF 守卫由服务端环境变量控制);每 URL 一条结果

answer

query、sources、urls、mode、portal、profile

仅在 academic 门户暴露;读取摘要或抓取全文,按 Agent 回退顺序合成带引用回答

协议行为:

  • 协议版本:2026-07-28 的请求无需握手,版本和客户端能力写在每个请求的 _meta 里,不支持的版本返回 -32022 并列出支持的版本;旧客户端用 initialize 协商 2025-11-25 / 2025-06-18 / 2025-03-26 / 2024-11-05,不认识的版本回 2025-11-25。

  • 服务端无法执行的工具参数(缺 query/urls、该是字符串却传了对象、数字不合法、recency 等取值不在范围内)按 2025-11-25 起的规定返回 isError: true 的工具结果,模型能读到原因并改正;1.0 能用的写法都照旧(null 视为未传,越界数字由 CLI 夹取,列表参数可写逗号字符串,未知参数忽略)。未知工具、门户未启用的工具仍是 -32602。

  • 工具带 title、annotations(readOnlyHint、openWorldHint)和 outputSchema;支持结构化输出的客户端直接拿 structuredContent,老客户端仍拿文本。

  • 每个工具调用有硬墙钟(search 120s / fetch 300s),超时杀进程组;notifications/cancelled 同样会中断。

  • 工具调用在线程池里跑,ping/tools/list 不会被慢引擎卡住。

  • prompts/list / prompts/get:每个门户一个研究流程提示,名字是 <领域>-research(general-research、academic-research、code-research、news-research;不绑门户时为 web-research),参数 topic(≤500 字,剥离控制字符)。提示只列出该门户启用的工具,跨门户取不到;支持 MCP prompts 的客户端会把它显示成斜杠命令。

  • search 在 MCP 下默认 fast=true(有限的召回预算),fast=false 才等全部引擎。

一行接入

agg-search-install --list                     # 支持 14 家客户端
agg-search-install -c claude-code             # 打印 claude mcp add 命令
agg-search-install -c cursor --write          # 合并进 ~/.cursor/mcp.json(自动备份)
agg-search-install -c vscode --scope project  # 写 .vscode/mcp.json
agg-search-install -c cursor --check          # 校验文件、条目与运行时是否就绪

逐客户端的路径、JSON/TOML/YAML 片段与 GUI 环境变量陷阱见 docs/adapters.md。

HTTP 传输

agg-search-http --host 127.0.0.1 --port 8765 --path /mcp

多个客户端共用一个进程(共享缓存与冷却),默认只绑回环并校验 Host/Origin(防 DNS rebinding 与浏览器跨站请求),端点不带认证——对外必须先套反向代理。协议细节与 nginx 示例见 docs/http.md。

领域定向与每 agent 策略

agg-search "speculative decoding" --profile academic   # openalex 优先,摘要 500 字,top 15
agg-search "sqlite wal corrupt" --profile code         # stack 优先,摘要 600 字
agg-search "release notes" --profile news --top-n 5    # 默认 recency=day
agg-search "vLLM 推理优化" --profile platform            # GitHub/YouTube/B站 平台源 + web 保底
agg-search --list-profiles

agg-search-install -c cursor --profile code --write    # 把某个客户端钉在 code 画像上

同一套数据也通过 MCP 暴露:工具参数 profile,或环境变量 AGG_SEARCH_PROFILE。优先级 flag > env > profile > 内置默认;openalex / hn / stack / arxiv 免 key,装好就能用;另有 brave_news / serper_news 新闻垂直端点(复用原 key,opt-in)。

反馈回路

search 记录每个结果由哪些引擎召回,fetch 成功读到其中某个 URL 时记一次「被使用」。 agg-search-tune 把 surfaced/used 折算成 0.5–2.0 的引擎权重乘数(样本少于 30 时保持 1.0), 之后所有搜索自动叠加,并进入缓存键——调权重不会命中旧结果。默认开启,--no-learn 或 AGG_SEARCH_NO_LEARN=1 关闭。

agg-search-tune --show   # 反馈表 + 当前乘数
agg-search-tune          # 写入 ~/.config/agg-search/weights.json

只存哈希与计数,不存查询词、页面正文或原始 URL。机制与公式见 docs/profiles.md。

同类项目对比

只列能核实的能力,语言一列仅在仓库自述里明确时填写:

项目

栈

它强在哪

与本项目的差别

search-cli

Rust

13 个 provider,单一二进制

本项目免编译;多容器抓取阶梯与 DeepSeek Fetch 是一等路径

web-search-mcp

TypeScript

注入防御(<untrusted_content> 包裹 + 隐藏字符剥离)、PDF/RSS/YouTube 抽取、本地语义重排、Recall@5 / MRR@10 评测、MCP resources/prompts

它的内容抽取与提示注入防护比本项目完整;本项目的差异在 8 引擎并行 + RRF→Jina listwise、DeepSeek Search/Fetch、RAG-Fusion 与容器阶梯。SSRF 防护两边都有,本项目覆盖到抓取前置校验(见 docs/fetching.md)

argo

—

300+ 来源、18 语言、MCP/CLI

本项目只做通用网页检索,覆盖面窄;差异在排序链路与成本控制更细

Tavily MCP

TypeScript

托管远端端点、search/extract/map/crawl 四件套、DEFAULT_PARAMETERS

本项目可自带引擎、离线缓存与精排链,不绑定单一供应商

Brave MCP

TypeScript

官方索引,HTTP 传输带 Origin/Host 白名单

本项目多引擎融合;传输层安全策略参考了它的做法

Exa MCP

TypeScript

托管端点 + OAuth、dynamic highlights

本项目无托管依赖,密钥和缓存都在本机

测试

uv venv && uv pip install -e .
python3 -m unittest discover -s tests -v

220+ 个离线测试:门户隔离与降级、内容去重、权威先验、域名过滤、RRF、冷却分类、缓存键、SSRF 判定、安装器、MCP 协议面与 stdio/HTTP 端到端(不发起网络请求、不消耗额度)。CI 覆盖 Python 3.10–3.13 + ruff。

安全与隐私

  • 仓库内不含任何密钥、账号、内网地址;.env.example 只有空占位。

  • 密钥只在进程环境里读取,不写日志、不落盘;--show-config 只输出布尔值。

  • 抓取前置 SSRF 校验:仅 http(s)、无 userinfo、私网/回环/链路本地/云元数据地址默认拒绝(--allow-private 显式放开);响应体上限 4 MiB。

  • 抓取在容器内执行,宿主机不留浏览器与爬虫依赖。

  • 进入模型上下文的页面文本会剥离零宽与双向控制字符(隐藏指令的常见载体),MCP 指令块也声明页面内容为不可信数据。

  • HTTP 传输默认回环绑定 + Host/Origin 白名单,无认证时不得裸奔到公网。

稳定性

从 1.0 起按 SemVer 发版。命令名、CLI 参数、--json 字段、crawl-fetch 的输出与退出码、MCP 工具/提示与协议版本、画像/门户/引擎名、环境变量和安全行为都在承诺范围内;结果排序等质量参数会按评测数据在次版本中调整。详见 docs/stability.md。

文档

文档

内容

docs/install.md

安装方式、环境变量全表、冒烟测试

docs/adapters.md

14 家客户端的接入配置

docs/http.md

HTTP 传输、安全模型、反向代理

docs/profiles.md

领域画像、每 agent 策略、反馈回路与调参

docs/portals.md

70 个 agent × domain 门户规格、工具顺序与降级路径

docs/stability.md

1.0 起的稳定性承诺:哪些接口受 SemVer 保护、弃用流程

docs/benchmarks.md

各项增强与领域调整的对照评测(候选 A–M)、合入与拒绝的依据

docs/agent-tests.md

6 个 CLI 客户端的门户隔离实测与清理记录

docs/handoff.md

交接:本机路径、凭据位置、逐层验证与发版流程

docs/fetching.md

分层抓取的梯子与容器

docs/reranking.md

RRF 与 Jina 精排、参数扫描、领域 A/B 工具(tools/eval-offline.sh)

docs/environment.md

环境变量与计费说明

License

MIT

Available Tools

2 tools
fetchFetch pages as clean textA
Read-onlyIdempotent

Read one or more URLs as clean text. Tries the DeepSeek Fetch API first (no container), then a static -> dynamic -> stealth container ladder for JS-heavy or anti-bot pages. Returns one result object per URL with the rung used and the page text.

Inputs: urls (required), out, tier, text_limit. Returns: results

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.9/5.0

    Scored across 2 tools

    Disambiguation5/5

    The two tools have entirely distinct roles: `search` discovers results across engines, while `fetch` reads a specific URL as text. Descriptions even cross-reference each other, explicitly steering an agent to use search for recall and fetch for reading a promising hit.

    Naming Consistency5/5

    Both names are single, lowercase verbs following the same minimal convention (search, fetch), with no mixing of styles or casing. A predictable pattern is trivially evident with only two tools.

    Tool Count3/5

    Two tools is on the thin side, though it matches a focused retrieval server's scope. The functionality is heavily parameterized internally (engine selection, fetch ladder), so the small surface is defensible but borderline.

    Completeness4/5

    Search plus fetch covers the core discover-then-read workflow with no dead ends for a read-only retrieval domain. Minor gaps like result caching, pagination, or structured/extraction options are absent but not blocking.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers