@nite07/websearch-mcp 0.2.3 → 0.2.5

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
@@ -21,175 +21,114 @@ run is the caller's decision: one id in `backends` runs one backend, several run
21
21
 
22
22
  ```sh
23
23
  npm install -g @nite07/websearch-mcp
24
+ mkdir -p ~/.config/websearch-mcp
24
25
  websearch-mcp --print-config > ~/.config/websearch-mcp/config.json
25
26
  ```
26
27
 
27
- `--print-config` writes a complete, valid configuration with every backend disabled except Keenable
28
- and Reddit, which need no account.
28
+ This creates the initial settings with Keenable and Reddit enabled; neither needs an account.
29
+ You do not need to edit the generated file. Use the settings page or ask your agent to make changes.
30
+
31
+ ## Connect your MCP client
32
+
33
+ Add a **stdio** MCP server in your client's MCP settings:
34
+
35
+ | Field | Value |
36
+ | --- | --- |
37
+ | Name | `websearch` |
38
+ | Command | `websearch-mcp` |
39
+ | Arguments | None |
40
+
41
+ The command must be available to the client. If it cannot find it, use the full path to the installed
42
+ executable. Clients that only accept a configuration file have their own setup format; follow that
43
+ client's instructions for adding a stdio server.
29
44
 
30
45
  ## First search
31
46
 
32
- 1. Open `~/.config/websearch-mcp/config.json`.
33
- 2. Under `search.backends`, set `"enabled": true` on the providers you want. Anonymous tiers —
34
- Keenable, Exa, You.com, AnySearch, Parallel, Reddit — need nothing else.
35
- 3. Register the server with your MCP client (next section).
36
- 4. Ask the client to search. To see what is available without spending anything, call
37
- `list_backends` first: it reports each backend's modes, cost tier, enabled state and whether a
38
- credential is present. It never enables anything.
47
+ Ask your agent to search using the default backends, or ask it to list the available providers first.
48
+ For example: “Search for recent self-hosting news using Keenable and Reddit.”
39
49
 
40
- ## Settings page
50
+ To choose providers, check costs or change search preferences, use the settings page below or ask the agent to
51
+ manage the settings for you. There is no need to write configuration by hand.
41
52
 
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:
53
+ ## Search results
45
54
 
46
- ```sh
47
- WEBSEARCH_MCP_UI_PORT=7799 WEBSEARCH_MCP_UI_TOKEN=... websearch-mcp # stdio client + page
48
- ```
55
+ Each result names the backends that found it, including multiple sources for the same page.
56
+ The response also shows which backends were used and whether it came from the cache.
49
57
 
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:
58
+ ## Settings page
59
+
60
+ Use the settings page to choose backends, check costs, enter credentials and test your setup:
76
61
 
77
62
  ```sh
78
- websearch-mcp --ui --host 0.0.0.0 --port 7799 --print-url # --print-url prints the links and exits
63
+ WEBSEARCH_MCP_UI_PORT=7799 WEBSEARCH_MCP_UI_TOKEN=replace-with-a-long-random-token websearch-mcp
79
64
  ```
80
65
 
81
- ## Client configuration
82
-
83
- ```json
84
- {
85
- "mcpServers": {
86
- "websearch": {
87
- "command": "websearch-mcp",
88
- "env": { "WEBSEARCH_MCP_CONFIG": "/home/you/.config/websearch-mcp/config.json" }
89
- }
90
- }
91
- }
92
- ```
66
+ Open `http://127.0.0.1:7799/?token=replace-with-a-long-random-token`. The page is available while the MCP server is running.
67
+ Set `WEBSEARCH_MCP_UI_HOST` if you need a different bind address. Without a token, the page is open;
68
+ set one before exposing it beyond your machine.
93
69
 
94
- `--config <path>` works too when you would rather pass the file explicitly. Without either, the
95
- server reads `~/.config/websearch-mcp/config.json`.
70
+ The page has sections for search, reliability, diagnostics, backends, browser setup and page fetching.
71
+ Saved changes take effect on the next call, without restarting the server. Invalid changes are
72
+ rejected; recent configuration backups are kept automatically.
96
73
 
97
- ## Credentials
74
+ To run only the settings page:
98
75
 
