@nite07/websearch-mcp 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -32,50 +32,36 @@ and Reddit, which need no account.
32
32
  1. Open `~/.config/websearch-mcp/config.json`.
33
33
  2. Under `search.backends`, set `"enabled": true` on the providers you want. Anonymous tiers —
34
34
  Keenable, Exa, You.com, AnySearch, Parallel, Reddit — need nothing else.
35
- 3. Register the server with your MCP client (next section).
35
+ 3. Register the server with your MCP client (see **Client configuration**).
36
36
  4. Ask the client to search. To see what is available without spending anything, call
37
37
  `list_backends` first: it reports each backend's modes, cost tier, enabled state and whether a
38
38
  credential is present. It never enables anything.
39
39
 
40
+ ## Search results
41
+
42
+ Each result names the backends that found it, including multiple sources for the same page.
43
+ The response also shows which backends were used and whether it came from the cache.
44
+
40
45
  ## Settings page
41
46
 
42
- The configuration has a page: every backend, its access mode, its cost tier, its options and its
43
- credential in one form, plus a probe button per backend. **The MCP server serves it itself** — one
44
- process, no extra unit, container or port-forwarder to install:
47
+ Use the settings page to choose backends, check costs, enter credentials and test your setup:
45
48
 
46
49
  ```sh
47
- WEBSEARCH_MCP_UI_PORT=7799 WEBSEARCH_MCP_UI_TOKEN=... websearch-mcp # stdio client + page
50
+ WEBSEARCH_MCP_UI_PORT=7799 WEBSEARCH_MCP_UI_TOKEN=replace-with-a-long-random-token websearch-mcp
48
51
  ```
49
52
 
50
- - `WEBSEARCH_MCP_UI_PORT` turns the page on for that process; `WEBSEARCH_MCP_UI_HOST` picks the bind
51
- address (default `127.0.0.1`, so a client on the same machine needs nothing else).
52
- - The page lives exactly as long as the server does. When the client closes stdin the process exits
53
- and the port is released, which also means a client that respawns the server gets a fresh page.
54
- - A port that cannot be bound is reported on stderr and the MCP tools carry on: a page is never a
55
- reason to lose the tools.
56
- - **Authentication is on only when a token is supplied, and the token comes from the environment or
57
- the command line — this server never writes one to disk.** `--no-token` (page-only mode) or
58
- `WEBSEARCH_MCP_UI_TOKEN` (any mode) decides it; with neither, the page is open and the log says so.
59
- - With a token the first request carries `?token=`, exchanged for an `HttpOnly`, `SameSite=Strict`
60
- cookie, so the link does not stay in browser history.
61
- - Saving validates against the same schema the server enforces. A rejected save leaves the file
62
- untouched and lists every problem by path; an accepted one writes `config.json.bak-<local time>`
63
- (five kept) and replaces the file atomically at mode 0600. The server watching that file reloads
64
- immediately, so the next `web_search` already uses what the page saved.
65
- - The page has **Search** and **Page fetch** tabs over one shared draft: the fetch tab edits route
66
- order and enablement, per-route fallback rules, the one selected fetch provider (with its own access
67
- mode, endpoint, timeout and options), the safety limits, and a user-triggered fetch test that takes a
68
- URL and a required format. Fetch settings live in the same file, so a running server picks them up
69
- through the same watcher.
70
- - A file that stops parsing keeps the previous configuration and says why on stderr.
71
- - When a `config.container.json` sits beside the file, every save rewrites it too: loopback endpoints
72
- become `host.containers.internal`, and the browser session file is mapped into `/host/home`. The
73
- companion is never created on its own.
74
-
75
- Page without an MCP client, for a quick look:
53
+ Open `http://127.0.0.1:7799/?token=replace-with-a-long-random-token`. The page is available while the MCP server is running.
54
+ Set `WEBSEARCH_MCP_UI_HOST` if you need a different bind address. Without a token, the page is open;
55
+ set one before exposing it beyond your machine.
56
+
57
+ The page has sections for search, reliability, diagnostics, backends, browser setup and page fetching.
58
+ Saved changes take effect on the next call, without restarting the server. Invalid changes are
59
+ rejected; recent configuration backups are kept automatically.
60
+
61
+ To run only the settings page:
76
62
 
