@scoheart/x-search-mcp 0.3.0 → 0.6.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/.env.example +7 -10
- package/README.md +29 -17
- package/THIRD_PARTY_NOTICES.md +4 -0
- package/TOOL.md +58 -77
- package/dist/evidence-licenses.txt +791 -0
- package/dist/evidence.html +170 -0
- package/dist/package.json +11 -3
- package/dist/src/auth.d.ts.map +1 -1
- package/dist/src/auth.js +67 -57
- package/dist/src/auth.js.map +1 -1
- package/dist/src/call-log.d.ts +5 -4
- package/dist/src/call-log.d.ts.map +1 -1
- package/dist/src/call-log.js +82 -54
- package/dist/src/call-log.js.map +1 -1
- package/dist/src/cli.d.ts.map +1 -1
- package/dist/src/cli.js +26 -19
- package/dist/src/cli.js.map +1 -1
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +12 -16
- package/dist/src/config.js.map +1 -1
- package/dist/src/device-login.d.ts +20 -0
- package/dist/src/device-login.d.ts.map +1 -0
- package/dist/src/device-login.js +110 -0
- package/dist/src/device-login.js.map +1 -0
- package/dist/src/events.d.ts +16 -0
- package/dist/src/events.d.ts.map +1 -0
- package/dist/src/events.js +128 -0
- package/dist/src/events.js.map +1 -0
- package/dist/src/evidence-app.d.ts +4 -0
- package/dist/src/evidence-app.d.ts.map +1 -0
- package/dist/src/evidence-app.js +17 -0
- package/dist/src/evidence-app.js.map +1 -0
- package/dist/src/http-server.d.ts +1 -0
- package/dist/src/http-server.d.ts.map +1 -1
- package/dist/src/http-server.js +6 -4
- package/dist/src/http-server.js.map +1 -1
- package/dist/src/http.d.ts +12 -15
- package/dist/src/http.d.ts.map +1 -1
- package/dist/src/http.js +78 -118
- package/dist/src/http.js.map +1 -1
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/multi-user/service.d.ts.map +1 -1
- package/dist/src/multi-user/service.js +3 -2
- package/dist/src/multi-user/service.js.map +1 -1
- package/dist/src/search-input.d.ts +31 -0
- package/dist/src/search-input.d.ts.map +1 -0
- package/dist/src/search-input.js +102 -0
- package/dist/src/search-input.js.map +1 -0
- package/dist/src/search-response.d.ts +26 -0
- package/dist/src/search-response.d.ts.map +1 -0
- package/dist/src/search-response.js +128 -0
- package/dist/src/search-response.js.map +1 -0
- package/dist/src/search.d.ts +7 -20
- package/dist/src/search.d.ts.map +1 -1
- package/dist/src/search.js +129 -440
- package/dist/src/search.js.map +1 -1
- package/dist/src/server.d.ts +8 -9
- package/dist/src/server.d.ts.map +1 -1
- package/dist/src/server.js +110 -193
- package/dist/src/server.js.map +1 -1
- package/dist/src/tool-contract.d.ts +183 -0
- package/dist/src/tool-contract.d.ts.map +1 -0
- package/dist/src/tool-contract.js +88 -0
- package/dist/src/tool-contract.js.map +1 -0
- package/dist/src/types.d.ts +7 -37
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/watch-cli.d.ts +2 -0
- package/dist/src/watch-cli.d.ts.map +1 -0
- package/dist/src/watch-cli.js +41 -0
- package/dist/src/watch-cli.js.map +1 -0
- package/dist/src/watch-store.d.ts +41 -0
- package/dist/src/watch-store.d.ts.map +1 -0
- package/dist/src/watch-store.js +171 -0
- package/dist/src/watch-store.js.map +1 -0
- package/dist/ui/evidence.d.ts +2 -0
- package/dist/ui/evidence.d.ts.map +1 -0
- package/dist/ui/evidence.js +150 -0
- package/dist/ui/evidence.js.map +1 -0
- package/docs/events-and-apps.md +40 -0
- package/examples/codex.toml +6 -7
- package/examples/mcp.json +2 -6
- package/package.json +11 -3
- package/server.json +34 -0
- package/src/auth.ts +65 -57
- package/src/call-log.ts +83 -53
- package/src/cli.ts +26 -19
- package/src/config.ts +11 -13
- package/src/device-login.ts +120 -0
- package/src/events.ts +124 -0
- package/src/evidence-app.ts +19 -0
- package/src/http-server.ts +7 -4
- package/src/http.ts +83 -162
- package/src/index.ts +1 -0
- package/src/multi-user/service.ts +3 -2
- package/src/search-input.ts +109 -0
- package/src/search-response.ts +122 -0
- package/src/search.ts +131 -476
- package/src/server.ts +114 -207
- package/src/tool-contract.ts +96 -0
- package/src/types.ts +8 -40
- package/src/watch-cli.ts +35 -0
- package/src/watch-store.ts +182 -0
- package/tsconfig.json +2 -1
package/.env.example
CHANGED
|
@@ -28,11 +28,9 @@ X_SEARCH_MODEL=grok-4.5
|
|
|
28
28
|
# X_SEARCH_HTTP_ALLOWED_HOSTS=mcp.example.com
|
|
29
29
|
# X_SEARCH_HTTP_ALLOWED_ORIGINS=https://app.example.com
|
|
30
30
|
|
|
31
|
-
#
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
# 失败重试次数 (默认 2,范围 0-3,仅针对网络、超时及 5xx)
|
|
35
|
-
X_SEARCH_RETRIES=2
|
|
31
|
+
# 搜索总时限和上游响应体上限
|
|
32
|
+
X_SEARCH_DEADLINE_MS=90000
|
|
33
|
+
X_SEARCH_MAX_RESPONSE_BYTES=2097152
|
|
36
34
|
|
|
37
35
|
# 最大轮数 (默认 4,范围 1-20)
|
|
38
36
|
X_SEARCH_MAX_TURNS=4
|
|
@@ -40,13 +38,12 @@ X_SEARCH_MAX_TURNS=4
|
|
|
40
38
|
# 思考深度: low | medium | high | xhigh (可选)
|
|
41
39
|
# X_SEARCH_REASONING_EFFORT=medium
|
|
42
40
|
|
|
43
|
-
#
|
|
44
|
-
# X_SEARCH_LOG=
|
|
41
|
+
# 个人调用日志:metadata、debug 或 off
|
|
42
|
+
# X_SEARCH_LOG=metadata
|
|
45
43
|
# X_SEARCH_LOG_DIR=/Users/username/.config/x-search-mcp/logs
|
|
46
|
-
# 保留最近多少份日志,0 表示不清理(默认 100)
|
|
47
44
|
# X_SEARCH_LOG_KEEP=100
|
|
48
|
-
#
|
|
49
|
-
#
|
|
45
|
+
# X_SEARCH_LOG_MAX_BYTES=65536
|
|
46
|
+
# X_SEARCH_LOG_TOTAL_BYTES=33554432
|
|
50
47
|
|
|
51
48
|
# 代理支持 (由 Undici EnvHttpProxyAgent 自动读取)
|
|
52
49
|
# HTTP_PROXY=http://127.0.0.1:7890
|
package/README.md
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/@scoheart/x-search-mcp)
|
|
4
4
|
[](./LICENSE)
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
Search public X posts through the xAI Responses API. The single `x_search` tool returns a bounded answer, canonical source evidence and usage counts.
|
|
7
7
|
|
|
8
8
|
[中文使用手册](./TOOL.md)
|
|
9
9
|
|
|
10
10
|
| If you want to… | Use | xAI credentials |
|
|
11
11
|
| --- | --- | --- |
|
|
12
|
-
| Search from
|
|
12
|
+
| Search from a local MCP client | [Client setup](#connect-an-mcp-client) | Your API key or eligible Grok subscription |
|
|
13
13
|
| Use one account from several devices | [Single-account HTTP](#single-account-http) | One API key or eligible Grok subscription on the server |
|
|
14
14
|
| Let invited users share a URL and use their own xAI accounts | [Multi-user HTTP](#multi-user-http) | Each user binds an API key and uses their own xAI API quota |
|
|
15
15
|
|
|
@@ -38,25 +38,24 @@ x-search-mcp search "What did @SpaceX post about Starship this week?" --auth oau
|
|
|
38
38
|
|
|
39
39
|
`X_SEARCH_AUTH_MODE=oauth` selects subscription credentials for local stdio or single-account HTTP. The default `auto` mode uses a configured API key first, then looks for a local OAuth login. See the [authentication and configuration reference](./TOOL.md#凭证配置).
|
|
40
40
|
|
|
41
|
-
## Connect
|
|
41
|
+
## Connect an MCP client
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
All transports use **MCP 2026-07-28**. For a client that supports that revision over stdio, use the [stdio configuration](./examples/mcp.json). It starts `x-search-mcp` as a child process.
|
|
44
|
+
|
|
45
|
+
For Codex 0.172.0, start personal Streamable HTTP on loopback. Export the service token in the environment that starts the server and Codex. For a source build, replace `x-search-mcp` with `node bin/x-search-mcp.js` after `npm run build`.
|
|
44
46
|
|
|
45
47
|
```sh
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
pi mcp add x-search -- x-search-mcp --stdio
|
|
48
|
+
export X_SEARCH_HTTP_TOKEN="$(openssl rand -hex 32)"
|
|
49
|
+
x-search-mcp http --interactive-login
|
|
49
50
|
```
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
When a local search returns `AUTH_REQUIRED`, your agent can call `x_search_login` to start Grok device authorization. Open the verification page and confirm the code and account in your browser. The agent can then call `x_search_auth_status` and retry the search after authorization completes. [Device sign-in details](./TOOL.md#在-agent-内完成-grok-设备授权)
|
|
52
|
+
Use the [Codex configuration](./examples/codex.toml) to enable `mcp_2026_07_28` and connect to the loopback endpoint. Codex 0.172.0 uses the modern revision over HTTP with this setting.
|
|
54
53
|
|
|
55
|
-
|
|
54
|
+
When Grok sign-in is needed, the client asks for consent with MCP form elicitation. The tool returns a verification link and short code. Check the account and code in Grok, then retry the same search after authorizing. The `auth login` command provides a terminal entry point. Use `--interactive-login` only for a personal listener with a trusted local client. [Device sign-in details](./TOOL.md#在-agent-内完成-grok-设备授权)
|
|
56
55
|
|
|
57
56
|
## Run over HTTP
|
|
58
57
|
|
|
59
|
-
Both modes use the official MCP SDK with Streamable HTTP.
|
|
58
|
+
Both modes use the official MCP SDK with Streamable HTTP on MCP 2026-07-28.
|
|
60
59
|
|
|
61
60
|
### Single-account HTTP
|
|
62
61
|
|
|
@@ -76,13 +75,26 @@ Deploy behind HTTPS with an MCP OAuth issuer and Alibaba Cloud KMS. Each invited
|
|
|
76
75
|
x-search-mcp http --multi-user --port 8000
|
|
77
76
|
```
|
|
78
77
|
|
|
79
|
-
See the [multi-user deployment guide](./docs/multi-user.md) for issuer setup, KMS permissions, reverse-proxy configuration
|
|
78
|
+
See the [multi-user deployment guide](./docs/multi-user.md) for issuer setup, KMS permissions, reverse-proxy configuration and client login. Grok subscription login is available in the personal modes.
|
|
80
79
|
|
|
81
80
|
## Results and logs
|
|
82
81
|
|
|
83
82
|
- `x_search` accepts a query, optional X account filters, and a date range. See the [tool parameters](./TOOL.md#工具参数规范-x_search).
|
|
84
|
-
- Results include
|
|
85
|
-
-
|
|
83
|
+
- Results include `sources[]` with canonical post IDs and a usage summary. Use `detail: "detailed"` for a longer response. `status` distinguishes complete, partial and unverified results.
|
|
84
|
+
- The default total search deadline is 90 seconds, and the upstream response limit is 2 MiB. Personal logs record timing and counts. Set `X_SEARCH_LOG=debug` to capture bounded diagnostics. Multi-user HTTP disables local call logs.
|
|
85
|
+
|
|
86
|
+
## Review sources and watch for new evidence
|
|
87
|
+
|
|
88
|
+
MCP Apps hosts render the source review view after an `x_search` call. Filter by account, post ID or website, open a source, and select the sources to add to the conversation context. The view runs from a bundled `ui://` resource. See the [Apps and Events guide](./docs/events-and-apps.md).
|
|
89
|
+
|
|
90
|
+
On personal loopback HTTP, you can create a bounded watch and enable the MCP Events Beta polling extension.
|
|
91
|
+
|
|
92
|
+
```sh
|
|
93
|
+
x-search-mcp watch add "Grok release announcements" --every-minutes 15 --runs 8
|
|
94
|
+
x-search-mcp http --events
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Use the watch ID with the event type `x_search.evidence_found` and keep the returned cursor. The server stores watch state and evidence in private SQLite. Watches run within their explicit budget while the listener is active. Delivery requires an MCP Events client supporting `events/poll`. [Protocol details and examples](./docs/events-and-apps.md)
|
|
86
98
|
|
|
87
99
|
## Development
|
|
88
100
|
|
|
@@ -91,10 +103,10 @@ git clone https://github.com/Scoheart/x-search-mcp.git
|
|
|
91
103
|
cd x-search-mcp
|
|
92
104
|
npm ci
|
|
93
105
|
npm test
|
|
94
|
-
npm
|
|
106
|
+
npm run verify:package
|
|
95
107
|
```
|
|
96
108
|
|
|
97
|
-
`npm test`
|
|
109
|
+
`npm test` builds the project and checks the tool contracts, xAI response handling and HTTP authorization flows. `npm run verify:package` packs and installs the tarball in a temporary directory and connects to the installed stdio entry point over MCP 2026-07-28. It verifies the included Registry manifest and the tool schema. It uses an empty auth store and may download package dependencies. Pass an output directory after `--` to keep the verified tarball.
|
|
98
110
|
|
|
99
111
|
## License
|
|
100
112
|
|
package/THIRD_PARTY_NOTICES.md
CHANGED
|
@@ -33,3 +33,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
33
33
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
34
34
|
SOFTWARE.
|
|
35
35
|
```
|
|
36
|
+
|
|
37
|
+
## MCP App bundle
|
|
38
|
+
|
|
39
|
+
License notices for the libraries bundled into the evidence view are included in `dist/evidence-licenses.txt`.
|
package/TOOL.md
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
# @scoheart/x-search-mcp 工具接入与使用说明
|
|
2
2
|
|
|
3
|
-
本工具是一个独立运行的 Node.js/TypeScript MCP
|
|
3
|
+
本工具是一个独立运行的 Node.js/TypeScript MCP 服务,提供一个 `x_search` 工具。检索使用 xAI Responses API,支持 X(原 Twitter)实时动态与历史发帖。本服务实现参考 Nous Research 的 Hermes Agent(commit `fcca1740533d59d7a46ab1a3a53d3a45ef3127ff`),作为独立 MCP 包运行。
|
|
4
4
|
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
## 核心特性
|
|
8
8
|
|
|
9
9
|
- **标准 MCP 协议**:基于 `@modelcontextprotocol/server`,默认运行在 `stdio` 模式,输出标准 JSON-RPC。
|
|
10
|
-
-
|
|
10
|
+
- **单工具**。 `x_search` 检索公开帖子。需要 Grok 登录时,可由宿主显示授权流程。
|
|
11
11
|
- **双认证模式**:支持按量付费 API Key 与 Grok 订阅 OAuth(设备码登录);支持多进程并发共享令牌并带文件锁(`proper-lockfile`)。
|
|
12
|
-
-
|
|
13
|
-
-
|
|
12
|
+
- **帖子证据**。 `sources[]` 提供去重链接、帖子 ID 和正文引用标记。
|
|
13
|
+
- **MCP 2026-07-28**。提供 stdio 和无状态 Streamable HTTP。
|
|
14
14
|
|
|
15
15
|
---
|
|
16
16
|
|
|
@@ -20,12 +20,12 @@
|
|
|
20
20
|
2. **传输与访问范围**。默认 stdio 供本机子进程接入。单账号 HTTP 默认监听 `127.0.0.1:8000/mcp`,客户端使用独立 Bearer 密钥。多人 HTTP 通过身份服务进行 MCP OAuth 登录,每人绑定自己的 xAI API Key。公网接入通过 HTTPS 反向代理配置。 [多人部署说明](./docs/multi-user.md)
|
|
21
21
|
3. **公共 OAuth Client ID 说明**:默认内置的公开客户端 ID 来自 Hermes Agent(`b1a00492-073a-47ea-816f-4c329264a828`)。在浏览器授权确认页面中可能会显示该客户端标识名称。如需使用专属客户端,可通过 `XAI_OAUTH_CLIENT_ID` 环境变量配置。
|
|
22
22
|
4. **OAuth 成功不等于搜索可用**:OAuth 设备码登录成功仅代表获得 xAI 账号凭证,实际搜索能力及并发额度由 xAI 云端及订阅权益决定;登录成功不保证账号一定具备 X Search 权限。
|
|
23
|
-
5.
|
|
23
|
+
5. **无引用不可作为确证**:结果标记为 `unverified` 表示缺少可识别的 X 帖子来源。
|
|
24
24
|
6. **计费与回退规则**:
|
|
25
25
|
- API Key 模式下按调用量付费(api_metered)。
|
|
26
26
|
- 显式 `oauth` 模式下仅使用订阅令牌,**绝不回退**到付费 API Key,避免产生非预期账单。
|
|
27
27
|
- `auto` 模式优先使用 API Key(如果配置),无 Key 时使用本地保存的 OAuth。
|
|
28
|
-
7.
|
|
28
|
+
7. **重试消耗**。个人模式只在 OAuth 401 或带有可等待的 `Retry-After` 的 429 后允许一次重试。多人 HTTP 每次搜索只发起一次 xAI 搜索请求。
|
|
29
29
|
8. **过滤作用域限制**:xAI 接口的 `allowed_x_handles`、`excluded_x_handles`、`from_date` 和 `to_date` 过滤主要作用于关键词与语义搜索阶段,并不严格保证限制上游服务端内部的级联线程抓取(thread fetch)。
|
|
30
30
|
|
|
31
31
|
---
|
|
@@ -35,14 +35,14 @@
|
|
|
35
35
|
需要 Node.js 22.19.0 或更高版本。可以用 `npx` 直接运行。
|
|
36
36
|
|
|
37
37
|
```bash
|
|
38
|
-
npx --yes @scoheart/x-search-mcp@0.
|
|
39
|
-
npx --yes @scoheart/x-search-mcp@0.
|
|
38
|
+
npx --yes @scoheart/x-search-mcp@0.6.0 auth login
|
|
39
|
+
npx --yes @scoheart/x-search-mcp@0.6.0 auth status
|
|
40
40
|
```
|
|
41
41
|
|
|
42
42
|
也可以在源码仓库运行 `npm ci` 和 `npm pack` 生成安装包。`prepack` 会先编译当前源码,安装端无需 TypeScript 或开发依赖。
|
|
43
43
|
|
|
44
44
|
```bash
|
|
45
|
-
npm install --global ./scoheart-x-search-mcp-0.
|
|
45
|
+
npm install --global ./scoheart-x-search-mcp-0.6.0.tgz
|
|
46
46
|
x-search-mcp auth status
|
|
47
47
|
```
|
|
48
48
|
|
|
@@ -81,11 +81,9 @@ Waiting for browser authorization...
|
|
|
81
81
|
|
|
82
82
|
### 在 agent 内完成 Grok 设备授权
|
|
83
83
|
|
|
84
|
-
|
|
85
|
-
2. `x_search_login` 返回 `pending`、官方验证链接、用户短码和有效期。用户在浏览器核对账号与短码并批准本次授权。原 stdio 进程在后台轮询,等待期间重复调用复用同一设备码。
|
|
86
|
-
3. 批准后,agent 调用 `x_search_auth_status`。最近一次流程到达 `authorized` 表示令牌已经保存,可以重试原搜索。`oauth_state` 描述本机缓存的凭证有效期,实际搜索仍取决于 xAI 订阅权益。
|
|
84
|
+
启用交互登录的服务在需要 Grok 凭据时,同一条 `x_search` 先由客户端显示登录确认。确认后工具返回 `authorization_pending`,包含验证链接、短码和有效期。服务在后台轮询,用户在 Grok 页面核对账号和短码并批准,再调用原搜索。
|
|
87
85
|
|
|
88
|
-
|
|
86
|
+
stdio 支持这一流程。使用 Codex 0.172.0 时,通过本机 HTTP 接入,服务使用 `--interactive-login`。客户端须支持 MCP 2026-07-28 的 form elicitation。可用 `x-search-mcp auth login` 直接在终端登录。[MCP Elicitation](https://modelcontextprotocol.io/specification/2026-07-28/client/elicitation) · [RFC 8628](https://www.rfc-editor.org/rfc/rfc8628.html)
|
|
89
87
|
|
|
90
88
|
### 凭证状态与注销
|
|
91
89
|
|
|
@@ -126,15 +124,16 @@ x-search-mcp auth logout
|
|
|
126
124
|
| `X_SEARCH_AUTH_FILE` | `~/.config/x-search-mcp/auth.json` | 本地 OAuth 凭证文件路径 |
|
|
127
125
|
| `XAI_OAUTH_CLIENT_ID` | `b1a00492-073a-47ea-816f-4c329264a828` | OAuth 公开客户端 ID |
|
|
128
126
|
| `X_SEARCH_MODEL` | `grok-4.5` | 搜索调用模型 |
|
|
129
|
-
| `
|
|
130
|
-
| `
|
|
127
|
+
| `X_SEARCH_DEADLINE_MS` | `90000` | 搜索共享时限(100–600000 毫秒) |
|
|
128
|
+
| `X_SEARCH_MAX_RESPONSE_BYTES` | `2097152` | 上游响应体上限(1024–16777216 字节) |
|
|
131
129
|
| `X_SEARCH_MAX_TURNS` | `4` | 内部搜索轮数(范围 1–20) |
|
|
132
130
|
| `X_SEARCH_REASONING_EFFORT`| - | 思考深度:`low` / `medium` / `high` / `xhigh` |
|
|
133
131
|
| `X_SEARCH_ENV_FILE` | - | 显式指定 `.env` 文件(通过 `process.loadEnvFile` 加载) |
|
|
134
|
-
| `X_SEARCH_LOG` | `
|
|
132
|
+
| `X_SEARCH_LOG` | `metadata` | 个人日志模式(`metadata` / `debug` / `off`) |
|
|
135
133
|
| `X_SEARCH_LOG_DIR` | `~/.config/x-search-mcp/logs` | 调用日志目录 |
|
|
136
|
-
| `X_SEARCH_LOG_KEEP` | `100` |
|
|
137
|
-
| `X_SEARCH_LOG_MAX_BYTES` | `
|
|
134
|
+
| `X_SEARCH_LOG_KEEP` | `100` | 最多保留的日志文件数 |
|
|
135
|
+
| `X_SEARCH_LOG_MAX_BYTES` | `65536` | 单次 debug 数据预算 |
|
|
136
|
+
| `X_SEARCH_LOG_TOTAL_BYTES` | `33554432` | 日志目录总字节数上限 |
|
|
138
137
|
| `HTTP_PROXY` / `HTTPS_PROXY` | - | 标准 HTTP/HTTPS 代理配置 |
|
|
139
138
|
|
|
140
139
|
### HTTP 服务配置
|
|
@@ -159,16 +158,11 @@ HTTP 请求体默认上限为 1 MiB。`SIGINT`/`SIGTERM` 停止服务并取消
|
|
|
159
158
|
|
|
160
159
|
## 调用日志
|
|
161
160
|
|
|
162
|
-
|
|
161
|
+
默认的 `metadata` 模式记录请求耗时、HTTP 状态、物理请求数和已知的上游搜索次数。多人 HTTP 关闭本地调用日志。
|
|
163
162
|
|
|
164
|
-
-
|
|
165
|
-
-
|
|
166
|
-
-
|
|
167
|
-
- 凭证处理:不记录 `Authorization`;`access_token`、`api_key` 等字段以及 `Bearer` / `xai-` 形态的字符串会替换成 `[redacted]`
|
|
168
|
-
- 失败调用也会写日志。HTTP 错误正文只进本地文件,不回传给 MCP 客户端
|
|
169
|
-
- 查看最近日志:`x-search-mcp logs`
|
|
170
|
-
|
|
171
|
-
日志写入失败不会让搜索失败;结果的 `warnings` 会说明日志没写上。
|
|
163
|
+
- 日志目录默认为 `~/.config/x-search-mcp/logs/`,新文件权限为 `0600`。
|
|
164
|
+
- 排查上游响应时可显式设 `X_SEARCH_LOG=debug`,请求和响应在写入前做凭据脱敏并按字节限制。日志总量和文件数各有上限。
|
|
165
|
+
- 用 `x-search-mcp logs` 查看最近记录。
|
|
172
166
|
|
|
173
167
|
## Agent 接入配置
|
|
174
168
|
|
|
@@ -184,11 +178,11 @@ node bin/x-search-mcp.js http --port 8000
|
|
|
184
178
|
|
|
185
179
|
安装后可直接使用 `x-search-mcp http`。客户端选择 **Streamable HTTP**,填写 `http://127.0.0.1:8000/mcp`,请求头设为 `Authorization: Bearer <X_SEARCH_HTTP_TOKEN 的值>`。未带正确密钥返回 401。来源 Host 或 Origin 未获允许时返回 403。
|
|
186
180
|
|
|
187
|
-
单账号 HTTP
|
|
181
|
+
单账号 HTTP 使用服务端配置的 xAI 凭据。直接回环监听可加 `--interactive-login`,启动宿主授权流程。对外部署可在服务端通过 CLI 完成登录。
|
|
188
182
|
|
|
189
183
|
若经域名代理,配置 `--allowed-host mcp.example.com`,让客户端连接 `https://mcp.example.com/mcp`。浏览器跨站调用还需显式 `--allowed-origin https://app.example.com`;非浏览器客户端可以不发送 Origin。HTTP 密钥与 Grok 凭证、npm 发布 token 分开管理。
|
|
190
184
|
|
|
191
|
-
### 1.
|
|
185
|
+
### 1. 支持 MCP 2026-07-28 的 stdio 客户端
|
|
192
186
|
|
|
193
187
|
在目标 Agent 的配置文件中添加:
|
|
194
188
|
|
|
@@ -197,32 +191,29 @@ node bin/x-search-mcp.js http --port 8000
|
|
|
197
191
|
"mcpServers": {
|
|
198
192
|
"x-search": {
|
|
199
193
|
"command": "npx",
|
|
200
|
-
"args": ["--yes", "@scoheart/x-search-mcp@0.
|
|
194
|
+
"args": ["--yes", "@scoheart/x-search-mcp@0.6.0"],
|
|
201
195
|
"env": {
|
|
202
196
|
"X_SEARCH_AUTH_MODE": "auto",
|
|
203
197
|
"X_SEARCH_MODEL": "grok-4.5"
|
|
204
|
-
}
|
|
205
|
-
"timeout": 600
|
|
198
|
+
}
|
|
206
199
|
}
|
|
207
200
|
}
|
|
208
201
|
}
|
|
209
202
|
```
|
|
210
203
|
|
|
211
|
-
> 若安装的是本地 tarball,可改用 `"command": "x-search-mcp"`、`"args": []`,并确保客户端的 `PATH` 包含安装目录。也可以运行 `x-search-mcp config` 生成当前可执行入口的绝对路径配置。修改配置后请重启或重新加载 Agent 会话。
|
|
204
|
+
> 若安装的是本地 tarball,可改用 `"command": "x-search-mcp"`、`"args": []`,并确保客户端的 `PATH` 包含安装目录。也可以运行 `x-search-mcp config` 生成当前可执行入口的绝对路径配置。修改配置后请重启或重新加载 Agent 会话。
|
|
212
205
|
|
|
213
|
-
### 2. Codex
|
|
206
|
+
### 2. Codex 0.172.0
|
|
214
207
|
|
|
215
|
-
|
|
216
|
-
[mcp_servers.x-search]
|
|
217
|
-
command = "npx"
|
|
218
|
-
args = ["--yes", "@scoheart/x-search-mcp@0.3.0"]
|
|
219
|
-
tool_timeout_sec = 600
|
|
208
|
+
服务和 Codex 进程使用同一环境里的 HTTP 服务密钥。在本机启动服务并保持运行。
|
|
220
209
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
210
|
+
```sh
|
|
211
|
+
export X_SEARCH_HTTP_TOKEN="$(openssl rand -hex 32)"
|
|
212
|
+
x-search-mcp http --interactive-login
|
|
224
213
|
```
|
|
225
214
|
|
|
215
|
+
将 [Codex 示例配置](./examples/codex.toml) 合入客户端配置。该版本开启 `mcp_2026_07_28` 后可通过 Streamable HTTP 发现工具,stdio 握手仍使用旧协议。
|
|
216
|
+
|
|
226
217
|
---
|
|
227
218
|
|
|
228
219
|
## 工具参数规范 (`x_search`)
|
|
@@ -236,53 +227,43 @@ interface XSearchInput {
|
|
|
236
227
|
to_date?: string; // 可选,结束日期 YYYY-MM-DD(不包含当天)
|
|
237
228
|
enable_image_understanding?: boolean; // 可选,是否启用推文配图理解
|
|
238
229
|
enable_video_understanding?: boolean; // 可选,是否启用推文视频理解
|
|
239
|
-
|
|
230
|
+
detail?: 'concise' | 'detailed'; // 可选,控制回答长度和来源条数
|
|
240
231
|
}
|
|
241
232
|
```
|
|
242
233
|
|
|
243
234
|
### 返回结构示例
|
|
244
235
|
|
|
236
|
+
`structuredContent` 提供字段化的回答与证据。`complete` 表示上游完成且有 X 帖子来源,`partial` 表示上游报告结果不完整,`unverified` 表示没有可识别的 X 帖子来源。`cited_in_answer` 仅在上游提供有效的正文引用标注时出现。外部网页也可列在 `sources` 内。
|
|
237
|
+
|
|
245
238
|
```json
|
|
246
239
|
{
|
|
247
|
-
"
|
|
248
|
-
"provider": "xai",
|
|
249
|
-
"tool": "x_search",
|
|
240
|
+
"status": "complete",
|
|
250
241
|
"model": "grok-4.5",
|
|
251
|
-
"
|
|
252
|
-
"
|
|
253
|
-
"billing_mode": "subscription_oauth",
|
|
254
|
-
"answer": "最新动态包括...",
|
|
255
|
-
"citations": [
|
|
256
|
-
"https://x.com/OpenAI/status/123456789"
|
|
257
|
-
],
|
|
258
|
-
"inline_citations": [
|
|
242
|
+
"answer": "找到一条相关公开帖子。",
|
|
243
|
+
"sources": [
|
|
259
244
|
{
|
|
260
|
-
"
|
|
261
|
-
"
|
|
262
|
-
"
|
|
263
|
-
"
|
|
245
|
+
"kind": "x_post",
|
|
246
|
+
"url": "https://x.com/Example/status/123456789",
|
|
247
|
+
"post_id": "123456789",
|
|
248
|
+
"handle": "Example",
|
|
249
|
+
"cited_in_answer": true
|
|
264
250
|
}
|
|
265
251
|
],
|
|
266
|
-
"
|
|
267
|
-
"degraded": false,
|
|
268
|
-
"degraded_reason": null,
|
|
269
|
-
"search_execution": "observed",
|
|
270
|
-
"server_side_calls": [
|
|
271
|
-
{
|
|
272
|
-
"call_id": "xs_123456",
|
|
273
|
-
"name": "x_keyword_search",
|
|
274
|
-
"arguments": { "query": "OpenAI Sora" }
|
|
275
|
-
}
|
|
276
|
-
],
|
|
277
|
-
"response_status": "completed",
|
|
278
|
-
"incomplete_details": null,
|
|
252
|
+
"truncated": false,
|
|
279
253
|
"usage": {
|
|
280
|
-
"
|
|
281
|
-
"
|
|
254
|
+
"requests": 1,
|
|
255
|
+
"x_search_calls": 2,
|
|
256
|
+
"x_posts_fetched": 5,
|
|
257
|
+
"x_users_fetched": null,
|
|
258
|
+
"input_tokens": 800,
|
|
259
|
+
"output_tokens": 350
|
|
282
260
|
},
|
|
283
|
-
"
|
|
284
|
-
"warnings": [
|
|
285
|
-
"OAuth subscription search availability and quota are determined upstream by xAI; successful login does not guarantee search availability."
|
|
286
|
-
]
|
|
261
|
+
"elapsed_ms": 1640
|
|
287
262
|
}
|
|
288
263
|
```
|
|
264
|
+
|
|
265
|
+
默认 `concise` 最多返回 3,000 字节回答与 8 条来源。`detailed` 最多返回 16,000 字节与 24 条来源。`truncated` 记录本地截断。用量字段为 `null` 表示上游未报告。若因限流返回 `status: "error"`,`error.retry_after_ms` 是可用的重试提示。缺少凭据时 `action` 给出登录命令或用户设置页。
|
|
266
|
+
|
|
267
|
+
## Apps 和 Events
|
|
268
|
+
|
|
269
|
+
支持 Apps 的宿主可以筛选并选择搜索来源。使用带 `--events` 的个人回环 HTTP 监听器可运行有预算的观察规则,并通过 MCP Events Beta 续读。 [接入与事件说明](./docs/events-and-apps.md)
|