99
- Credential names are fixed by search-core, not configuration fields: a backend id is uppercased with
100
- hyphens turned into underscores, then suffixed with `_KEY`. So Brave is `DSH_SEARCH_BRAVE_KEY` and
101
- Zhihu site search is `DSH_SEARCH_ZHIHU_SITE_KEY`.
102
-
103
- Put them where your client can see them:
104
-
105
- ```json
106
- {
107
- "mcpServers": {
108
- "websearch": {
109
- "command": "websearch-mcp",
110
- "env": {
111
- "WEBSEARCH_MCP_CONFIG": "/home/you/.config/websearch-mcp/config.json",
112
- "DSH_SEARCH_BRAVE_KEY": "…"
113
- }
114
- }
115
- }
116
- }
76
+ ```sh
77
+ websearch-mcp --ui --port 7799 --token replace-with-a-long-random-token
117
78
  ```
118
79
 
119
- 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.
80
+ ## Credentials
81
+
82
+ Enter a provider's API key or account credential on its card in the settings page and save.
83
+ You can also authorize the agent to set or remove a credential with `search_manage`.
84
+ Credential values are never returned by that tool. Do not paste secrets into a shared conversation.
122
85
 
123
86
  ## Browser-backed search
124
87
 
125
- Xiaohongshu answers only its own page runtime, so it reads through a browser container you host. Start
126
- it from [packages/core/image](../core/image/README.md), sign in over VNC, then point the server at it:
127
-
128
- ```json
129
- {
130
- "search": {
131
- "browser": {
132
- "endpoint": "ws://127.0.0.1:3000/ws",
133
- "statePath": "/path/to/search-browser/data/state.json",
134
- "timeoutMs": 60000,
135
- "maxConcurrentReads": 2
136
- },
137
- "backends": {
138
- "xiaohongshu": { "enabled": true, "mode": "browser" }
139
- }
140
- }
141
- }
142
- ```
88
+ Xiaohongshu search and note reading need a browser container:
143
89
 
144
- 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.
90
+ 1. Start the [browser container](../core/image/README.md) and sign in to Xiaohongshu over VNC.
91
+ 2. In the settings page's **Browser** section, enter the endpoint and endpoint token shown by the
92
+ container. If you use a saved session file, enter its path there too.
93
+ 3. Enable Xiaohongshu in browser mode in **Backends** and save.
148
94
 
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.
95
+ Then ask your agent to search Xiaohongshu or read a full share link copied from the app.
152
96
 
153
97
  ## Tools
154
98
 
155
99
  | Tool | What it does |
156
100
  | --- | --- |
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.
101
+ | `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. |
102
+ | `reddit_thread` | Read a Reddit post, comments and pictures. |
103
+ | `x_thread` | Read an X post, replies and pictures. Requires the X backend in session mode. |
104
+ | `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. |
105
+ | `list_backends` | List available backends, access modes, costs, enabled state and credential readiness. |
106
+ | `search_manage` | Inspect or change settings and credentials, test a backend, or test page fetching. |
107
+ | `web_extract` | Read one page as Markdown or HTML. Disabled by default; enable it in **Page fetch**. |
168
108
 
169
- ## Page fetching
109
+ `compact: true` omits snippets while keeping links, titles, dates and backend provenance.
170
110
 
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.
111
+ The former `read_thread` tool has been replaced by `reddit_thread` and `x_thread`; update existing
112
+ calls to use the platform's tool without a `source` argument.
175
113
 
176
- ```sh
177
- websearch-mcp --print-config > ~/.config/websearch-mcp/config.json # includes pageFetch and tools.webExtract
178
- ```
114
+ ## Agent settings management
115
+
116
+ Ask the agent to use `search_manage` to view settings, change backends or page-fetch options, and
117
+ set or remove credentials. It can also test a saved backend or page-fetch setup. Credential values
118
+ are never returned. Changes take effect without restarting the MCP server.
179
119
 
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.
120
+ For example: “Show me the available free backends, enable Keenable, and save.”
121
+ Tests make real requests and may incur charges. Configuration changes, credential changes and tests
122
+ require your authorization.
123
+
124
+ ## Page fetching
186
125
 
187
- ## Protocol versions
126
+ Enable **web_extract** in the settings page's **Page fetch** section, or ask the agent to enable it.
127
+ Then ask it to read a URL as Markdown, or return HTML when you need the page structure.
188
128
 
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.
129
+ Browser support is available for JavaScript pages. You can choose a fetch provider on the same page;
130
+ check its supported formats and costs, and supply an API key if required. Public URLs are allowed by
131
+ default.
193
132
 
194
133
  ## Behaviour worth relying on
195
134
 
@@ -199,20 +138,17 @@ The wire protocol is the [official TypeScript SDK](https://ts.sdk.modelcontextpr
199
138
  not; total failures say the search failed. Failed calls are never cached.
200
139
  - **Per-call strategy, saved config untouched.** `backends`, `exclude` and `compact` apply to that one
201
140
  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.
141
+ - **Reddit is anonymous by default.** No account is needed.
142
+ - **X discussions include replies.** Use session mode with valid account cookies.
207
143
 
208
144
  ## Troubleshooting
209
145
 
210
146
  | Symptom | Cause and fix |
211
147
  | --- | --- |
212
- | The client shows no tools | The server failed to start. Run `websearch-mcp --config <path>` by hand and read the error. |
213
- | Every search fails | No backend is enabled. Call `list_backends`, then enable one and restart the client. |
214
- | A keyed backend reports a missing credential | The environment variable is named after the backend id. Check the exact name with `list_backends`. |
215
- | Xiaohongshu reports no endpoint | `search.browser.endpoint` is empty and the backend has none. |
148
+ | The client shows no tools | The server failed to start. Run `websearch-mcp` in a terminal and read the startup error. |
149
+ | Every search fails | No backend is enabled. Enable one in the settings page or ask the agent to enable it, then retry. |
150
+ | A keyed backend reports a missing credential | Enter the credential on the provider card, or authorize the agent to set it. |
151
+ | Xiaohongshu reports no endpoint | Fill in the endpoint in the settings page’s Browser section. |
216
152
  | Xiaohongshu reports not signed in | The container's session expired. Sign in again over VNC; the next read reloads the state file. |
217
153
 
218
154
  ## Development
package/README.zh.md CHANGED
@@ -15,156 +15,124 @@
15
15
 
16
16
  ```sh
