@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 +79 -143
- package/README.zh.md +72 -104
- package/dist/sdk.js +16 -1
- package/dist/tools.js +16 -2
- package/package.json +2 -2
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
|
-
|
|
28
|
-
|
|
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
|
-
|
|
33
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
47
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
63
|
+
WEBSEARCH_MCP_UI_PORT=7799 WEBSEARCH_MCP_UI_TOKEN=replace-with-a-long-random-token websearch-mcp
|
|
79
64
|
```
|
|
80
65
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
|
|
95
|
-
server
|
|
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
|
-
|
|
74
|
+
To run only the settings page:
|
|
98
75
|
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
|
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
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
-
|
|
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
|
|
158
|
-
| `
|
|
159
|
-
| `
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
or
|
|
163
|
-
| `
|
|
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
|
-
|
|
109
|
+
`compact: true` omits snippets while keeping links, titles, dates and backend provenance.
|
|
170
110
|
|
|
171
|
-
|
|
172
|
-
|
|
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
|
-
|
|
177
|
-
|
|
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
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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
|
-
|
|
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
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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
|
|
203
|
-
|
|
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
|
|
213
|
-
| Every search fails | No backend is enabled.
|
|
214
|
-
| A keyed backend reports a missing credential |
|
|
215
|
-
| Xiaohongshu reports no endpoint |
|
|
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
|
-
|
|
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
|
-
|
|
26
|
-
2. 在 `search.backends` 里把想用的那几家改成 `"enabled": true`。匿名档的 Keenable、Exa、You.com、AnySearch、Parallel、Reddit 不需要额外配置
|
|
27
|
-
3. 按下一节把服务注册到你的 MCP 客户端
|
|
28
|
-
4. 让客户端搜点东西
|
|
39
|
+
让 Agent 使用默认后端搜索,也可以先让它列出可用服务商。例如:
|
|
29
40
|
|
|
30
|
-
|
|
41
|
+
> 用 Keenable 和 Reddit 搜一下最近的自托管新闻。
|
|
31
42
|
|
|
32
|
-
|
|
43
|
+
想更换后端、查看费用或调整搜索偏好,可以使用下面的 Web UI,或直接让 Agent 操作,无需手写配置。
|
|
33
44
|
|
|
34
|
-
|
|
35
|
-
**这个页面由 MCP 服务器自己提供**——一个进程,不需要额外的单元、容器或端口转发:
|
|
45
|
+
## 搜索结果
|
|
36
46
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
47
|
+
每条结果都会标注找到它的后端,同一页面可以保留多个来源。响应还会说明本次使用了哪些后端,
|
|
48
|
+
以及是否命中缓存。
|
|
49
|
+
|
|
50
|
+
## 配置页面
|
|
40
51
|
|
|
41
|
-
|
|
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
|
-
|
|
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
|
-
|
|
61
|
+
页面分为搜索、可靠性、诊断、后端、浏览器和页面抓取几个部分。保存后下一次调用即使用新配置,
|
|
62
|
+
无需重启服务;无效配置不会保存,近期配置会自动备份。
|
|
75
63
|
|
|
76
|
-
|
|
64
|
+
只运行配置页面:
|
|
77
65
|
|
|
78
|
-
|
|
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
|
-
|
|
70
|
+
## 凭证
|
|
71
|
+
|
|
72
|
+
在 Web UI 的服务商卡片中填写 API Key 或账号凭证并保存,也可以授权 Agent 通过 `search_manage`
|
|
73
|
+
设置或清除凭证。该工具不会返回凭证值。不要把密钥粘贴到共享对话中。
|
|
97
74
|
|
|
98
75
|
## 需要浏览器的搜索
|
|
99
76
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
|
|
83
|
+
随后就可以让 Agent 搜索小红书,或读取从 App 复制的完整分享链接。
|
|
119
84
|
|
|
120
85
|
## 工具
|
|
121
86
|
|
|
122
87
|
| 工具 | 做什么 |
|
|
123
88
|
| --- | --- |
|
|
124
|
-
| `web_search` |
|
|
125
|
-
| `
|
|
126
|
-
| `
|
|
127
|
-
| `
|
|
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`
|
|
97
|
+
`compact: true` 不返回摘要,保留链接、标题、日期和来源后端。
|
|
130
98
|
|
|
131
|
-
|
|
99
|
+
原 `read_thread` 已由 `reddit_thread` 和 `x_thread` 替代,已有调用请改用对应平台的工具,不再传入 `source`。
|
|
132
100
|
|
|
133
|
-
|
|
134
|
-
回退规则(三值条件),输出 HTML 或 Markdown。`search.tools.webExtract` 默认 `false`;关闭时工具不会
|
|
135
|
-
出现在 `tools/list` 里,而配置、凭证、设置页与库 API 仍然可用。
|
|
101
|
+
## 让 Agent 管理设置
|
|
136
102
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
103
|
+
可以让 Agent 用 `search_manage` 查看设置、调整后端或页面抓取选项、设置或清除凭证,
|
|
104
|
+
也可以测试已保存的后端与抓取配置。工具不会返回凭证值,修改后无需重启 MCP 服务。
|
|
105
|
+
|
|
106
|
+
例如:
|
|
140
107
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
108
|
+
> 帮我看看有哪些免费后端,启用 Keenable 并保存。
|
|
109
|
+
|
|
110
|
+
测试会发出真实请求,可能产生费用。修改配置、凭证或运行测试前,都需要你的授权。
|
|
111
|
+
|
|
112
|
+
## 页面抓取
|
|
145
113
|
|
|
146
|
-
|
|
114
|
+
在 Web UI 的「页面抓取」中启用 **web_extract**,或让 Agent 帮你启用。
|
|
115
|
+
随后让它读取指定网页,返回 Markdown;需要查看页面结构时,可以要求返回 HTML。
|
|
147
116
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
`initialize` 开场的客户端回退到 2025 握手。协议改版因此是升依赖,不是重写连接层。
|
|
117
|
+
支持读取需要 JavaScript 的页面,也可以在同一页面选择抓取服务商。使用前请查看支持的格式和费用,
|
|
118
|
+
需要 API Key 的模式先填写凭证。默认只允许公网地址。
|
|
151
119
|
|
|
152
120
|
## 可以依赖的行为
|
|
153
121
|
|
|
154
122
|
- **不切换。** 后端只按你选定的模式、你给的凭证、配置里的端点工作。重试不会换服务商、不会换模式。
|
|
155
123
|
- **失败看得见。** 部分失败返回成功的那部分并点名失败的;全部失败就说搜索失败。失败的调用不会进缓存。
|
|
156
|
-
- **单次策略不动配置。** `
|
|
157
|
-
- **Reddit 默认匿名。**
|
|
158
|
-
- **X
|
|
124
|
+
- **单次策略不动配置。** `backends`、`exclude`、`compact` 只作用这一次,所以窄查询和广撒网可以并存,不用来回改文件。
|
|
125
|
+
- **Reddit 默认匿名。** 不需要账号。
|
|
126
|
+
- **X 讨论支持读取回复。** 需要使用会话模式,并提供有效的账号 Cookie。
|
|
159
127
|
|
|
160
128
|
## 常见问题
|
|
161
129
|
|
|
162
130
|
| 现象 | 原因与处理 |
|
|
163
131
|
| --- | --- |
|
|
164
|
-
| 客户端里看不到工具 |
|
|
165
|
-
| 每次搜索都失败 |
|
|
166
|
-
| 某个要 Key 的后端报缺凭证 |
|
|
167
|
-
| 小红书报没有端点 |
|
|
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
|
-
|
|
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
|
-
|
|
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
|
+
"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.
|
|
46
|
+
"@nite07/search-core": "0.2.2"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@types/node": "^22.10.2",
|