@scoheart/x-search-mcp 0.6.0 → 0.6.2
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 +16 -86
- package/TOOL.md +32 -247
- package/dist/evidence.html +25 -17
- package/dist/package.json +2 -2
- package/dist/src/evidence-app.d.ts +1 -1
- package/dist/src/evidence-app.d.ts.map +1 -1
- package/dist/src/evidence-app.js +39 -0
- package/dist/src/evidence-app.js.map +1 -1
- package/dist/ui/evidence.js +68 -1
- package/dist/ui/evidence.js.map +1 -1
- package/docs/events-and-apps.md +8 -20
- package/examples/mcp.json +1 -1
- package/package.json +2 -2
- package/server.json +3 -3
- package/src/evidence-app.ts +39 -1
package/README.md
CHANGED
|
@@ -1,113 +1,43 @@
|
|
|
1
|
-
#
|
|
1
|
+
# X Search MCP
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[](./LICENSE)
|
|
3
|
+
Search public X posts with Grok, review sources, and watch for new evidence.
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
[中文指南](./TOOL.md) · [npm](https://www.npmjs.com/package/@scoheart/x-search-mcp)
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
## Install
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
| --- | --- | --- |
|
|
12
|
-
| Search from a local MCP client | [Client setup](#connect-an-mcp-client) | Your API key or eligible Grok subscription |
|
|
13
|
-
| Use one account from several devices | [Single-account HTTP](#single-account-http) | One API key or eligible Grok subscription on the server |
|
|
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
|
-
|
|
16
|
-
## Quick start
|
|
17
|
-
|
|
18
|
-
Requires Node.js **22.19.0 or later**.
|
|
9
|
+
Requires Node.js 22.19+ and an MCP 2026-07-28 client.
|
|
19
10
|
|
|
20
11
|
```sh
|
|
21
|
-
npm install
|
|
12
|
+
npm install -g @scoheart/x-search-mcp
|
|
22
13
|
```
|
|
23
14
|
|
|
24
|
-
|
|
15
|
+
Set `XAI_API_KEY_FILE` to a private key file, or run `x-search-mcp auth login` with an eligible Grok subscription.
|
|
25
16
|
|
|
26
|
-
|
|
27
|
-
export XAI_API_KEY_FILE=/absolute/path/to/xai-api-key
|
|
28
|
-
x-search-mcp search "What did @SpaceX post about Starship this week?"
|
|
29
|
-
```
|
|
17
|
+
## Connect
|
|
30
18
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
```sh
|
|
34
|
-
x-search-mcp auth login
|
|
35
|
-
x-search-mcp auth status
|
|
36
|
-
x-search-mcp search "What did @SpaceX post about Starship this week?" --auth oauth
|
|
37
|
-
```
|
|
38
|
-
|
|
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
|
-
|
|
41
|
-
## Connect an MCP client
|
|
42
|
-
|
|
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`.
|
|
19
|
+
Launch `x-search-mcp` for [stdio clients](./examples/mcp.json). For Codex 0.172.0, use [loopback HTTP](./examples/codex.toml) with `mcp_2026_07_28` enabled.
|
|
46
20
|
|
|
47
21
|
```sh
|
|
48
22
|
export X_SEARCH_HTTP_TOKEN="$(openssl rand -hex 32)"
|
|
49
23
|
x-search-mcp http --interactive-login
|
|
50
24
|
```
|
|
51
25
|
|
|
52
|
-
|
|
53
|
-
|
|
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-设备授权)
|
|
55
|
-
|
|
56
|
-
## Run over HTTP
|
|
57
|
-
|
|
58
|
-
Both modes use the official MCP SDK with Streamable HTTP on MCP 2026-07-28.
|
|
59
|
-
|
|
60
|
-
### Single-account HTTP
|
|
61
|
-
|
|
62
|
-
Configure xAI credentials on the host that runs the service. Save a long, randomly generated MCP bearer token in a separate private file and start the server.
|
|
63
|
-
|
|
64
|
-
```sh
|
|
65
|
-
x-search-mcp http --token-file /absolute/path/to/mcp-token
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
Connect to `http://127.0.0.1:8000/mcp` with `Authorization: Bearer <MCP token>`. All callers use the host's configured xAI account. For remote access, keep the server on loopback, terminate HTTPS at a reverse proxy, and pass its hostname with `--allowed-host mcp.example.com`. See `x-search-mcp http --help` and the [HTTP configuration reference](./TOOL.md#http-服务配置).
|
|
69
|
-
|
|
70
|
-
### Multi-user HTTP
|
|
71
|
-
|
|
72
|
-
Deploy behind HTTPS with an MCP OAuth issuer and Alibaba Cloud KMS. Each invited user signs in to the same `/mcp` URL, opens `/settings` with the same identity, and binds their xAI API key. The server stores each binding encrypted and uses it for that user's searches. The settings page supports replacing and removing keys.
|
|
73
|
-
|
|
74
|
-
```sh
|
|
75
|
-
x-search-mcp http --multi-user --port 8000
|
|
76
|
-
```
|
|
77
|
-
|
|
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.
|
|
26
|
+
See [multi-user HTTP](./docs/multi-user.md) for shared deployments.
|
|
79
27
|
|
|
80
|
-
##
|
|
28
|
+
## Apps and Events
|
|
81
29
|
|
|
82
|
-
-
|
|
83
|
-
-
|
|
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.
|
|
30
|
+
- **Apps** lets you filter sources, preview public posts, and add selected sources to the conversation.
|
|
31
|
+
- **Events** delivers new post evidence from bounded watches. Start a personal listener with `--events`.
|
|
85
32
|
|
|
86
|
-
|
|
33
|
+
[Apps and Events guide](./docs/events-and-apps.md)
|
|
87
34
|
|
|
88
|
-
|
|
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)
|
|
98
|
-
|
|
99
|
-
## Development
|
|
35
|
+
## Develop
|
|
100
36
|
|
|
101
37
|
```sh
|
|
102
|
-
git clone https://github.com/Scoheart/x-search-mcp.git
|
|
103
|
-
cd x-search-mcp
|
|
104
38
|
npm ci
|
|
105
39
|
npm test
|
|
106
40
|
npm run verify:package
|
|
107
41
|
```
|
|
108
42
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
## License
|
|
112
|
-
|
|
113
|
-
[MIT](./LICENSE) © Scoheart. The implementation was inspired by Nous Research's Hermes Agent. See [third-party notices](./THIRD_PARTY_NOTICES.md).
|
|
43
|
+
[MIT](./LICENSE) · [Third-party notices](./THIRD_PARTY_NOTICES.md)
|
package/TOOL.md
CHANGED
|
@@ -1,269 +1,54 @@
|
|
|
1
|
-
#
|
|
1
|
+
# X Search MCP
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
用 Grok 搜索 X 的公开帖子,核对来源,并观察新证据。
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## 安装与接入
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
需要 Node.js 22.19+ 和 MCP 2026-07-28 客户端。
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
- **双认证模式**:支持按量付费 API Key 与 Grok 订阅 OAuth(设备码登录);支持多进程并发共享令牌并带文件锁(`proper-lockfile`)。
|
|
12
|
-
- **帖子证据**。 `sources[]` 提供去重链接、帖子 ID 和正文引用标记。
|
|
13
|
-
- **MCP 2026-07-28**。提供 stdio 和无状态 Streamable HTTP。
|
|
14
|
-
|
|
15
|
-
---
|
|
16
|
-
|
|
17
|
-
## 约束与边界说明(重要)
|
|
18
|
-
|
|
19
|
-
1. **非官方项目**:本项目为独立开源 MCP 实现,并非 xAI 或 Nous Research / Hermes 官方 MCP。
|
|
20
|
-
2. **传输与访问范围**。默认 stdio 供本机子进程接入。单账号 HTTP 默认监听 `127.0.0.1:8000/mcp`,客户端使用独立 Bearer 密钥。多人 HTTP 通过身份服务进行 MCP OAuth 登录,每人绑定自己的 xAI API Key。公网接入通过 HTTPS 反向代理配置。 [多人部署说明](./docs/multi-user.md)
|
|
21
|
-
3. **公共 OAuth Client ID 说明**:默认内置的公开客户端 ID 来自 Hermes Agent(`b1a00492-073a-47ea-816f-4c329264a828`)。在浏览器授权确认页面中可能会显示该客户端标识名称。如需使用专属客户端,可通过 `XAI_OAUTH_CLIENT_ID` 环境变量配置。
|
|
22
|
-
4. **OAuth 成功不等于搜索可用**:OAuth 设备码登录成功仅代表获得 xAI 账号凭证,实际搜索能力及并发额度由 xAI 云端及订阅权益决定;登录成功不保证账号一定具备 X Search 权限。
|
|
23
|
-
5. **无引用不可作为确证**:结果标记为 `unverified` 表示缺少可识别的 X 帖子来源。
|
|
24
|
-
6. **计费与回退规则**:
|
|
25
|
-
- API Key 模式下按调用量付费(api_metered)。
|
|
26
|
-
- 显式 `oauth` 模式下仅使用订阅令牌,**绝不回退**到付费 API Key,避免产生非预期账单。
|
|
27
|
-
- `auto` 模式优先使用 API Key(如果配置),无 Key 时使用本地保存的 OAuth。
|
|
28
|
-
7. **重试消耗**。个人模式只在 OAuth 401 或带有可等待的 `Retry-After` 的 429 后允许一次重试。多人 HTTP 每次搜索只发起一次 xAI 搜索请求。
|
|
29
|
-
8. **过滤作用域限制**:xAI 接口的 `allowed_x_handles`、`excluded_x_handles`、`from_date` 和 `to_date` 过滤主要作用于关键词与语义搜索阶段,并不严格保证限制上游服务端内部的级联线程抓取(thread fetch)。
|
|
30
|
-
|
|
31
|
-
---
|
|
32
|
-
|
|
33
|
-
## npm 安装与打包
|
|
34
|
-
|
|
35
|
-
需要 Node.js 22.19.0 或更高版本。可以用 `npx` 直接运行。
|
|
36
|
-
|
|
37
|
-
```bash
|
|
38
|
-
npx --yes @scoheart/x-search-mcp@0.6.0 auth login
|
|
39
|
-
npx --yes @scoheart/x-search-mcp@0.6.0 auth status
|
|
9
|
+
```sh
|
|
10
|
+
npm install -g @scoheart/x-search-mcp
|
|
40
11
|
```
|
|
41
12
|
|
|
42
|
-
|
|
13
|
+
支持新版协议的本地客户端可以用 [stdio 配置](./examples/mcp.json)。Codex 0.172.0 通过回环 HTTP 接入,打开 `mcp_2026_07_28`。服务与 Codex 使用同一份 HTTP Bearer。
|
|
43
14
|
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
x-search-mcp
|
|
15
|
+
```sh
|
|
16
|
+
export X_SEARCH_HTTP_TOKEN="$(openssl rand -hex 32)"
|
|
17
|
+
x-search-mcp http --interactive-login
|
|
47
18
|
```
|
|
48
19
|
|
|
49
|
-
|
|
20
|
+
[Codex 配置](./examples/codex.toml) · [多人 HTTP 部署](./docs/multi-user.md)
|
|
50
21
|
|
|
51
22
|
## 凭证配置
|
|
52
23
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
# 或
|
|
59
|
-
export XAI_API_KEY_FILE="/path/to/private/xai-key.txt"
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
### 方式 2:Grok 订阅 OAuth(设备码流程)
|
|
63
|
-
|
|
64
|
-
无需购买 API Key,使用包含 X Search 权益的 xAI 账号直接在终端完成登录:
|
|
24
|
+
| 方式 | 用法 |
|
|
25
|
+
| --- | --- |
|
|
26
|
+
| xAI API | 用 `XAI_API_KEY_FILE` 指向私有密钥文件,或设置 `XAI_API_KEY` |
|
|
27
|
+
| Grok 订阅 | 运行 `x-search-mcp auth login`,或在支持表单 elicitation 的宿主里确认登录 |
|
|
28
|
+
| 多人 HTTP | 先登录 MCP 服务,再在 `/settings` 绑定自己的 xAI API key |
|
|
65
29
|
|
|
66
|
-
|
|
67
|
-
# 执行设备码登录
|
|
68
|
-
x-search-mcp auth login
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
终端将输出授权网址与用户确认码:
|
|
72
|
-
```text
|
|
73
|
-
1. Visit the authorization page: https://auth.x.ai/oauth2/device/code
|
|
74
|
-
2. Confirm code: ABCD-EFGH
|
|
75
|
-
3. Code expires at: 20:30:00
|
|
76
|
-
Waiting for browser authorization...
|
|
77
|
-
```
|
|
78
|
-
在浏览器中打开链接、输入确认码并批准后,令牌将原子写入本地配置文件:
|
|
79
|
-
- 默认路径:`~/.config/x-search-mcp/auth.json`(权限 `0600`,目录权限 `0700`)
|
|
80
|
-
- 自定义路径:可通过 `X_SEARCH_AUTH_FILE` 覆盖。
|
|
30
|
+
`X_SEARCH_AUTH_MODE` 默认为 `auto`,优先使用已配置的 API key。用 `oauth` 显式选择订阅。用 `x-search-mcp auth status` 查看状态,用 `auth logout` 清除本机登录。
|
|
81
31
|
|
|
82
32
|
### 在 agent 内完成 Grok 设备授权
|
|
83
33
|
|
|
84
|
-
|
|
85
|
-
|
|
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)
|
|
87
|
-
|
|
88
|
-
### 凭证状态与注销
|
|
89
|
-
|
|
90
|
-
```bash
|
|
91
|
-
# 查看凭证配置状态(不探测额度、不泄露密钥内容)
|
|
92
|
-
x-search-mcp auth status
|
|
93
|
-
|
|
94
|
-
# 清除本地 OAuth 令牌文件(不影响云端授权及 API Key)
|
|
95
|
-
x-search-mcp auth logout
|
|
96
|
-
```
|
|
97
|
-
|
|
98
|
-
---
|
|
99
|
-
|
|
100
|
-
## CLI 命令一览
|
|
101
|
-
|
|
102
|
-
| 命令 | 说明 |
|
|
103
|
-
|---|---|
|
|
104
|
-
| `x-search-mcp` 或 `x-search-mcp --stdio` | 默认启动 MCP stdio 服务(供 Agent 客户端调用) |
|
|
105
|
-
| `x-search-mcp http [options]` 或 `x-search-mcp --http [options]` | 启动单账号 Streamable HTTP,使用独立访问密钥 |
|
|
106
|
-
| `x-search-mcp http --multi-user` | 启动受邀多用户模式,各自绑定 xAI API Key,配置见 [多人部署说明](./docs/multi-user.md) |
|
|
107
|
-
| `x-search-mcp --help` / `x-search-mcp http --help` | 查看命令与 HTTP 参数 |
|
|
108
|
-
| `x-search-mcp auth login` | 发起 OAuth 设备码登录并在终端交互 |
|
|
109
|
-
| `x-search-mcp auth status` | 安全输出当前认证模式、Key/OAuth 就绪状态 |
|
|
110
|
-
| `x-search-mcp auth logout` | 在文件锁保护下安全删除本地 OAuth 凭据 |
|
|
111
|
-
| `x-search-mcp config` | 打印安全的标准 `mcpServers` JSON 配置(不导出密钥) |
|
|
112
|
-
| `x-search-mcp search "<query>"` | 直接在命令行测试搜索并输出结构化 JSON |
|
|
113
|
-
| `x-search-mcp logs` | 列出最近的本地调用日志路径 |
|
|
114
|
-
|
|
115
|
-
---
|
|
116
|
-
|
|
117
|
-
## 环境变量参考
|
|
118
|
-
|
|
119
|
-
| 变量名 | 默认值 | 说明 |
|
|
120
|
-
|---|---|---|
|
|
121
|
-
| `XAI_API_KEY` | - | xAI API Key(优先级高于文件) |
|
|
122
|
-
| `XAI_API_KEY_FILE` | - | 存放 API Key 的私有文件路径 |
|
|
123
|
-
| `X_SEARCH_AUTH_MODE` | `auto` | 认证模式:`auto`、`api_key`、`oauth` |
|
|
124
|
-
| `X_SEARCH_AUTH_FILE` | `~/.config/x-search-mcp/auth.json` | 本地 OAuth 凭证文件路径 |
|
|
125
|
-
| `XAI_OAUTH_CLIENT_ID` | `b1a00492-073a-47ea-816f-4c329264a828` | OAuth 公开客户端 ID |
|
|
126
|
-
| `X_SEARCH_MODEL` | `grok-4.5` | 搜索调用模型 |
|
|
127
|
-
| `X_SEARCH_DEADLINE_MS` | `90000` | 搜索共享时限(100–600000 毫秒) |
|
|
128
|
-
| `X_SEARCH_MAX_RESPONSE_BYTES` | `2097152` | 上游响应体上限(1024–16777216 字节) |
|
|
129
|
-
| `X_SEARCH_MAX_TURNS` | `4` | 内部搜索轮数(范围 1–20) |
|
|
130
|
-
| `X_SEARCH_REASONING_EFFORT`| - | 思考深度:`low` / `medium` / `high` / `xhigh` |
|
|
131
|
-
| `X_SEARCH_ENV_FILE` | - | 显式指定 `.env` 文件(通过 `process.loadEnvFile` 加载) |
|
|
132
|
-
| `X_SEARCH_LOG` | `metadata` | 个人日志模式(`metadata` / `debug` / `off`) |
|
|
133
|
-
| `X_SEARCH_LOG_DIR` | `~/.config/x-search-mcp/logs` | 调用日志目录 |
|
|
134
|
-
| `X_SEARCH_LOG_KEEP` | `100` | 最多保留的日志文件数 |
|
|
135
|
-
| `X_SEARCH_LOG_MAX_BYTES` | `65536` | 单次 debug 数据预算 |
|
|
136
|
-
| `X_SEARCH_LOG_TOTAL_BYTES` | `33554432` | 日志目录总字节数上限 |
|
|
137
|
-
| `HTTP_PROXY` / `HTTPS_PROXY` | - | 标准 HTTP/HTTPS 代理配置 |
|
|
138
|
-
|
|
139
|
-
### HTTP 服务配置
|
|
140
|
-
|
|
141
|
-
| 变量名 | 默认值 | 说明 |
|
|
142
|
-
|---|---|---|
|
|
143
|
-
| `X_SEARCH_HTTP_TOKEN` | - | HTTP MCP 的独立 Bearer 密钥;不输出到日志 |
|
|
144
|
-
| `X_SEARCH_HTTP_TOKEN_FILE` | - | 仅包含 HTTP 密钥的私有文件,启动时读取 |
|
|
145
|
-
| `X_SEARCH_HTTP_HOST` | `127.0.0.1` | 监听地址;远端接入通常由本机 HTTPS 反代转发 |
|
|
146
|
-
| `X_SEARCH_HTTP_PORT` | `8000` | TCP 端口;`0` 自动分配 |
|
|
147
|
-
| `X_SEARCH_HTTP_PATH` | `/mcp` | 规范化 URL 路径,不含查询参数或片段 |
|
|
148
|
-
| `X_SEARCH_HTTP_ALLOWED_HOSTS` | - | 额外允许的 Host 主机名,逗号分隔,不含协议或端口 |
|
|
149
|
-
| `X_SEARCH_HTTP_ALLOWED_ORIGINS` | - | 明确允许的浏览器 Origin,逗号分隔,匹配协议、主机和端口 |
|
|
150
|
-
|
|
151
|
-
同名 CLI 参数覆盖环境默认值。`--allowed-host` 与 `--allowed-origin` 可重复;提供这类参数时使用命令行列表。显式 `--token-file` 优先,否则非空 `X_SEARCH_HTTP_TOKEN` 优先于环境 token 文件。空密钥、非法路径、非法端口或不可读文件会阻止启动。
|
|
152
|
-
|
|
153
|
-
HTTP 请求体默认上限为 1 MiB。`SIGINT`/`SIGTERM` 停止服务并取消活动请求;上游超时和客户端取消持续覆盖响应体读取阶段。
|
|
34
|
+
客户端确认后,`x_search` 返回 `authorization_pending`、验证链接和短码。打开 Grok 核对账号和短码,批准后重试搜索。
|
|
154
35
|
|
|
155
|
-
|
|
36
|
+
## 工具参数规范(x_search)
|
|
156
37
|
|
|
157
|
-
|
|
38
|
+
| 参数 | 用法 |
|
|
39
|
+
| --- | --- |
|
|
40
|
+
| `query` | 检索语句,必填 |
|
|
41
|
+
| `allowed_x_handles` / `excluded_x_handles` | 互斥,各最多 10 个账号 |
|
|
42
|
+
| `from_date` / `to_date` | YYYY-MM-DD,包含起始日,截止日不包含 |
|
|
43
|
+
| `enable_image_understanding` / `enable_video_understanding` | 可选媒体分析 |
|
|
44
|
+
| `detail` | 默认 `concise`,设为 `detailed` 可取更长回答和更多证据 |
|
|
158
45
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
默认的 `metadata` 模式记录请求耗时、HTTP 状态、物理请求数和已知的上游搜索次数。多人 HTTP 关闭本地调用日志。
|
|
162
|
-
|
|
163
|
-
- 日志目录默认为 `~/.config/x-search-mcp/logs/`,新文件权限为 `0600`。
|
|
164
|
-
- 排查上游响应时可显式设 `X_SEARCH_LOG=debug`,请求和响应在写入前做凭据脱敏并按字节限制。日志总量和文件数各有上限。
|
|
165
|
-
- 用 `x-search-mcp logs` 查看最近记录。
|
|
166
|
-
|
|
167
|
-
## Agent 接入配置
|
|
168
|
-
|
|
169
|
-
### 单账号 HTTP
|
|
170
|
-
|
|
171
|
-
源码构建后执行:
|
|
172
|
-
|
|
173
|
-
```bash
|
|
174
|
-
export X_SEARCH_AUTH_MODE=oauth
|
|
175
|
-
export X_SEARCH_HTTP_TOKEN="$(openssl rand -hex 32)"
|
|
176
|
-
node bin/x-search-mcp.js http --port 8000
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
安装后可直接使用 `x-search-mcp http`。客户端选择 **Streamable HTTP**,填写 `http://127.0.0.1:8000/mcp`,请求头设为 `Authorization: Bearer <X_SEARCH_HTTP_TOKEN 的值>`。未带正确密钥返回 401。来源 Host 或 Origin 未获允许时返回 403。
|
|
180
|
-
|
|
181
|
-
单账号 HTTP 使用服务端配置的 xAI 凭据。直接回环监听可加 `--interactive-login`,启动宿主授权流程。对外部署可在服务端通过 CLI 完成登录。
|
|
182
|
-
|
|
183
|
-
若经域名代理,配置 `--allowed-host mcp.example.com`,让客户端连接 `https://mcp.example.com/mcp`。浏览器跨站调用还需显式 `--allowed-origin https://app.example.com`;非浏览器客户端可以不发送 Origin。HTTP 密钥与 Grok 凭证、npm 发布 token 分开管理。
|
|
184
|
-
|
|
185
|
-
### 1. 支持 MCP 2026-07-28 的 stdio 客户端
|
|
186
|
-
|
|
187
|
-
在目标 Agent 的配置文件中添加:
|
|
188
|
-
|
|
189
|
-
```json
|
|
190
|
-
{
|
|
191
|
-
"mcpServers": {
|
|
192
|
-
"x-search": {
|
|
193
|
-
"command": "npx",
|
|
194
|
-
"args": ["--yes", "@scoheart/x-search-mcp@0.6.0"],
|
|
195
|
-
"env": {
|
|
196
|
-
"X_SEARCH_AUTH_MODE": "auto",
|
|
197
|
-
"X_SEARCH_MODEL": "grok-4.5"
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
```
|
|
203
|
-
|
|
204
|
-
> 若安装的是本地 tarball,可改用 `"command": "x-search-mcp"`、`"args": []`,并确保客户端的 `PATH` 包含安装目录。也可以运行 `x-search-mcp config` 生成当前可执行入口的绝对路径配置。修改配置后请重启或重新加载 Agent 会话。
|
|
205
|
-
|
|
206
|
-
### 2. Codex 0.172.0
|
|
207
|
-
|
|
208
|
-
服务和 Codex 进程使用同一环境里的 HTTP 服务密钥。在本机启动服务并保持运行。
|
|
209
|
-
|
|
210
|
-
```sh
|
|
211
|
-
export X_SEARCH_HTTP_TOKEN="$(openssl rand -hex 32)"
|
|
212
|
-
x-search-mcp http --interactive-login
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
将 [Codex 示例配置](./examples/codex.toml) 合入客户端配置。该版本开启 `mcp_2026_07_28` 后可通过 Streamable HTTP 发现工具,stdio 握手仍使用旧协议。
|
|
216
|
-
|
|
217
|
-
---
|
|
218
|
-
|
|
219
|
-
## 工具参数规范 (`x_search`)
|
|
220
|
-
|
|
221
|
-
```typescript
|
|
222
|
-
interface XSearchInput {
|
|
223
|
-
query: string; // 必填,检索语句(trim 后非空,最大 16000 字符)
|
|
224
|
-
allowed_x_handles?: string[]; // 可选,白名单账号(最多 10 个,无需 @,与 excluded 互斥)
|
|
225
|
-
excluded_x_handles?: string[]; // 可选,黑名单账号(最多 10 个,无需 @,与 allowed 互斥)
|
|
226
|
-
from_date?: string; // 可选,开始日期 YYYY-MM-DD(不能晚于当天 UTC,需严格早于 to_date)
|
|
227
|
-
to_date?: string; // 可选,结束日期 YYYY-MM-DD(不包含当天)
|
|
228
|
-
enable_image_understanding?: boolean; // 可选,是否启用推文配图理解
|
|
229
|
-
enable_video_understanding?: boolean; // 可选,是否启用推文视频理解
|
|
230
|
-
detail?: 'concise' | 'detailed'; // 可选,控制回答长度和来源条数
|
|
231
|
-
}
|
|
232
|
-
```
|
|
233
|
-
|
|
234
|
-
### 返回结构示例
|
|
235
|
-
|
|
236
|
-
`structuredContent` 提供字段化的回答与证据。`complete` 表示上游完成且有 X 帖子来源,`partial` 表示上游报告结果不完整,`unverified` 表示没有可识别的 X 帖子来源。`cited_in_answer` 仅在上游提供有效的正文引用标注时出现。外部网页也可列在 `sources` 内。
|
|
237
|
-
|
|
238
|
-
```json
|
|
239
|
-
{
|
|
240
|
-
"status": "complete",
|
|
241
|
-
"model": "grok-4.5",
|
|
242
|
-
"answer": "找到一条相关公开帖子。",
|
|
243
|
-
"sources": [
|
|
244
|
-
{
|
|
245
|
-
"kind": "x_post",
|
|
246
|
-
"url": "https://x.com/Example/status/123456789",
|
|
247
|
-
"post_id": "123456789",
|
|
248
|
-
"handle": "Example",
|
|
249
|
-
"cited_in_answer": true
|
|
250
|
-
}
|
|
251
|
-
],
|
|
252
|
-
"truncated": false,
|
|
253
|
-
"usage": {
|
|
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
|
|
260
|
-
},
|
|
261
|
-
"elapsed_ms": 1640
|
|
262
|
-
}
|
|
263
|
-
```
|
|
46
|
+
`structuredContent` 返回 `answer`、去重的 `sources[]`、用量和耗时。按帖子来源的 `post_id` 与链接核对证据。`partial` 表示上游结果不完整,`unverified` 表示缺少可识别的 X 帖子来源,`truncated` 表示本地截断。
|
|
264
47
|
|
|
265
|
-
|
|
48
|
+
## 运行配置
|
|
266
49
|
|
|
267
|
-
|
|
50
|
+
- 搜索默认总时限 90 秒,上游响应上限 2 MiB。参数见 [.env.example](./.env.example)。
|
|
51
|
+
- 个人日志默认只记录耗时和计数。运行 `x-search-mcp logs` 查看,设 `X_SEARCH_LOG=debug` 开启限量调试数据。
|
|
52
|
+
- `x-search-mcp http --help` 查看监听、访问凭据和主机限制选项。交互登录和 Events 面向个人回环监听器。
|
|
268
53
|
|
|
269
|
-
|
|
54
|
+
[引用审阅和证据观察](./docs/events-and-apps.md)
|