17
17
  npm install -g @nite07/websearch-mcp
18
+ mkdir -p ~/.config/websearch-mcp
18
19
  websearch-mcp --print-config > ~/.config/websearch-mcp/config.json
19
20
  ```
20
21
 
21
- `--print-config` 生成一份完整且合法的配置,除了 Keenable 和 Reddit(这两家不需要账号)之外全部关闭。
22
+ 这会生成初始设置,默认启用无需账号的 Keenable 和 Reddit。无需编辑生成的文件,后续在 Web UI 中操作,或让 Agent 帮你修改即可。
23
+
24
+ ## 接入 MCP 客户端
25
+
26
+ 在客户端的 MCP 设置中添加一个 **stdio** 服务:
27
+
28
+ | 字段 | 填写内容 |
29
+ | --- | --- |
30
+ | 名称 | `websearch` |
31
+ | 命令 | `websearch-mcp` |
32
+ | 参数 | 留空 |
33
+
34
+ 客户端需要能找到该命令;找不到时,填安装后的可执行文件完整路径。如果客户端只接受配置文件,
35
+ 按该客户端的说明添加 stdio 服务即可。
22
36
 
23
37
  ## 第一次搜索
24
38
 
25
- 1. 打开 `~/.config/websearch-mcp/config.json`
26
- 2. 在 `search.backends` 里把想用的那几家改成 `"enabled": true`。匿名档的 Keenable、Exa、You.com、AnySearch、Parallel、Reddit 不需要额外配置
27
- 3. 按下一节把服务注册到你的 MCP 客户端
28
- 4. 让客户端搜点东西
39
+ 让 Agent 使用默认后端搜索,也可以先让它列出可用服务商。例如:
29
40
 
30
- 想先看看有什么可用又不花钱,调 `list_backends`:它列出每个后端的模式、费用档、启用状态以及有没有凭证,但不会启用任何东西。
41
+ > 用 Keenable 和 Reddit 搜一下最近的自托管新闻。
31
42
 
32
- ## 配置页面
43
+ 想更换后端、查看费用或调整搜索偏好,可以使用下面的 Web UI,或直接让 Agent 操作,无需手写配置。
33
44
 
34
- 配置有页面了:每个后端的接入模式、成本档位、选项与凭证都在同一张表里,每张卡片带一个实测按钮。
35
- **这个页面由 MCP 服务器自己提供**——一个进程,不需要额外的单元、容器或端口转发:
45
+ ## 搜索结果
36
46
 
37
- ```sh
38
- WEBSEARCH_MCP_UI_PORT=7799 WEBSEARCH_MCP_UI_TOKEN=... websearch-mcp # stdio 服务 + 页面
39
- ```
47
+ 每条结果都会标注找到它的后端,同一页面可以保留多个来源。响应还会说明本次使用了哪些后端,
48
+ 以及是否命中缓存。
49
+
50
+ ## 配置页面
40
51
 
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 客户端、只想看一眼页面:
52
+ 在配置页面选择后端、查看费用、填写凭证,也可以直接测试是否可用:
56
53
 
57
54
  ```sh
