@scoheart/x-search-mcp 0.4.0 → 0.6.1
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 +18 -76
- package/THIRD_PARTY_NOTICES.md +4 -0
- package/TOOL.md +32 -268
- package/dist/evidence-licenses.txt +791 -0
- package/dist/evidence.html +170 -0
- package/dist/package.json +10 -3
- package/dist/src/auth.d.ts.map +1 -1
- package/dist/src/auth.js +6 -11
- 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 +38 -29
- 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 +15 -41
- package/dist/src/device-login.d.ts.map +1 -1
- package/dist/src/device-login.js +101 -63
- package/dist/src/device-login.js.map +1 -1
- 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 +2 -1
- package/dist/src/multi-user/service.js.map +1 -1
- package/dist/src/search-input.d.ts +5 -17
- package/dist/src/search-input.d.ts.map +1 -1
- package/dist/src/search-input.js +5 -8
- package/dist/src/search-input.js.map +1 -1
- package/dist/src/search-response.d.ts +25 -5
- package/dist/src/search-response.d.ts.map +1 -1
- package/dist/src/search-response.js +97 -94
- package/dist/src/search-response.js.map +1 -1
- package/dist/src/search.d.ts +6 -3
- package/dist/src/search.d.ts.map +1 -1
- package/dist/src/search.js +131 -184
- package/dist/src/search.js.map +1 -1
- package/dist/src/server.d.ts +7 -10
- package/dist/src/server.d.ts.map +1 -1
- package/dist/src/server.js +109 -95
- package/dist/src/server.js.map +1 -1
- package/dist/src/tool-contract.d.ts +159 -126
- package/dist/src/tool-contract.d.ts.map +1 -1
- package/dist/src/tool-contract.js +78 -73
- package/dist/src/tool-contract.js.map +1 -1
- 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 +28 -0
- package/examples/codex.toml +6 -7
- package/examples/mcp.json +2 -6
- package/package.json +10 -3
- package/server.json +34 -0
- package/src/auth.ts +6 -11
- package/src/call-log.ts +39 -30
- package/src/cli.ts +26 -19
- package/src/config.ts +11 -13
- package/src/device-login.ts +107 -71
- 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 +2 -1
- package/src/search-input.ts +5 -9
- package/src/search-response.ts +90 -95
- package/src/search.ts +126 -180
- package/src/server.ts +115 -104
- package/src/tool-contract.ts +82 -76
- 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
|
@@ -1,101 +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 Codex, Pi, or another local MCP client | [Local stdio](#connect-a-local-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**.
|
|
19
|
-
|
|
20
|
-
```sh
|
|
21
|
-
npm install --global @scoheart/x-search-mcp
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
Save your xAI API key in a private file and set `XAI_API_KEY_FILE`, or supply it through `XAI_API_KEY`. Then run a search from the terminal.
|
|
25
|
-
|
|
26
|
-
```sh
|
|
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
|
-
```
|
|
30
|
-
|
|
31
|
-
For a personal Grok subscription, sign in with the device code and explicitly select OAuth for the test. X Search access depends on your account's subscription entitlements.
|
|
9
|
+
Requires Node.js 22.19+ and an MCP 2026-07-28 client.
|
|
32
10
|
|
|
33
11
|
```sh
|
|
34
|
-
x-search-mcp
|
|
35
|
-
x-search-mcp auth status
|
|
36
|
-
x-search-mcp search "What did @SpaceX post about Starship this week?" --auth oauth
|
|
12
|
+
npm install -g @scoheart/x-search-mcp
|
|
37
13
|
```
|
|
38
14
|
|
|
39
|
-
|
|
15
|
+
Set `XAI_API_KEY_FILE` to a private key file, or run `x-search-mcp auth login` with an eligible Grok subscription.
|
|
40
16
|
|
|
41
|
-
## Connect
|
|
17
|
+
## Connect
|
|
42
18
|
|
|
43
|
-
|
|
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.
|
|
44
20
|
|
|
45
21
|
```sh
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
pi mcp add x-search -- x-search-mcp --stdio
|
|
22
|
+
export X_SEARCH_HTTP_TOKEN="$(openssl rand -hex 32)"
|
|
23
|
+
x-search-mcp http --interactive-login
|
|
49
24
|
```
|
|
50
25
|
|
|
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-设备授权)
|
|
26
|
+
See [multi-user HTTP](./docs/multi-user.md) for shared deployments.
|
|
54
27
|
|
|
55
|
-
|
|
28
|
+
## Apps and Events
|
|
56
29
|
|
|
57
|
-
|
|
30
|
+
- **Apps** lets you filter, open, and select sources to add to the conversation.
|
|
31
|
+
- **Events** delivers new post evidence from bounded watches. Start a personal listener with `--events`.
|
|
58
32
|
|
|
59
|
-
|
|
33
|
+
[Apps and Events guide](./docs/events-and-apps.md)
|
|
60
34
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
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.
|
|
35
|
+
## Develop
|
|
64
36
|
|
|
65
37
|
```sh
|
|
66
|
-
x-search-mcp http --token-file /absolute/path/to/mcp-token
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
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-服务配置).
|
|
70
|
-
|
|
71
|
-
### Multi-user HTTP
|
|
72
|
-
|
|
73
|
-
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.
|
|
74
|
-
|
|
75
|
-
```sh
|
|
76
|
-
x-search-mcp http --multi-user --port 8000
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
See the [multi-user deployment guide](./docs/multi-user.md) for issuer setup, KMS permissions, reverse-proxy configuration, and Codex and Pi login commands. Grok subscription login is available in the personal modes.
|
|
80
|
-
|
|
81
|
-
## Results and logs
|
|
82
|
-
|
|
83
|
-
- `x_search` accepts a query, optional X account filters, and a date range. See the [tool parameters](./TOOL.md#工具参数规范-x_search).
|
|
84
|
-
- Results include the answer, citations, and available usage information. A result marked `degraded: true` lacks source links. Incomplete xAI responses carry a warning.
|
|
85
|
-
- By default, stdio and single-account HTTP save local call logs under `~/.config/x-search-mcp/logs/`. Multi-user HTTP disables those logs.
|
|
86
|
-
|
|
87
|
-
## Development
|
|
88
|
-
|
|
89
|
-
```sh
|
|
90
|
-
git clone https://github.com/Scoheart/x-search-mcp.git
|
|
91
|
-
cd x-search-mcp
|
|
92
38
|
npm ci
|
|
93
39
|
npm test
|
|
94
40
|
npm run verify:package
|
|
95
41
|
```
|
|
96
42
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
## License
|
|
100
|
-
|
|
101
|
-
[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/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,290 +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
|
-
- **来源与降级感知**:提取结构化 citations 与正文 inline_citations。若上游无有效引用来源,自动标记 `degraded: true`。
|
|
13
|
-
- **原生双传输**:默认 stdio;`http` / `--http` 使用官方 SDK 的无状态 Streamable HTTP,兼容 2026 与 2025 两代协议。
|
|
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. **无引用不可作为确证**:当结果标记为 `has_citations: false` / `degraded: true` 时,表示上游未返回任何经过验证的 URL 引用,该回答不可作为来源充分的 X 检索事实依据。
|
|
24
|
-
6. **计费与回退规则**:
|
|
25
|
-
- API Key 模式下按调用量付费(api_metered)。
|
|
26
|
-
- 显式 `oauth` 模式下仅使用订阅令牌,**绝不回退**到付费 API Key,避免产生非预期账单。
|
|
27
|
-
- `auto` 模式优先使用 API Key(如果配置),无 Key 时使用本地保存的 OAuth。
|
|
28
|
-
7. **重试消耗**。stdio 和单账号 HTTP 遇到网络波动或 5xx 错误时可执行有限次数退避重试,可能重复消耗上游额度。多人 HTTP 每次搜索只发起一次上游请求。
|
|
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.4.0 auth login
|
|
39
|
-
npx --yes @scoheart/x-search-mcp@0.4.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 账号直接在终端完成登录:
|
|
65
|
-
|
|
66
|
-
```bash
|
|
67
|
-
# 执行设备码登录
|
|
68
|
-
x-search-mcp auth login
|
|
69
|
-
```
|
|
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 |
|
|
70
29
|
|
|
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
|
-
2. `x_search_login` 返回 `pending`、官方验证链接、用户短码和有效期。用户在浏览器核对账号与短码并批准本次授权。原 stdio 进程在后台轮询,等待期间重复调用复用同一设备码。
|
|
86
|
-
3. 批准后,agent 调用 `x_search_auth_status`。最近一次流程到达 `authorized` 表示令牌已经保存,可以重试原搜索。`oauth_state` 描述本机缓存的凭证有效期,实际搜索仍取决于 xAI 订阅权益。
|
|
87
|
-
|
|
88
|
-
令牌和用于后端换取令牌的 `device_code` 留在服务端。stdio 的这两个工具使用本机 Grok 设备授权。单账号 HTTP 使用独立的 MCP Bearer 密钥,多人 HTTP 使用 MCP OAuth 和独立的 API Key 绑定。 [MCP Authorization](https://modelcontextprotocol.io/specification/2026-07-28/basic/authorization) · [RFC 8628](https://www.rfc-editor.org/rfc/rfc8628.html)
|
|
89
|
-
|
|
90
|
-
### 凭证状态与注销
|
|
91
|
-
|
|
92
|
-
```bash
|
|
93
|
-
# 查看凭证配置状态(不探测额度、不泄露密钥内容)
|
|
94
|
-
x-search-mcp auth status
|
|
95
|
-
|
|
96
|
-
# 清除本地 OAuth 令牌文件(不影响云端授权及 API Key)
|
|
97
|
-
x-search-mcp auth logout
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
---
|
|
101
|
-
|
|
102
|
-
## CLI 命令一览
|
|
103
|
-
|
|
104
|
-
| 命令 | 说明 |
|
|
105
|
-
|---|---|
|
|
106
|
-
| `x-search-mcp` 或 `x-search-mcp --stdio` | 默认启动 MCP stdio 服务(供 Agent 客户端调用) |
|
|
107
|
-
| `x-search-mcp http [options]` 或 `x-search-mcp --http [options]` | 启动单账号 Streamable HTTP,使用独立访问密钥 |
|
|
108
|
-
| `x-search-mcp http --multi-user` | 启动受邀多用户模式,各自绑定 xAI API Key,配置见 [多人部署说明](./docs/multi-user.md) |
|
|
109
|
-
| `x-search-mcp --help` / `x-search-mcp http --help` | 查看命令与 HTTP 参数 |
|
|
110
|
-
| `x-search-mcp auth login` | 发起 OAuth 设备码登录并在终端交互 |
|
|
111
|
-
| `x-search-mcp auth status` | 安全输出当前认证模式、Key/OAuth 就绪状态 |
|
|
112
|
-
| `x-search-mcp auth logout` | 在文件锁保护下安全删除本地 OAuth 凭据 |
|
|
113
|
-
| `x-search-mcp config` | 打印安全的标准 `mcpServers` JSON 配置(不导出密钥) |
|
|
114
|
-
| `x-search-mcp search "<query>"` | 直接在命令行测试搜索并输出结构化 JSON |
|
|
115
|
-
| `x-search-mcp logs` | 列出最近的本地调用日志路径 |
|
|
116
|
-
|
|
117
|
-
---
|
|
118
|
-
|
|
119
|
-
## 环境变量参考
|
|
120
|
-
|
|
121
|
-
| 变量名 | 默认值 | 说明 |
|
|
122
|
-
|---|---|---|
|
|
123
|
-
| `XAI_API_KEY` | - | xAI API Key(优先级高于文件) |
|
|
124
|
-
| `XAI_API_KEY_FILE` | - | 存放 API Key 的私有文件路径 |
|
|
125
|
-
| `X_SEARCH_AUTH_MODE` | `auto` | 认证模式:`auto`、`api_key`、`oauth` |
|
|
126
|
-
| `X_SEARCH_AUTH_FILE` | `~/.config/x-search-mcp/auth.json` | 本地 OAuth 凭证文件路径 |
|
|
127
|
-
| `XAI_OAUTH_CLIENT_ID` | `b1a00492-073a-47ea-816f-4c329264a828` | OAuth 公开客户端 ID |
|
|
128
|
-
| `X_SEARCH_MODEL` | `grok-4.5` | 搜索调用模型 |
|
|
129
|
-
| `X_SEARCH_TIMEOUT_SECONDS` | `180` | 请求超时时间(秒,范围 5–600) |
|
|
130
|
-
| `X_SEARCH_RETRIES` | `2` | stdio 和单账号 HTTP 的失败重试次数(网络/5xx,范围 0–3) |
|
|
131
|
-
| `X_SEARCH_MAX_TURNS` | `4` | 内部搜索轮数(范围 1–20) |
|
|
132
|
-
| `X_SEARCH_REASONING_EFFORT`| - | 思考深度:`low` / `medium` / `high` / `xhigh` |
|
|
133
|
-
| `X_SEARCH_ENV_FILE` | - | 显式指定 `.env` 文件(通过 `process.loadEnvFile` 加载) |
|
|
134
|
-
| `X_SEARCH_LOG` | `on` | stdio 和单账号 HTTP 是否保存调用日志(`on` / `off`) |
|
|
135
|
-
| `X_SEARCH_LOG_DIR` | `~/.config/x-search-mcp/logs` | 调用日志目录 |
|
|
136
|
-
| `X_SEARCH_LOG_KEEP` | `100` | 保留最近多少份日志;`0` 表示不清理 |
|
|
137
|
-
| `X_SEARCH_LOG_MAX_BYTES` | `8388608` | 单次原始响应写入上限;超出后截断并标记 |
|
|
138
|
-
| `HTTP_PROXY` / `HTTPS_PROXY` | - | 标准 HTTP/HTTPS 代理配置 |
|
|
139
|
-
|
|
140
|
-
### HTTP 服务配置
|
|
141
|
-
|
|
142
|
-
| 变量名 | 默认值 | 说明 |
|
|
143
|
-
|---|---|---|
|
|
144
|
-
| `X_SEARCH_HTTP_TOKEN` | - | HTTP MCP 的独立 Bearer 密钥;不输出到日志 |
|
|
145
|
-
| `X_SEARCH_HTTP_TOKEN_FILE` | - | 仅包含 HTTP 密钥的私有文件,启动时读取 |
|
|
146
|
-
| `X_SEARCH_HTTP_HOST` | `127.0.0.1` | 监听地址;远端接入通常由本机 HTTPS 反代转发 |
|
|
147
|
-
| `X_SEARCH_HTTP_PORT` | `8000` | TCP 端口;`0` 自动分配 |
|
|
148
|
-
| `X_SEARCH_HTTP_PATH` | `/mcp` | 规范化 URL 路径,不含查询参数或片段 |
|
|
149
|
-
| `X_SEARCH_HTTP_ALLOWED_HOSTS` | - | 额外允许的 Host 主机名,逗号分隔,不含协议或端口 |
|
|
150
|
-
| `X_SEARCH_HTTP_ALLOWED_ORIGINS` | - | 明确允许的浏览器 Origin,逗号分隔,匹配协议、主机和端口 |
|
|
34
|
+
客户端确认后,`x_search` 返回 `authorization_pending`、验证链接和短码。打开 Grok 核对账号和短码,批准后重试搜索。
|
|
151
35
|
|
|
152
|
-
|
|
36
|
+
## 工具参数规范(x_search)
|
|
153
37
|
|
|
154
|
-
|
|
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` 可取更长回答和更多证据 |
|
|
155
45
|
|
|
156
|
-
|
|
46
|
+
`structuredContent` 返回 `answer`、去重的 `sources[]`、用量和耗时。按帖子来源的 `post_id` 与链接核对证据。`partial` 表示上游结果不完整,`unverified` 表示缺少可识别的 X 帖子来源,`truncated` 表示本地截断。
|
|
157
47
|
|
|
158
|
-
|
|
48
|
+
## 运行配置
|
|
159
49
|
|
|
160
|
-
|
|
50
|
+
- 搜索默认总时限 90 秒,上游响应上限 2 MiB。参数见 [.env.example](./.env.example)。
|
|
51
|
+
- 个人日志默认只记录耗时和计数。运行 `x-search-mcp logs` 查看,设 `X_SEARCH_LOG=debug` 开启限量调试数据。
|
|
52
|
+
- `x-search-mcp http --help` 查看监听、访问凭据和主机限制选项。交互登录和 Events 面向个人回环监听器。
|
|
161
53
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
- 默认目录:`~/.config/x-search-mcp/logs/`
|
|
165
|
-
- 文件权限:`0600`,目录权限:`0700`
|
|
166
|
-
- 字段:`request`、`attempts[].raw_response`、顶层 `raw_response`(最后一次尝试)
|
|
167
|
-
- 凭证处理:不记录 `Authorization`;`access_token`、`api_key` 等字段以及 `Bearer` / `xai-` 形态的字符串会替换成 `[redacted]`
|
|
168
|
-
- 失败调用也会写日志。HTTP 错误正文只进本地文件,不回传给 MCP 客户端
|
|
169
|
-
- 查看最近日志:`x-search-mcp logs`
|
|
170
|
-
|
|
171
|
-
日志写入失败不会让搜索失败;结果的 `warnings` 会说明日志没写上。
|
|
172
|
-
|
|
173
|
-
## Agent 接入配置
|
|
174
|
-
|
|
175
|
-
### 单账号 HTTP
|
|
176
|
-
|
|
177
|
-
源码构建后执行:
|
|
178
|
-
|
|
179
|
-
```bash
|
|
180
|
-
export X_SEARCH_AUTH_MODE=oauth
|
|
181
|
-
export X_SEARCH_HTTP_TOKEN="$(openssl rand -hex 32)"
|
|
182
|
-
node bin/x-search-mcp.js http --port 8000
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
安装后可直接使用 `x-search-mcp http`。客户端选择 **Streamable HTTP**,填写 `http://127.0.0.1:8000/mcp`,请求头设为 `Authorization: Bearer <X_SEARCH_HTTP_TOKEN 的值>`。未带正确密钥返回 401。来源 Host 或 Origin 未获允许时返回 403。
|
|
186
|
-
|
|
187
|
-
单账号 HTTP 使用同一份本机 Grok 凭证和调用日志。其搜索同时支持新旧 MCP 协议,设备授权可在服务端运行 CLI 进行。
|
|
188
|
-
|
|
189
|
-
若经域名代理,配置 `--allowed-host mcp.example.com`,让客户端连接 `https://mcp.example.com/mcp`。浏览器跨站调用还需显式 `--allowed-origin https://app.example.com`;非浏览器客户端可以不发送 Origin。HTTP 密钥与 Grok 凭证、npm 发布 token 分开管理。
|
|
190
|
-
|
|
191
|
-
### 1. 通用 mcpServers JSON(Claude Desktop / Cline / Cursor 等)
|
|
192
|
-
|
|
193
|
-
在目标 Agent 的配置文件中添加:
|
|
194
|
-
|
|
195
|
-
```json
|
|
196
|
-
{
|
|
197
|
-
"mcpServers": {
|
|
198
|
-
"x-search": {
|
|
199
|
-
"command": "npx",
|
|
200
|
-
"args": ["--yes", "@scoheart/x-search-mcp@0.4.0"],
|
|
201
|
-
"env": {
|
|
202
|
-
"X_SEARCH_AUTH_MODE": "auto",
|
|
203
|
-
"X_SEARCH_MODEL": "grok-4.5"
|
|
204
|
-
},
|
|
205
|
-
"timeout": 600
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
```
|
|
210
|
-
|
|
211
|
-
> 若安装的是本地 tarball,可改用 `"command": "x-search-mcp"`、`"args": []`,并确保客户端的 `PATH` 包含安装目录。也可以运行 `x-search-mcp config` 生成当前可执行入口的绝对路径配置。修改配置后请重启或重新加载 Agent 会话。Pi 使用 `--no-mcp` 启动时不会连接 MCP 服务。
|
|
212
|
-
|
|
213
|
-
### 2. Codex 配置 (`~/.codex/config.toml`)
|
|
214
|
-
|
|
215
|
-
```toml
|
|
216
|
-
[mcp_servers.x-search]
|
|
217
|
-
command = "npx"
|
|
218
|
-
args = ["--yes", "@scoheart/x-search-mcp@0.4.0"]
|
|
219
|
-
tool_timeout_sec = 600
|
|
220
|
-
|
|
221
|
-
[mcp_servers.x-search.env]
|
|
222
|
-
X_SEARCH_AUTH_MODE = "auto"
|
|
223
|
-
X_SEARCH_MODEL = "grok-4.5"
|
|
224
|
-
```
|
|
225
|
-
|
|
226
|
-
---
|
|
227
|
-
|
|
228
|
-
## 工具参数规范 (`x_search`)
|
|
229
|
-
|
|
230
|
-
```typescript
|
|
231
|
-
interface XSearchInput {
|
|
232
|
-
query: string; // 必填,检索语句(trim 后非空,最大 16000 字符)
|
|
233
|
-
allowed_x_handles?: string[]; // 可选,白名单账号(最多 10 个,无需 @,与 excluded 互斥)
|
|
234
|
-
excluded_x_handles?: string[]; // 可选,黑名单账号(最多 10 个,无需 @,与 allowed 互斥)
|
|
235
|
-
from_date?: string; // 可选,开始日期 YYYY-MM-DD(不能晚于当天 UTC,需严格早于 to_date)
|
|
236
|
-
to_date?: string; // 可选,结束日期 YYYY-MM-DD(不包含当天)
|
|
237
|
-
enable_image_understanding?: boolean; // 可选,是否启用推文配图理解
|
|
238
|
-
enable_video_understanding?: boolean; // 可选,是否启用推文视频理解
|
|
239
|
-
auth_mode?: 'auto' | 'api_key' | 'oauth'; // 可选,仅本地 stdio 和单账号 HTTP
|
|
240
|
-
}
|
|
241
|
-
```
|
|
242
|
-
|
|
243
|
-
### 返回结构示例
|
|
244
|
-
|
|
245
|
-
客户端在 `tools/list` 能看到结果 schema。同一结果同时写入 `structuredContent` 和 JSON 文本。`search_execution: "observed"` 表示上游返回了 X Search 调用或 X 帖子/账号获取计数。判断回答的来源覆盖情况时检查 `citations` 和 `degraded`。当上游报告结果不完整时,`warnings` 会提示覆盖范围有限。内联引用的位置来自上游原始文本。
|
|
246
|
-
|
|
247
|
-
```json
|
|
248
|
-
{
|
|
249
|
-
"success": true,
|
|
250
|
-
"provider": "xai",
|
|
251
|
-
"tool": "x_search",
|
|
252
|
-
"model": "grok-4.5",
|
|
253
|
-
"query": "OpenAI Sora news",
|
|
254
|
-
"credential_source": "oauth",
|
|
255
|
-
"billing_mode": "subscription_oauth",
|
|
256
|
-
"answer": "最新动态包括...",
|
|
257
|
-
"citations": [
|
|
258
|
-
"https://x.com/OpenAI/status/123456789"
|
|
259
|
-
],
|
|
260
|
-
"inline_citations": [
|
|
261
|
-
{
|
|
262
|
-
"url": "https://x.com/OpenAI/status/123456789",
|
|
263
|
-
"title": "OpenAI on X",
|
|
264
|
-
"start_index": 12,
|
|
265
|
-
"end_index": 35
|
|
266
|
-
}
|
|
267
|
-
],
|
|
268
|
-
"has_citations": true,
|
|
269
|
-
"degraded": false,
|
|
270
|
-
"degraded_reason": null,
|
|
271
|
-
"search_execution": "observed",
|
|
272
|
-
"server_side_calls": [
|
|
273
|
-
{
|
|
274
|
-
"call_id": "xs_123456",
|
|
275
|
-
"name": "x_keyword_search",
|
|
276
|
-
"arguments": { "query": "OpenAI Sora" }
|
|
277
|
-
}
|
|
278
|
-
],
|
|
279
|
-
"response_status": "completed",
|
|
280
|
-
"incomplete_details": null,
|
|
281
|
-
"usage": {
|
|
282
|
-
"prompt_tokens": 800,
|
|
283
|
-
"completion_tokens": 350
|
|
284
|
-
},
|
|
285
|
-
"log_file": "/Users/username/.config/x-search-mcp/logs/call-20260814T120000000Z-ab12cd.json",
|
|
286
|
-
"warnings": [
|
|
287
|
-
"OAuth subscription search availability and quota are determined upstream by xAI; successful login does not guarantee search availability."
|
|
288
|
-
]
|
|
289
|
-
}
|
|
290
|
-
```
|
|
54
|
+
[引用审阅和证据观察](./docs/events-and-apps.md)
|