77
63
  ```sh
78
- websearch-mcp --ui --host 0.0.0.0 --port 7799 --print-url # --print-url prints the links and exits
64
+ websearch-mcp --ui --port 7799 --token replace-with-a-long-random-token
79
65
  ```
80
66
 
81
67
  ## Client configuration
@@ -117,12 +103,11 @@ Put them where your client can see them:
117
103
  ```
118
104
 
119
105
  If an environment value is absent, `credentials.<backend-id>` may hold the value itself inside the
120
- config file. Values are literal strings: `${...}` is not expanded. Saved `credentialRef` fields are
121
- discarded on load so a file can never redirect a lookup.
106
+ config file. Values are literal strings: `${...}` is not expanded.
122
107
 
123
108
  ## Browser-backed search
124
109
 
125
- Xiaohongshu answers only its own page runtime, so it reads through a browser container you host. Start
110
+ Xiaohongshu search and note reading need a browser container. Start
126
111
  it from [packages/core/image](../core/image/README.md), sign in over VNC, then point the server at it:
127
112
 
128
113
  ```json
@@ -142,54 +127,36 @@ it from [packages/core/image](../core/image/README.md), sign in over VNC, then p
142
127
  ```
143
128
 
144
129
  The endpoint token goes in `DSH_SEARCH_BROWSER_TOKEN`, or in `credentials.browser` inside the file.
145
- `maxConcurrentReads` (1–8) caps how many reads run on the site at once; the default is a conservative
146
- local value, not a site quota. `statePath` must be the file the container writes, otherwise every read
147
- starts signed out.
130
+ Set `statePath` to the container's saved session file. `maxConcurrentReads` (1–8) controls concurrent
131
+ reads on the same site.
148
132
 
149
- Searching needs only the endpoint. Reading a note goes through the same browser, so the backend
150
- must be enabled in browser mode; `xiaohongshu_note` then takes the share link from the app (it
151
- carries the token the read needs) or a note id an earlier search returned.
133
+ To read a note, pass its full share link from the app, or a note id returned by an earlier search,
134
+ to `xiaohongshu_note`.
152
135
 
153
136
  ## Tools
154
137
 
155
138
  | Tool | What it does |
156
139
  | --- | --- |
157
- | `web_search` | Search across the enabled backends. Takes `query`, plus optional `backends`, `allBackends`, `exclude`, `compact` and `maxResults`. `backends` decides how many run: one id runs that backend alone, several run in parallel, and omitting it runs every enabled backend. Anything that cannot be honoured is named in the report rather than silently dropped. |
158
- | `read_thread` | Read one discussion, with the pictures a post carries returned as MCP image content (bounded by count, per-file size and a per-call budget, with every link listed): `source: "reddit"` for a post with its comment tree (`sort`, `limit`, `depth` caps), or `source: "x"` for a post with its replies (needs the X backend in session mode). Comment text is untrusted user content. |
159
- | `xiaohongshu_note` | Read one note: text, author, engagement counts, tags, pictures as image
160
- content, and optionally its top-level comments (depth is one level, `commentLimit` 1–50). Needs the
161
- Xiaohongshu backend in browser mode plus a browser endpoint; a disabled backend, a missing endpoint
162
- or a missing note token is reported instead of an empty note. |
163
- | `list_backends` | Every backend with its modes, cost tier, enabled state and whether a credential is present. It never enables anything. |
164
- | `web_extract` | Fetch **one** page: `url` plus a required `format` (`markdown` to read, `html` to inspect structure). Only one URL per call, never a crawl. Route order, provider selection, credentials and fallback rules are saved configuration. Returned page content is untrusted. **Hidden until `search.tools.webExtract` is `true`**: while it is off the tool is absent from `tools/list` instead of being advertised and refusing to run, and turning it on or off reloads through the SDK's `notifications/tools/list_changed`. |
165
-
166
- `compact: true` returns URL, title and date only, which is usually the difference between a usable
167
- context and a flooded one.
140
+ | `web_search` | Search selected backends with `query`. Optional: `backends`, `allBackends`, `exclude`, `compact`, `maxResults`. One backend id searches only that backend; omitting the selection searches every enabled backend. |
141
+ | `read_thread` | Read a Reddit post and comments or an X post and replies, including pictures. X requires session mode. |
142
+ | `xiaohongshu_note` | Read a note's text, author, engagement, tags and pictures, with optional comments. Requires the Xiaohongshu backend in browser mode and a configured browser. |
143
+ | `list_backends` | List available backends, access modes, costs, enabled state and credential readiness. |
144
+ | `web_extract` | Read one page as Markdown or HTML. Disabled by default; enable it in **Page fetch**. |
145
+
146
+ `compact: true` omits snippets while keeping links, titles, dates and backend provenance.
168
147
 
169
148
  ## Page fetching
170
149
 
171
- Page fetching is the same core engine the DSH plugin uses: ordered routes (HTTP, shared browser, one
172
- selected provider), per-route fallback rules with three-valued conditions, and HTML or Markdown output.
173
- `search.tools.webExtract` defaults to `false`; with it off the tool is hidden while the configuration,
174
- credentials, settings page and library API stay available.
150
+ Use `web_extract` to read a known URL as Markdown or HTML. Enable it in the settings page, or set
151
+ `search.tools.webExtract` to `true` in the configuration file.
175
152
 
176
- ```sh
177
- websearch-mcp --print-config > ~/.config/websearch-mcp/config.json # includes pageFetch and tools.webExtract
153
+ ```json
154
+ { "url": "https://example.com/article", "format": "markdown" }
178
155
  ```