58
- websearch-mcp --ui --host 0.0.0.0 --port 7799 --print-url # --print-url 只打印链接
55
+ WEBSEARCH_MCP_UI_PORT=7799 WEBSEARCH_MCP_UI_TOKEN=replace-with-a-long-random-token websearch-mcp
59
56
  ```
60
57
 
61
- ## 客户端配置
62
-
63
- ```json
64
- {
65
- "mcpServers": {
66
- "websearch": {
67
- "command": "websearch-mcp",
68
- "env": { "WEBSEARCH_MCP_CONFIG": "/home/you/.config/websearch-mcp/config.json" }
69
- }
70
- }
71
- }
72
- ```
58
+ 打开 `http://127.0.0.1:7799/?token=replace-with-a-long-random-token`,页面会随 MCP 服务一起运行。
59
+ 需要更改监听地址时设置 `WEBSEARCH_MCP_UI_HOST`。不设令牌时页面无需登录,向本机以外开放前请设置令牌。
73
60
 
74
- 想显式指定文件时也可以用 `--config <path>`。两者都没有时,服务读取 `~/.config/websearch-mcp/config.json`。
61
+ 页面分为搜索、可靠性、诊断、后端、浏览器和页面抓取几个部分。保存后下一次调用即使用新配置,
62
+ 无需重启服务;无效配置不会保存,近期配置会自动备份。
75
63
 
76
- ## 凭证
64
+ 只运行配置页面:
77
65
 
