@nite07/websearch-mcp 0.1.3 → 0.2.0
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 +147 -39
- package/README.zh.md +161 -0
- package/dist/live.d.ts +21 -0
- package/dist/live.js +52 -0
- package/dist/main.js +217 -37
- package/dist/sdk.d.ts +21 -0
- package/dist/sdk.js +88 -0
- package/dist/tools.d.ts +8 -2
- package/dist/tools.js +91 -7
- package/dist/ui/embedded.d.ts +20 -0
- package/dist/ui/embedded.js +14 -0
- package/dist/ui/page.d.ts +2 -0
- package/dist/ui/page.html +694 -0
- package/dist/ui/page.js +15 -0
- package/dist/ui/server.d.ts +21 -0
- package/dist/ui/server.js +243 -0
- package/dist/ui/session.d.ts +38 -0
- package/dist/ui/session.js +111 -0
- package/dist/ui/state.d.ts +62 -0
- package/dist/ui/state.js +256 -0
- package/dist/ui/token.d.ts +23 -0
- package/dist/ui/token.js +23 -0
- package/package.json +4 -3
- package/dist/protocol.d.ts +0 -19
- package/dist/protocol.js +0 -125
package/README.md
CHANGED
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
# websearch-mcp
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
English | [中文](README.zh.md)
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@nite07/websearch-mcp)
|
|
6
|
+
[](https://www.npmjs.com/package/@nite07/websearch-mcp)
|
|
7
|
+
|
|
8
|
+
An MCP server for multi-backend web search, plus discussion reading for Reddit and X and note reading
|
|
9
|
+
for Xiaohongshu. Works with any
|
|
10
|
+
MCP client: Claude Code, Codex, DeepSeek Harness, or your own.
|
|
6
11
|
|
|
7
12
|
## Why another search server
|
|
8
13
|
|
|
9
14
|
Most MCP search servers pick a provider for you and hide what happens when it fails. This one does the
|
|
10
15
|
opposite: every backend has an explicit access mode, every access mode carries a cost tier, and a
|
|
11
|
-
failure comes back named instead of as an empty result. The model can also steer
|
|
12
|
-
or single, which backends, how much of each source — so a cheap lookup does not cost the same
|
|
13
|
-
broad sweep.
|
|
16
|
+
failure comes back named instead of as an empty result. The model can also steer a single call —
|
|
17
|
+
parallel or single, which backends, how much of each source — so a cheap lookup does not cost the same
|
|
18
|
+
as a broad sweep.
|
|
14
19
|
|
|
15
20
|
## Install
|
|
16
21
|
|
|
@@ -19,24 +24,54 @@ npm install -g @nite07/websearch-mcp
|
|
|
19
24
|
websearch-mcp --print-config > ~/.config/websearch-mcp/config.json
|
|
20
25
|
```
|
|
21
26
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
27
|
+
`--print-config` writes a complete, valid configuration with every backend disabled except Keenable
|
|
28
|
+
and Reddit, which need no account.
|
|
29
|
+
|
|
30
|
+
## First search
|
|
31
|
+
|
|
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.
|
|
39
|
+
|
|
40
|
+
## Settings page
|
|
41
|
+
|
|
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:
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
WEBSEARCH_MCP_UI_PORT=7799 WEBSEARCH_MCP_UI_TOKEN=... websearch-mcp # stdio client + page
|
|
48
|
+
```
|
|
49
|
+
|
|
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
|
+
- A file that stops parsing keeps the previous configuration and says why on stderr.
|
|
66
|
+
- When a `config.container.json` sits beside the file, every save rewrites it too: loopback endpoints
|
|
67
|
+
become `host.containers.internal`, and the browser session file is mapped into `/host/home`. The
|
|
68
|
+
companion is never created on its own.
|
|
69
|
+
|
|
70
|
+
Page without an MCP client, for a quick look:
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
websearch-mcp --ui --host 0.0.0.0 --port 7799 --print-url # --print-url prints the links and exits
|
|
74
|
+
```
|
|
40
75
|
|
|
41
76
|
## Client configuration
|
|
42
77
|
|
|
@@ -51,7 +86,64 @@ Xiaohongshu search, but not a Xiaohongshu note-reading tool.
|
|
|
51
86
|
}
|
|
52
87
|
```
|
|
53
88
|
|
|
54
|
-
`--config <path>`
|
|
89
|
+
`--config <path>` works too when you would rather pass the file explicitly. Without either, the
|
|
90
|
+
server reads `~/.config/websearch-mcp/config.json`.
|
|
91
|
+
|
|
92
|
+
## Credentials
|
|
93
|
+
|
|
94
|
+
Credential names are fixed by search-core, not configuration fields: a backend id is uppercased with
|
|
95
|
+
hyphens turned into underscores, then suffixed with `_KEY`. So Brave is `DSH_SEARCH_BRAVE_KEY` and
|
|
96
|
+
Zhihu site search is `DSH_SEARCH_ZHIHU_SITE_KEY`.
|
|
97
|
+
|
|
98
|
+
Put them where your client can see them:
|
|
99
|
+
|
|
100
|
+
```json
|
|
101
|
+
{
|
|
102
|
+
"mcpServers": {
|
|
103
|
+
"websearch": {
|
|
104
|
+
"command": "websearch-mcp",
|
|
105
|
+
"env": {
|
|
106
|
+
"WEBSEARCH_MCP_CONFIG": "/home/you/.config/websearch-mcp/config.json",
|
|
107
|
+
"DSH_SEARCH_BRAVE_KEY": "…"
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
If an environment value is absent, `credentials.<backend-id>` may hold the value itself inside the
|
|
115
|
+
config file. Values are literal strings: `${...}` is not expanded. Saved `credentialRef` fields are
|
|
116
|
+
discarded on load so a file can never redirect a lookup.
|
|
117
|
+
|
|
118
|
+
## Browser-backed search
|
|
119
|
+
|
|
120
|
+
Xiaohongshu answers only its own page runtime, so it reads through a browser container you host. Start
|
|
121
|
+
it from [packages/core/image](../core/image/README.md), sign in over VNC, then point the server at it:
|
|
122
|
+
|
|
123
|
+
```json
|
|
124
|
+
{
|
|
125
|
+
"search": {
|
|
126
|
+
"browser": {
|
|
127
|
+
"endpoint": "ws://127.0.0.1:3000/ws",
|
|
128
|
+
"statePath": "/path/to/search-browser/data/state.json",
|
|
129
|
+
"timeoutMs": 60000,
|
|
130
|
+
"maxConcurrentReads": 2
|
|
131
|
+
},
|
|
132
|
+
"backends": {
|
|
133
|
+
"xiaohongshu": { "enabled": true, "mode": "browser" }
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
The endpoint token goes in `DSH_SEARCH_BROWSER_TOKEN`, or in `credentials.browser` inside the file.
|
|
140
|
+
`maxConcurrentReads` (1–8) caps how many reads run on the site at once; the default is a conservative
|
|
141
|
+
local value, not a site quota. `statePath` must be the file the container writes, otherwise every read
|
|
142
|
+
starts signed out.
|
|
143
|
+
|
|
144
|
+
Searching needs only the endpoint. Reading a note goes through the same browser, so the backend
|
|
145
|
+
must be enabled in browser mode; `xiaohongshu_note` then takes the share link from the app (it
|
|
146
|
+
carries the token the read needs) or a note id an earlier search returned.
|
|
55
147
|
|
|
56
148
|
## Tools
|
|
57
149
|
|
|
@@ -59,33 +151,49 @@ Xiaohongshu search, but not a Xiaohongshu note-reading tool.
|
|
|
59
151
|
| --- | --- |
|
|
60
152
|
| `web_search` | Search across the enabled backends. Takes `query`, plus optional `mode`, `backends`, `allBackends`, `exclude`, `backend`, `compact` and `maxResults`. Anything that cannot be honoured is named in the report rather than silently dropped. |
|
|
61
153
|
| `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. |
|
|
154
|
+
| `xiaohongshu_note` | Read one note: text, author, engagement counts, tags, pictures as image
|
|
155
|
+
content, and optionally its top-level comments (depth is one level, `commentLimit` 1–50). Needs the
|
|
156
|
+
Xiaohongshu backend in browser mode plus a browser endpoint; a disabled backend, a missing endpoint
|
|
157
|
+
or a missing note token is reported instead of an empty note. |
|
|
62
158
|
| `list_backends` | Every backend with its modes, cost tier, enabled state and whether a credential is present. It never enables anything. |
|
|
63
159
|
|
|
160
|
+
`compact: true` returns URL, title and date only, which is usually the difference between a usable
|
|
161
|
+
context and a flooded one.
|
|
162
|
+
|
|
163
|
+
## Protocol versions
|
|
164
|
+
|
|
165
|
+
The wire protocol is the [official TypeScript SDK](https://ts.sdk.modelcontextprotocol.io/v2/)
|
|
166
|
+
(`@modelcontextprotocol/server`), not a hand-written loop: the server answers the stateless
|
|
167
|
+
`2026-07-28` revision and falls back to the 2025 handshake for clients that still open with
|
|
168
|
+
`initialize`. A protocol revision therefore reaches this package as a dependency bump.
|
|
169
|
+
|
|
64
170
|
## Behaviour worth relying on
|
|
65
171
|
|
|
66
|
-
- **No fallback.** A backend uses the mode you selected, the credential you gave it
|
|
172
|
+
- **No fallback.** A backend uses the mode you selected, the credential you gave it and the endpoint in
|
|
67
173
|
the config. Retries stay on the same provider and mode.
|
|
68
174
|
- **Failures are visible.** Partial failures return the sources that worked and name the ones that did
|
|
69
|
-
not; total failures say the search failed.
|
|
70
|
-
- **
|
|
71
|
-
|
|
72
|
-
- **Reddit
|
|
175
|
+
not; total failures say the search failed. Failed calls are never cached.
|
|
176
|
+
- **Per-call strategy, saved config untouched.** `mode`, `backends` and `compact` apply to that one
|
|
177
|
+
call, so a narrow lookup and a broad sweep can coexist without editing the file.
|
|
178
|
+
- **Reddit is anonymous by default.** No account needed; the adapter uses the same anonymous token the
|
|
73
179
|
Android client obtains, because Reddit's public REST search answers 403 to anonymous callers.
|
|
74
180
|
- **X thread reading follows the site, not a scraper.** The adapter reads the operation the web app
|
|
75
181
|
embeds in the post page and calls it directly, so it survives front-end releases without a
|
|
76
|
-
transaction-id signer
|
|
182
|
+
transaction-id signer.
|
|
77
183
|
|
|
78
|
-
##
|
|
184
|
+
## Troubleshooting
|
|
79
185
|
|
|
80
|
-
|
|
186
|
+
| Symptom | Cause and fix |
|
|
187
|
+
| --- | --- |
|
|
188
|
+
| The client shows no tools | The server failed to start. Run `websearch-mcp --config <path>` by hand and read the error. |
|
|
189
|
+
| Every search fails | No backend is enabled. Call `list_backends`, then enable one and restart the client. |
|
|
190
|
+
| A keyed backend reports a missing credential | The environment variable is named after the backend id. Check the exact name with `list_backends`. |
|
|
191
|
+
| Xiaohongshu reports no endpoint | `search.browser.endpoint` is empty and the backend has none. |
|
|
192
|
+
| Xiaohongshu reports not signed in | The container's session expired. Sign in again over VNC; the next read reloads the state file. |
|
|
81
193
|
|
|
82
|
-
|
|
83
|
-
npm ci --ignore-scripts
|
|
84
|
-
npm run check
|
|
85
|
-
node packages/websearch-mcp/dist/main.js --config ./config.json
|
|
86
|
-
```
|
|
194
|
+
## Development
|
|
87
195
|
|
|
88
|
-
|
|
196
|
+
See [docs/DEVELOPMENT.md](../../docs/DEVELOPMENT.md).
|
|
89
197
|
|
|
90
198
|
## License
|
|
91
199
|
|
package/README.zh.md
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# websearch-mcp
|
|
2
|
+
|
|
3
|
+
[English](README.md) | 中文
|
|
4
|
+
|
|
5
|
+
[](https://www.npmjs.com/package/@nite07/websearch-mcp)
|
|
6
|
+
[](https://www.npmjs.com/package/@nite07/websearch-mcp)
|
|
7
|
+
|
|
8
|
+
一个多后端网页搜索的 MCP 服务,另外能读 Reddit 和 X 的讨论帖,以及小红书的笔记。任何 MCP 客户端都能用:Claude Code、Codex、DeepSeek Harness,或者你自己写的。
|
|
9
|
+
|
|
10
|
+
## 为什么还要一个搜索 MCP
|
|
11
|
+
|
|
12
|
+
多数搜索 MCP 会替你选好一家,然后什么都不说地失败。这个反过来:每个后端的接入模式由你指定,每种模式标了费用档,失败时直接点名是哪家失败、为什么失败,而不是回一个空结果。模型还能只对单次调用提要求——并行还是单家、问哪几家、每个源返回多少——这样查个小问题不至于和广撒网一个价钱。
|
|
13
|
+
|
|
14
|
+
## 安装
|
|
15
|
+
|
|
16
|
+
```sh
|
|
17
|
+
npm install -g @nite07/websearch-mcp
|
|
18
|
+
websearch-mcp --print-config > ~/.config/websearch-mcp/config.json
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`--print-config` 生成一份完整且合法的配置,除了 Keenable 和 Reddit(这两家不需要账号)之外全部关闭。
|
|
22
|
+
|
|
23
|
+
## 第一次搜索
|
|
24
|
+
|
|
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. 让客户端搜点东西
|
|
29
|
+
|
|
30
|
+
想先看看有什么可用又不花钱,调 `list_backends`:它列出每个后端的模式、费用档、启用状态以及有没有凭证,但不会启用任何东西。
|
|
31
|
+
|
|
32
|
+
## 配置页面
|
|
33
|
+
|
|
34
|
+
配置有页面了:每个后端的接入模式、成本档位、选项与凭证都在同一张表里,每张卡片带一个实测按钮。
|
|
35
|
+
**这个页面由 MCP 服务器自己提供**——一个进程,不需要额外的单元、容器或端口转发:
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
WEBSEARCH_MCP_UI_PORT=7799 WEBSEARCH_MCP_UI_TOKEN=... websearch-mcp # stdio 服务 + 页面
|
|
39
|
+
```
|
|
40
|
+
|
|
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 客户端、只想看一眼页面:
|
|
56
|
+
|
|
57
|
+
```sh
|
|
58
|
+
websearch-mcp --ui --host 0.0.0.0 --port 7799 --print-url # --print-url 只打印链接
|
|
59
|
+
```
|
|
60
|
+
|
|
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
|
+
```
|
|
73
|
+
|
|
74
|
+
想显式指定文件时也可以用 `--config <path>`。两者都没有时,服务读取 `~/.config/websearch-mcp/config.json`。
|
|
75
|
+
|
|
76
|
+
## 凭证
|
|
77
|
+
|
|
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
|
+
}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
环境变量没有时,可以用配置文件里的 `credentials.<后端-id>` 直接写值。值是字面字符串,`${...}` 不会被展开。加载时保存的 `credentialRef` 字段会被丢弃,配置文件没办法把查询指到别的密钥上。
|
|
97
|
+
|
|
98
|
+
## 需要浏览器的搜索
|
|
99
|
+
|
|
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
|
+
```
|
|
117
|
+
|
|
118
|
+
端点令牌写在 `DSH_SEARCH_BROWSER_TOKEN`,或者文件里的 `credentials.browser`。`maxConcurrentReads`(1–8)限制同一个站点上同时跑几个读取,默认值是保守的本地取值,不代表站点额度。`statePath` 必须是容器写的那个文件,否则每次读回来都是未登录。只要端点配好就能搜索;读笔记走的是同一个浏览器,所以后端必须启用为 browser 模式,`xiaohongshu_note` 吃 App 里复制的分享链接(里面带着读取要用的 token),或者之前搜索返回的笔记 id。
|
|
119
|
+
|
|
120
|
+
## 工具
|
|
121
|
+
|
|
122
|
+
| 工具 | 做什么 |
|
|
123
|
+
| --- | --- |
|
|
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` | 列出每个后端的模式、费用档、启用状态和凭证是否就位。不会启用任何东西。 |
|
|
128
|
+
|
|
129
|
+
`compact: true` 只回 URL、标题和日期,通常就是一个还能用的上下文和一个被灌满的上下文的区别。
|
|
130
|
+
|
|
131
|
+
## 协议版本
|
|
132
|
+
|
|
133
|
+
线上协议交给[官方 TypeScript SDK](https://ts.sdk.modelcontextprotocol.io/v2/)
|
|
134
|
+
(`@modelcontextprotocol/server`),不是手写循环:服务端会说无状态的 `2026-07-28`,对仍在用
|
|
135
|
+
`initialize` 开场的客户端回退到 2025 握手。协议改版因此是升依赖,不是重写连接层。
|
|
136
|
+
|
|
137
|
+
## 可以依赖的行为
|
|
138
|
+
|
|
139
|
+
- **不切换。** 后端只按你选定的模式、你给的凭证、配置里的端点工作。重试不会换服务商、不会换模式。
|
|
140
|
+
- **失败看得见。** 部分失败返回成功的那部分并点名失败的;全部失败就说搜索失败。失败的调用不会进缓存。
|
|
141
|
+
- **单次策略不动配置。** `mode`、`backends`、`compact` 只作用这一次,所以窄查询和广撒网可以并存,不用来回改文件。
|
|
142
|
+
- **Reddit 默认匿名。** 不需要账号,用的就是安卓客户端拿的那种匿名 token——Reddit 的公开 REST 搜索对匿名调用一律 403。
|
|
143
|
+
- **X 的帖子按站点自己的方式读。** 适配层读页面里内嵌的那个接口再直接调用,前端发版不会失效,也不需要自己签 transaction id。
|
|
144
|
+
|
|
145
|
+
## 常见问题
|
|
146
|
+
|
|
147
|
+
| 现象 | 原因与处理 |
|
|
148
|
+
| --- | --- |
|
|
149
|
+
| 客户端里看不到工具 | 服务没起来。手动跑一次 `websearch-mcp --config <path>` 看报错。 |
|
|
150
|
+
| 每次搜索都失败 | 没有启用任何后端。先调 `list_backends`,启用一家,再重启客户端。 |
|
|
151
|
+
| 某个要 Key 的后端报缺凭证 | 环境变量名是按后端 id 生成的,用 `list_backends` 核对准确名字。 |
|
|
152
|
+
| 小红书报没有端点 | `search.browser.endpoint` 是空的,后端自己也没配端点。 |
|
|
153
|
+
| 小红书报未登录 | 容器的登录态过期了。去 VNC 里重新登录,下次读取会重新加载会话文件。 |
|
|
154
|
+
|
|
155
|
+
## 开发
|
|
156
|
+
|
|
157
|
+
见 [docs/DEVELOPMENT.md](../../docs/DEVELOPMENT.md)。
|
|
158
|
+
|
|
159
|
+
## 许可
|
|
160
|
+
|
|
161
|
+
MIT。
|
package/dist/live.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type ServerConfig } from './config.js';
|
|
2
|
+
/**
|
|
3
|
+
* Tools read the configuration through this handle on every call instead of closing over a snapshot,
|
|
4
|
+
* so an edit that lands on disk reaches a server that is already running.
|
|
5
|
+
*/
|
|
6
|
+
export interface ConfigSource {
|
|
7
|
+
get(): ServerConfig;
|
|
8
|
+
/** Changes whenever the configuration behind get() changed; the search engine rebuilds on a new value. */
|
|
9
|
+
revision(): string;
|
|
10
|
+
}
|
|
11
|
+
export declare const fixedSource: (config: ServerConfig) => ConfigSource;
|
|
12
|
+
export declare function asSource(value: ServerConfig | ConfigSource): ConfigSource;
|
|
13
|
+
export interface ReloadableSource extends ConfigSource {
|
|
14
|
+
close(): void;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Watches the directory rather than the file: a settings page replaces the file by rename, which
|
|
18
|
+
* detaches a watcher bound to the inode. A failed reload keeps the previous configuration alive and
|
|
19
|
+
* says why, because a half-written file must never take the running server down.
|
|
20
|
+
*/
|
|
21
|
+
export declare function watchSource(initial: ServerConfig, log: (message: string) => void): ReloadableSource;
|
package/dist/live.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { watch } from 'node:fs';
|
|
2
|
+
import { basename, dirname } from 'node:path';
|
|
3
|
+
import { loadConfig } from './config.js';
|
|
4
|
+
export const fixedSource = (config) => ({ get: () => config, revision: () => 'fixed' });
|
|
5
|
+
export function asSource(value) {
|
|
6
|
+
return typeof value.get === 'function' ? value : fixedSource(value);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Watches the directory rather than the file: a settings page replaces the file by rename, which
|
|
10
|
+
* detaches a watcher bound to the inode. A failed reload keeps the previous configuration alive and
|
|
11
|
+
* says why, because a half-written file must never take the running server down.
|
|
12
|
+
*/
|
|
13
|
+
export function watchSource(initial, log) {
|
|
14
|
+
let current = initial;
|
|
15
|
+
let revision = 0;
|
|
16
|
+
let timer;
|
|
17
|
+
let closed = false;
|
|
18
|
+
const directory = dirname(initial.configPath);
|
|
19
|
+
const name = basename(initial.configPath);
|
|
20
|
+
const watcher = watch(directory, { persistent: false }, (_event, filename) => {
|
|
21
|
+
if (filename && basename(String(filename)) !== name)
|
|
22
|
+
return;
|
|
23
|
+
if (timer)
|
|
24
|
+
clearTimeout(timer);
|
|
25
|
+
timer = setTimeout(() => void reload(), 150);
|
|
26
|
+
timer.unref?.();
|
|
27
|
+
});
|
|
28
|
+
watcher.on('error', error => log(`configuration watcher stopped: ${error instanceof Error ? error.message : String(error)}`));
|
|
29
|
+
async function reload() {
|
|
30
|
+
if (closed)
|
|
31
|
+
return;
|
|
32
|
+
try {
|
|
33
|
+
current = await loadConfig({ configPath: initial.configPath });
|
|
34
|
+
revision += 1;
|
|
35
|
+
log(`configuration reloaded from ${initial.configPath} (revision ${revision})`);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
const reason = error instanceof Error ? error.message.split('\n')[0] : String(error);
|
|
39
|
+
log(`configuration at ${initial.configPath} is not usable; keeping the previous one: ${reason}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
get: () => current,
|
|
44
|
+
revision: () => `r${revision}`,
|
|
45
|
+
close: () => {
|
|
46
|
+
closed = true;
|
|
47
|
+
if (timer)
|
|
48
|
+
clearTimeout(timer);
|
|
49
|
+
watcher.close();
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|