179
156
 
180
- Only public targets are fetched by default, and the HTTP transport pins the connection to the address
181
- the policy validated. Redirects are followed one hop at a time. A browser or provider route resolves
182
- the target elsewhere, so `pageFetch.allowDelegatedFetching` has to be switched on deliberately; the
183
- result then names that trust boundary. Both shipped fetch providers return native Markdown, so
184
- `format: "html"` is served by the HTTP or browser route, and a Markdown-only provider is skipped
185
- without a request.
186
-
187
- ## Protocol versions
188
-
189
- The wire protocol is the [official TypeScript SDK](https://ts.sdk.modelcontextprotocol.io/v2/)
190
- (`@modelcontextprotocol/server`), not a hand-written loop: the server answers the stateless
191
- `2026-07-28` revision and falls back to the 2025 handshake for clients that still open with
192
- `initialize`. A protocol revision therefore reaches this package as a dependency bump.
157
+ Use `"html"` when you need the page structure. Browser support is available for JavaScript pages.
158
+ You can choose a fetch provider in **Page fetch**; check its supported formats and costs, and supply
159
+ an API key if required. Page fetching allows public URLs by default.
193
160
 
194
161
  ## Behaviour worth relying on
195
162
 
@@ -199,11 +166,8 @@ The wire protocol is the [official TypeScript SDK](https://ts.sdk.modelcontextpr
199
166
  not; total failures say the search failed. Failed calls are never cached.
200
167
  - **Per-call strategy, saved config untouched.** `backends`, `exclude` and `compact` apply to that one
201
168
  call, so a narrow lookup and a broad sweep can coexist without editing the file.
202
- - **Reddit is anonymous by default.** No account needed; the adapter uses the same anonymous token the
203
- Android client obtains, because Reddit's public REST search answers 403 to anonymous callers.
204
- - **X thread reading follows the site, not a scraper.** The adapter reads the operation the web app
205
- embeds in the post page and calls it directly, so it survives front-end releases without a
206
- transaction-id signer.
169
+ - **Reddit is anonymous by default.** No account is needed.
170
+ - **X discussions include replies.** Use session mode with valid account cookies.
207
171
 
208
172
  ## Troubleshooting
209
173
 
package/README.zh.md CHANGED
@@ -24,38 +24,34 @@ websearch-mcp --print-config > ~/.config/websearch-mcp/config.json
24
24
 
25
25
  1. 打开 `~/.config/websearch-mcp/config.json`
26
26
  2. 在 `search.backends` 里把想用的那几家改成 `"enabled": true`。匿名档的 Keenable、Exa、You.com、AnySearch、Parallel、Reddit 不需要额外配置
27
- 3. 按下一节把服务注册到你的 MCP 客户端
27
+ 3. 按「客户端配置」把服务注册到你的 MCP 客户端
28
28
  4. 让客户端搜点东西
29
29
 
30
30
  想先看看有什么可用又不花钱,调 `list_backends`:它列出每个后端的模式、费用档、启用状态以及有没有凭证,但不会启用任何东西。
31
31
 
32
+ ## 搜索结果
33
+
34
+ 每条结果都会标注找到它的后端,同一页面可以保留多个来源。响应还会说明本次使用了哪些后端,
35
+ 以及是否命中缓存。
36
+
32
37
  ## 配置页面
33
38
 
34
- 配置有页面了:每个后端的接入模式、成本档位、选项与凭证都在同一张表里,每张卡片带一个实测按钮。
35
- **这个页面由 MCP 服务器自己提供**——一个进程,不需要额外的单元、容器或端口转发:
39
+ 在配置页面选择后端、查看费用、填写凭证,也可以直接测试是否可用:
36
40
 
37
41
  ```sh
38
- WEBSEARCH_MCP_UI_PORT=7799 WEBSEARCH_MCP_UI_TOKEN=... websearch-mcp # stdio 服务 + 页面
42
+ WEBSEARCH_MCP_UI_PORT=7799 WEBSEARCH_MCP_UI_TOKEN=replace-with-a-long-random-token websearch-mcp
39
43
  ```
40
44
 
41
- - `WEBSEARCH_MCP_UI_PORT` 打开页面,`WEBSEARCH_MCP_UI_HOST` 选绑定地址(默认 `127.0.0.1`,
42
- 同机客户端什么都不用加)。
43
- - 页面活多久取决于服务活多久。客户端关掉 stdin,进程退出、端口释放;客户端重新拉起服务,页面也就跟着回来。
44
- - 端口绑不上时只在 stderr 报一句,MCP 工具照常工作——页面永远不该成为丢工具的理由。
45
- - **只有给了令牌才鉴权,令牌只从环境变量或命令行来——服务绝不往磁盘写令牌。** 页面模式也可以用
46
- `--no-token`;两者都没有时页面是开放的,日志会说明。
47
- - 有令牌时第一个请求带 `?token=`,换成 `HttpOnly` + `SameSite=Strict` 的 cookie,链接不留在浏览器历史里。
48
- - 保存用服务端同一套 schema 校验。被拒的保存不动文件,按字段路径列出问题;通过的保存先写
49
- `config.json.bak-<本地时间>`(保留 5 份),再原子替换并设为 0600。服务一直在 watch 这个文件,
50
- 所以保存完下一次 `web_search` 就用新配置。
51
- - 文件解析不了时保留上一份可用配置,并在 stderr 说明原因。
52
- - 配置旁边如果有 `config.container.json`,每次保存会连它一起重写:loopback 端点换成
53
- `host.containers.internal`,浏览器登录态文件映射到 `/host/home`。没有这个文件就不会凭空创建。
54
-
55
- 不想起 MCP 客户端、只想看一眼页面:
45
+ 打开 `http://127.0.0.1:7799/?token=replace-with-a-long-random-token`,页面会随 MCP 服务一起运行。
46
+ 需要更改监听地址时设置 `WEBSEARCH_MCP_UI_HOST`。不设令牌时页面无需登录,向本机以外开放前请设置令牌。
47
+
48
+ 页面分为搜索、可靠性、诊断、后端、浏览器和页面抓取几个部分。保存后下一次调用即使用新配置,
49
+ 无需重启服务;无效配置不会保存,近期配置会自动备份。
50
+
51
+ 只运行配置页面:
56
52
 
57
53
  ```sh
58
- websearch-mcp --ui --host 0.0.0.0 --port 7799 --print-url # --print-url 只打印链接
54
+ websearch-mcp --ui --port 7799 --token replace-with-a-long-random-token
59
55
  ```
60
56
 
61
57
  ## 客户端配置
@@ -93,11 +89,11 @@ websearch-mcp --ui --host 0.0.0.0 --port 7799 --print-url # --print-url 只打
93
89
  }
94
90
  ```
95
91
 
96
- 环境变量没有时,可以用配置文件里的 `credentials.<后端-id>` 直接写值。值是字面字符串,`${...}` 不会被展开。加载时保存的 `credentialRef` 字段会被丢弃,配置文件没办法把查询指到别的密钥上。
92
+ 环境变量没有时,可以用配置文件里的 `credentials.<后端-id>` 直接写值。值是字面字符串,`${...}` 不会被展开。
97
93
 
98
94
  ## 需要浏览器的搜索
99
95
 
100
- 小红书只认自己的页面运行时,所以它走你自己托管的浏览器容器。按 [packages/core/image](../core/image/README.zh.md) 起容器、在 VNC 里登录,然后把它配进来:
96
+ 小红书搜索和笔记读取需要浏览器容器。按 [packages/core/image](../core/image/README.zh.md) 起容器、在 VNC 里登录,然后把它配进来:
101
97
 
102
98
  ```json
103
99
  {
@@ -115,47 +111,42 @@ websearch-mcp --ui --host 0.0.0.0 --port 7799 --print-url # --print-url 只打
115
111
  }
116
112
  ```
117
113
 
118
- 端点令牌写在 `DSH_SEARCH_BROWSER_TOKEN`,或者文件里的 `credentials.browser`。`maxConcurrentReads`(1–8)限制同一个站点上同时跑几个读取,默认值是保守的本地取值,不代表站点额度。`statePath` 必须是容器写的那个文件,否则每次读回来都是未登录。只要端点配好就能搜索;读笔记走的是同一个浏览器,所以后端必须启用为 browser 模式,`xiaohongshu_note` 吃 App 里复制的分享链接(里面带着读取要用的 token),或者之前搜索返回的笔记 id。
114
+ 端点令牌写在 `DSH_SEARCH_BROWSER_TOKEN` 或文件里的 `credentials.browser`。
115
+ `statePath` 填容器保存登录态的文件路径,`maxConcurrentReads`(1–8)控制同一站点的并发读取数。
116
+
117
+ 读取笔记时,向 `xiaohongshu_note` 传入 App 中复制的完整分享链接,或之前搜索返回的笔记 id。
119
118
 
120
119
  ## 工具
121
120
 
122
121
  | 工具 | 做什么 |
123
122
  | --- | --- |
124
- | `web_search` | 在已启用的后端里搜索。参数 `query`,可选 `mode`、`backends`、`allBackends`、`exclude`、`backend`、`compact`、`maxResults`。没法满足的选项会在报告里点名,不会被悄悄忽略。 |
125
- | `read_thread` | 读一个讨论帖,图片以 MCP 图片内容返回(按张数、单文件大小和单次预算限制,所有链接都会列出):`source: "reddit"` 读帖子及评论树(可设 `sort`、`limit`、`depth`),`source: "x"` 读推文及回复(需要 X 后端处于会话模式)。评论内容是用户生成的,不可信。 |
126
- | `xiaohongshu_note` | 读一篇笔记:正文、作者、赞藏评转、标签、配图(以图片内容返回),需要的话再读一层评论(只有一层,`commentLimit` 1–50)。需要小红书后端处于 browser 模式且浏览器端点已配置;后端没开、端点没配、缺笔记 token 都会直说,不会回一篇空笔记。 |
127
- | `list_backends` | 列出每个后端的模式、费用档、启用状态和凭证是否就位。不会启用任何东西。 |
123
+ | `web_search` | 搜索指定后端。必填 `query`,可选 `backends`、`allBackends`、`exclude`、`compact`、`maxResults`。只指定一个后端就只搜这一家,不指定则搜索所有已启用后端。 |
124
+ | `read_thread` | 读取 Reddit 帖子和评论,或 X 帖子和回复,包括配图。X 需要会话模式。 |
125
+ | `xiaohongshu_note` | 读取笔记正文、作者、互动数据、标签和配图,可选读取评论。需要启用小红书后端的 browser 模式并配置浏览器。 |
126
+ | `list_backends` | 查看后端、接入模式、费用、启用状态和凭证是否就绪。 |
127
+ | `web_extract` | 读取单个网页,返回 Markdown 或 HTML。默认关闭,在「页面抓取」中启用。 |
128
128
 
129
- `compact: true` 只回 URL、标题和日期,通常就是一个还能用的上下文和一个被灌满的上下文的区别。
129
+ `compact: true` 不返回摘要,保留链接、标题、日期和来源后端。
130
130
 
131
131
  ## 页面抓取
132
132
 
133
- 页面抓取与 DSH 插件共用同一个 core 引擎:有序路由(HTTP、共享浏览器、一个选定服务商)、按路由配置的
134
- 回退规则(三值条件),输出 HTML 或 Markdown。`search.tools.webExtract` 默认 `false`;关闭时工具不会
135
- 出现在 `tools/list` 里,而配置、凭证、设置页与库 API 仍然可用。
133
+ 用 `web_extract` 读取已知 URL,返回 Markdown 或 HTML。在设置页启用,或将配置文件中的
134
+ `search.tools.webExtract` 设为 `true`。
136
135
 
137
- ```sh
138
- websearch-mcp --print-config > ~/.config/websearch-mcp/config.json # 含 pageFetch 与 tools.webExtract
136
+ ```json
137
+ { "url": "https://example.com/article", "format": "markdown" }
139
138
  ```
140
139
 
141
- 默认只抓公网目标,HTTP 传输会把连接绑定到策略校验过的地址;重定向逐跳跟随。浏览器或服务商在别处解析
142
- 目标地址,所以必须显式打开 `pageFetch.allowDelegatedFetching`,结果里会写明这个信任边界。两个内置抓取
143
- 服务商都只返回原生 Markdown,因此 `format: "html"` 由 HTTP 或浏览器路由提供,只支持 Markdown 的服务商
144
- 会在不发请求的情况下被跳过。
145
-
146
- ## 协议版本
147
-
148
- 线上协议交给[官方 TypeScript SDK](https://ts.sdk.modelcontextprotocol.io/v2/)
149
- (`@modelcontextprotocol/server`),不是手写循环:服务端会说无状态的 `2026-07-28`,对仍在用
150
- `initialize` 开场的客户端回退到 2025 握手。协议改版因此是升依赖,不是重写连接层。
140
+ 需要查看页面结构时使用 `"html"`。支持读取需要 JavaScript 的页面,也可以在「页面抓取」中选择服务商。
141
+ 使用前请查看支持的格式和费用,需要 API Key 的模式应先填写凭证。默认只允许公网地址。
151
142
 
152
143
  ## 可以依赖的行为
153
144
 
154
145
  - **不切换。** 后端只按你选定的模式、你给的凭证、配置里的端点工作。重试不会换服务商、不会换模式。
155
146
  - **失败看得见。** 部分失败返回成功的那部分并点名失败的;全部失败就说搜索失败。失败的调用不会进缓存。
156
- - **单次策略不动配置。** `mode`、`backends`、`compact` 只作用这一次,所以窄查询和广撒网可以并存,不用来回改文件。
157
- - **Reddit 默认匿名。** 不需要账号,用的就是安卓客户端拿的那种匿名 token——Reddit 的公开 REST 搜索对匿名调用一律 403。
158
- - **X 的帖子按站点自己的方式读。** 适配层读页面里内嵌的那个接口再直接调用,前端发版不会失效,也不需要自己签 transaction id。
147
+ - **单次策略不动配置。** `backends`、`exclude`、`compact` 只作用这一次,所以窄查询和广撒网可以并存,不用来回改文件。
148
+ - **Reddit 默认匿名。** 不需要账号。
149
+ - **X 讨论支持读取回复。** 需要使用会话模式,并提供有效的账号 Cookie。
159
150
 
160
151
  ## 常见问题
161
152
 
package/dist/sdk.js CHANGED
@@ -100,10 +100,25 @@ export function render(value) {
100
100
  return record.text;
101
101
  if (Array.isArray(record.sources)) {
102
102
  const lines = [];
103
+ for (const [key, label] of [['enabledBackends', 'Enabled backends'], ['requestedBackends', 'Requested backends'], ['selectedBackends', 'Selected backends'], ['executedBackends', 'Executed backends']]) {
104
+ const ids = record[key];
105
+ if (Array.isArray(ids))
106
+ lines.push(`${label}: ${ids.join(', ') || '(none)'}.`);
107
+ else if (ids === 'all')
108
+ lines.push(`${label}: all enabled (before exclusions).`);
109
+ }
110
+ if (typeof record.cached === 'boolean')
111
+ lines.push(`Cache hit: ${record.cached ? 'yes; no upstream requests were made' : 'no'}.`);
112
+ if (Array.isArray(record.backendStats)) {
113
+ for (const stats of record.backendStats) {
114
+ lines.push(`[${stats.backend}] ${stats.ok ? 'OK' : 'FAILED'}; attempts=${stats.attempts}; sourceCount=${stats.sourceCount} (before filtering and deduplication).`);
115
+ }
116
+ }
103
117
  if (typeof record.report === 'string' && record.report !== '')
104
118
  lines.push(record.report);
105
119
  for (const source of record.sources) {
106
- lines.push(`- ${source.title ?? source.url ?? ''} <${source.url ?? ''}>`);
120
+ const provenance = source.backends?.length ? ` [backends: ${source.backends.join(', ')}]` : '';
121
+ lines.push(`- ${source.title ?? source.url ?? ''} <${source.url ?? ''}>${provenance}`);
107
122
  }
108
123
  return lines.join('\n') || 'No sources returned.';
109
124
  }
package/dist/tools.js CHANGED
@@ -56,7 +56,7 @@ export function createTools(config, identity, engine, readers = { reddit: fetchR
56
56
  };
57
57
  const searchTool = {
58
58
  name: 'web_search',
59
- description: 'Search the web through the enabled backends and return citeable sources. The backends array is the whole strategy: one id runs that backend alone, several ids run in parallel, allBackends with exclude is the same choice written as a set, and leaving it out runs every enabled backend. Failures are named instead of being hidden behind an empty result, and the response reports every request that failed. Nothing falls back to another backend, access mode or credential.',
59
+ description: 'Search the web through the enabled backends and return citeable sources. The backends array is the whole strategy: one id runs that backend alone, several ids run in parallel, allBackends with exclude is the same choice written as a set, and leaving it out runs every enabled backend. Failures are named instead of being hidden behind an empty result, and the response reports every request that failed. Nothing falls back to another backend, access mode or credential. The response distinguishes enabled, requested, selected and executed backends, reports cache hits and per-backend statistics, and each merged source carries a backends array naming every backend that found it.',
60
60
  inputSchema: {
61
61
  type: 'object',
62
62
  properties: {
@@ -83,11 +83,25 @@ export function createTools(config, identity, engine, readers = { reddit: fetchR
83
83
  ...(int(args.maxResults) !== undefined ? { maxResults: int(args.maxResults) } : {}),
84
84
  };
85
85
  const result = await search.search({ query }, signal, undefined, overrides);
86
+ const selectedBackends = result.outcomes.map(outcome => outcome.backend);
86
87
  return {
87
88
  sources: result.sources,
88
89
  truncated: result.truncated,
89
90
  report: result.content,
90
- backends: enabledBackendIds(config),
91
+ enabledBackends: enabledBackendIds(config),
92
+ requestedBackends: overrides.backends ?? 'all',
93
+ selectedBackends,
94
+ // A selected backend can fail before sending a request; cache hits send none at all.
95
+ executedBackends: result.cached ? [] : result.outcomes.filter(outcome => outcome.attempts > 0).map(outcome => outcome.backend),
96
+ backends: selectedBackends,
97
+ cached: result.cached,
98
+ backendStats: result.outcomes.map(outcome => ({
99
+ backend: outcome.backend,
100
+ ok: outcome.ok,
101
+ attempts: result.cached ? 0 : outcome.attempts,
102
+ sourceCount: outcome.sources.length,
103
+ ...(outcome.error ? { error: outcome.error } : {}),
104
+ })),
91
105
  };
92
106
  },
93
107
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nite07/websearch-mcp",
3
- "version": "0.2.3",
3
+ "version": "0.2.4",
4
4
  "description": "MCP server for multi-backend web search plus Reddit and X thread reading, built on @nite07/search-core.",
5
5
  "license": "MIT",
6
6
  "author": "nite07",
@@ -43,7 +43,7 @@
43
43
  },
44
44
  "dependencies": {
45
45
  "@modelcontextprotocol/server": "^2.4.0",
46
- "@nite07/search-core": "0.2.1"
46
+ "@nite07/search-core": "0.2.2"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@types/node": "^22.10.2",