78
- 凭证名字由 search-core 固定,不是配置项:后端 id 转大写、连字符换下划线,再加 `_KEY`。Brave 是 `DSH_SEARCH_BRAVE_KEY`,知乎站内是 `DSH_SEARCH_ZHIHU_SITE_KEY`。
79
-
80
- 放到客户端能看到的地方:
81
-
82
- ```json
83
- {
84
- "mcpServers": {
85
- "websearch": {
86
- "command": "websearch-mcp",
87
- "env": {
88
- "WEBSEARCH_MCP_CONFIG": "/home/you/.config/websearch-mcp/config.json",
89
- "DSH_SEARCH_BRAVE_KEY": "…"
90
- }
91
- }
92
- }
93
- }
66
+ ```sh
67
+ websearch-mcp --ui --port 7799 --token replace-with-a-long-random-token
94
68
  ```
95
69
 
96
- 环境变量没有时,可以用配置文件里的 `credentials.<后端-id>` 直接写值。值是字面字符串,`${...}` 不会被展开。加载时保存的 `credentialRef` 字段会被丢弃,配置文件没办法把查询指到别的密钥上。
70
+ ## 凭证
71
+
72
+ 在 Web UI 的服务商卡片中填写 API Key 或账号凭证并保存,也可以授权 Agent 通过 `search_manage`
73
+ 设置或清除凭证。该工具不会返回凭证值。不要把密钥粘贴到共享对话中。
97
74
 
98
75
  ## 需要浏览器的搜索
99
76
 
100
- 小红书只认自己的页面运行时,所以它走你自己托管的浏览器容器。按 [packages/core/image](../core/image/README.zh.md) 起容器、在 VNC 里登录,然后把它配进来:
101
-
102
- ```json
103
- {
104
- "search": {
105
- "browser": {
106
- "endpoint": "ws://127.0.0.1:3000/ws",
107
- "statePath": "/path/to/search-browser/data/state.json",
108
- "timeoutMs": 60000,
109
- "maxConcurrentReads": 2
110
- },
111
- "backends": {
112
- "xiaohongshu": { "enabled": true, "mode": "browser" }
113
- }
114
- }
115
- }
116
- ```
77
+ 小红书搜索和笔记读取需要浏览器容器:
78
+
79
+ 1. 按[浏览器容器说明](../core/image/README.zh.md)启动容器,在 VNC 中登录小红书。
80
+ 2. 在 Web UI 的「浏览器」部分填写容器提供的端点和端点令牌;使用登录态文件时,也在这里填写路径。
81
+ 3. 在「后端」中启用小红书的 browser 模式并保存。
117
82
 
118
- 端点令牌写在 `DSH_SEARCH_BROWSER_TOKEN`,或者文件里的 `credentials.browser`。`maxConcurrentReads`(1–8)限制同一个站点上同时跑几个读取,默认值是保守的本地取值,不代表站点额度。`statePath` 必须是容器写的那个文件,否则每次读回来都是未登录。只要端点配好就能搜索;读笔记走的是同一个浏览器,所以后端必须启用为 browser 模式,`xiaohongshu_note` 吃 App 里复制的分享链接(里面带着读取要用的 token),或者之前搜索返回的笔记 id。
83
+ 随后就可以让 Agent 搜索小红书,或读取从 App 复制的完整分享链接。
119
84
 
120
85
  ## 工具
121
86
 
122
87
  | 工具 | 做什么 |
123
88
  | --- | --- |
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` | 列出每个后端的模式、费用档、启用状态和凭证是否就位。不会启用任何东西。 |
89
+ | `web_search` | 搜索指定后端。必填 `query`,可选 `backends`、`allBackends`、`exclude`、`compact`、`maxResults`。只指定一个后端就只搜这一家,不指定则搜索所有已启用后端。 |
90
+ | `reddit_thread` | 读取 Reddit 帖子、评论和配图。 |
91
+ | `x_thread` | 读取 X 帖子、回复和配图,需要 X 后端处于会话模式。 |
92
+ | `xiaohongshu_note` | 读取笔记正文、作者、互动数据、标签和配图,可选读取评论。需要启用小红书后端的 browser 模式并配置浏览器。 |
93
+ | `list_backends` | 查看后端、接入模式、费用、启用状态和凭证是否就绪。 |
94
+ | `search_manage` | 查看或修改设置与凭证,测试后端或页面抓取。 |
95
+ | `web_extract` | 读取单个网页,返回 Markdown 或 HTML。默认关闭,在「页面抓取」中启用。 |
128
96
 
129
- `compact: true` 只回 URL、标题和日期,通常就是一个还能用的上下文和一个被灌满的上下文的区别。
97
+ `compact: true` 不返回摘要,保留链接、标题、日期和来源后端。
130
98
 
131
- ## 页面抓取
99
+ 原 `read_thread` 已由 `reddit_thread` 和 `x_thread` 替代,已有调用请改用对应平台的工具,不再传入 `source`。
132
100
 
133
- 页面抓取与 DSH 插件共用同一个 core 引擎:有序路由(HTTP、共享浏览器、一个选定服务商)、按路由配置的
134
- 回退规则(三值条件),输出 HTML 或 Markdown。`search.tools.webExtract` 默认 `false`;关闭时工具不会
135
- 出现在 `tools/list` 里,而配置、凭证、设置页与库 API 仍然可用。
101
+ ## 让 Agent 管理设置
136
102
 
137
- ```sh
138
- websearch-mcp --print-config > ~/.config/websearch-mcp/config.json # 含 pageFetch 与 tools.webExtract
139
- ```
103
+ 可以让 Agent 用 `search_manage` 查看设置、调整后端或页面抓取选项、设置或清除凭证,
104
+ 也可以测试已保存的后端与抓取配置。工具不会返回凭证值,修改后无需重启 MCP 服务。
105
+
106
+ 例如:
140
107
 
141
- 默认只抓公网目标,HTTP 传输会把连接绑定到策略校验过的地址;重定向逐跳跟随。浏览器或服务商在别处解析
142
- 目标地址,所以必须显式打开 `pageFetch.allowDelegatedFetching`,结果里会写明这个信任边界。两个内置抓取
143
- 服务商都只返回原生 Markdown,因此 `format: "html"` 由 HTTP 或浏览器路由提供,只支持 Markdown 的服务商
144
- 会在不发请求的情况下被跳过。
108
+ > 帮我看看有哪些免费后端,启用 Keenable 并保存。
109
+
110
+ 测试会发出真实请求,可能产生费用。修改配置、凭证或运行测试前,都需要你的授权。
111
+
112
+ ## 页面抓取
145
113
 
146
- ## 协议版本
114
+ 在 Web UI 的「页面抓取」中启用 **web_extract**,或让 Agent 帮你启用。
115
+ 随后让它读取指定网页,返回 Markdown;需要查看页面结构时,可以要求返回 HTML。
147
116
 
148
- 线上协议交给[官方 TypeScript SDK](https://ts.sdk.modelcontextprotocol.io/v2/)
149
- (`@modelcontextprotocol/server`),不是手写循环:服务端会说无状态的 `2026-07-28`,对仍在用
150
- `initialize` 开场的客户端回退到 2025 握手。协议改版因此是升依赖,不是重写连接层。
117
+ 支持读取需要 JavaScript 的页面,也可以在同一页面选择抓取服务商。使用前请查看支持的格式和费用,
118
+ 需要 API Key 的模式先填写凭证。默认只允许公网地址。
151
119
 
152
120
  ## 可以依赖的行为
153
121
 
154
122
  - **不切换。** 后端只按你选定的模式、你给的凭证、配置里的端点工作。重试不会换服务商、不会换模式。
155
123
  - **失败看得见。** 部分失败返回成功的那部分并点名失败的;全部失败就说搜索失败。失败的调用不会进缓存。
156
- - **单次策略不动配置。** `mode`、`backends`、`compact` 只作用这一次,所以窄查询和广撒网可以并存,不用来回改文件。
157
- - **Reddit 默认匿名。** 不需要账号,用的就是安卓客户端拿的那种匿名 token——Reddit 的公开 REST 搜索对匿名调用一律 403。
158
- - **X 的帖子按站点自己的方式读。** 适配层读页面里内嵌的那个接口再直接调用,前端发版不会失效,也不需要自己签 transaction id。
124
+ - **单次策略不动配置。** `backends`、`exclude`、`compact` 只作用这一次,所以窄查询和广撒网可以并存,不用来回改文件。
125
+ - **Reddit 默认匿名。** 不需要账号。
126
+ - **X 讨论支持读取回复。** 需要使用会话模式,并提供有效的账号 Cookie。
159
127
 
160
128
  ## 常见问题
161
129
 
162
130
  | 现象 | 原因与处理 |
163
131
  | --- | --- |
164
- | 客户端里看不到工具 | 服务没起来。手动跑一次 `websearch-mcp --config <path>` 看报错。 |
165
- | 每次搜索都失败 | 没有启用任何后端。先调 `list_backends`,启用一家,再重启客户端。 |
166
- | 某个要 Key 的后端报缺凭证 | 环境变量名是按后端 id 生成的,用 `list_backends` 核对准确名字。 |
167
- | 小红书报没有端点 | `search.browser.endpoint` 是空的,后端自己也没配端点。 |
132
+ | 客户端里看不到工具 | 服务没起来。在终端运行 `websearch-mcp` 查看启动报错。 |
133
+ | 每次搜索都失败 | 没有启用任何后端。在 Web UI 中启用一家,或让 Agent 帮你启用,再重试。 |
134
+ | 某个要 Key 的后端报缺凭证 | 在服务商卡片中填写凭证,或授权 Agent 设置。 |
135
+ | 小红书报没有端点 | 在 Web UI 的「浏览器」部分填写端点。 |
168
136
  | 小红书报未登录 | 容器的登录态过期了。去 VNC 里重新登录,下次读取会重新加载会话文件。 |
169
137
 
170
138
  ## 开发
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.5",
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",