xcrawl-mcp 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -5,9 +5,9 @@ Model Context Protocol (MCP) server for XCrawl. It exposes scraping, search, map
5
5
  ## Table of Contents
6
6
 
7
7
  - [Prerequisites](#prerequisites)
8
+ - [Remote Hosted URL](#remote-hosted-url)
8
9
  - [Quick Start (Stdio)](#quick-start-stdio)
9
10
  - [Claude Desktop Configuration](#claude-desktop-configuration)
10
- - [Cloudflare Workers Deployment](#cloudflare-workers-deployment)
11
11
  - [Authentication](#authentication)
12
12
  - [Available Tools](#available-tools)
13
13
  - [Request Defaults](#request-defaults)
@@ -20,21 +20,42 @@ Model Context Protocol (MCP) server for XCrawl. It exposes scraping, search, map
20
20
 
21
21
  - Node.js 18+
22
22
  - XCrawl API key from [xcrawl.com](https://xcrawl.com)
23
- - Cloudflare account (only for Workers deployment)
23
+
24
+ ## Remote Hosted URL
25
+
26
+ Use the hosted MCP endpoint:
27
+
28
+ ```text
29
+ https://mcp.xcrawl.com/{XCRAWL_API_KEY}/mcp
30
+ ```
31
+
32
+ You can pass the API key in the URL path:
33
+
34
+ ```text
35
+ https://mcp.xcrawl.com/{XCRAWL_API_KEY}/mcp
36
+ ```
37
+
38
+ Or via headers. Supported methods:
39
+
40
+ ```text
41
+ Authorization: Bearer {XCRAWL_API_KEY}
42
+ x-api-key: {XCRAWL_API_KEY}
43
+ x-xcrawl-api-key: {XCRAWL_API_KEY}
44
+ ```
24
45
 
25
46
  ## Quick Start (Stdio)
26
47
 
27
48
  Run directly with `npx`:
28
49
 
29
50
  ```bash
30
- XCRAWL_API_KEY=your-api-key npx -y xcrawl-mcp
51
+ XCRAWL_API_KEY=YOUR_API_KEY npx -y xcrawl-mcp
31
52
  ```
32
53
 
33
54
  Or install globally:
34
55
 
35
56
  ```bash
36
57
  npm install -g xcrawl-mcp
37
- XCRAWL_API_KEY=your-api-key xcrawl-mcp
58
+ XCRAWL_API_KEY=YOUR_API_KEY xcrawl-mcp
38
59
  ```
39
60
 
40
61
  ## Claude Desktop Configuration
@@ -43,6 +64,20 @@ Add to Claude Desktop config:
43
64
  - macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
44
65
  - Windows: `%APPDATA%\Claude\claude_desktop_config.json`
45
66
 
67
+ Use the hosted MCP endpoint:
68
+
69
+ ```json
70
+ {
71
+ "mcpServers": {
72
+ "xcrawl": {
73
+ "url": "https://mcp.xcrawl.com/{XCRAWL_API_KEY}/mcp"
74
+ }
75
+ }
76
+ }
77
+ ```
78
+
79
+ Or run locally:
80
+
46
81
  ```json
47
82
  {
48
83
  "mcpServers": {
@@ -50,26 +85,13 @@ Add to Claude Desktop config:
50
85
  "command": "npx",
51
86
  "args": ["-y", "xcrawl-mcp"],
52
87
  "env": {
53
- "XCRAWL_API_KEY": "your-api-key"
88
+ "XCRAWL_API_KEY": "YOUR_API_KEY"
54
89
  }
55
90
  }
56
91
  }
57
92
  }
58
93
  ```
59
94
 
60
- ## Cloudflare Workers Deployment
61
-
62
- ```bash
63
- git clone <your-repo>
64
- cd xcrawl-mcp
65
- npm install
66
- npm run deploy
67
- ```
68
-
69
- After deployment:
70
- - `https://xcrawl-mcp.<your-account>.workers.dev/mcp`
71
- - `https://xcrawl-mcp.<your-account>.workers.dev/health`
72
-
73
95
  ## Authentication
74
96
 
75
97
  ### Stdio mode
@@ -77,12 +99,13 @@ After deployment:
77
99
  Use environment variable:
78
100
  - `XCRAWL_API_KEY` (required)
79
101
 
80
- ### Workers mode
102
+ ### Hosted / Workers mode
81
103
 
82
- Pass API key in request headers (priority order):
83
- 1. `Authorization: Bearer <api-key>`
84
- 2. `x-api-key: <api-key>`
85
- 3. `x-xcrawl-api-key: <api-key>`
104
+ Pass API key using one of these methods:
105
+ 1. URL path: `https://mcp.xcrawl.com/{XCRAWL_API_KEY}/mcp`
106
+ 2. `Authorization: Bearer {XCRAWL_API_KEY}`
107
+ 3. `x-api-key: {XCRAWL_API_KEY}`
108
+ 4. `x-xcrawl-api-key: {XCRAWL_API_KEY}`
86
109
 
87
110
  ## Available Tools
88
111
 
@@ -94,6 +117,7 @@ Pass API key in request headers (priority order):
94
117
  | `xcrawl_map` | Discover URLs from a site |
95
118
  | `xcrawl_crawl` | Async multi-page crawl |
96
119
  | `xcrawl_check_crawl_status` | Check async crawl status |
120
+ | `xcrawl_key_status` | Check whether the current API key is valid and has remaining credits |
97
121
 
98
122
  ### `xcrawl_scrape`
99
123
 
@@ -186,6 +210,28 @@ Possible values: `pending`, `crawling`, `completed`, `failed`.
186
210
 
187
211
  Possible values: `pending`, `crawling`, `completed`, `failed`.
188
212
 
213
+ ### `xcrawl_key_status`
214
+
215
+ ```json
216
+ {}
217
+ ```
218
+
219
+ Returns key validity and current credit status, including:
220
+
221
+ - `status`
222
+ - `valid`
223
+ - `authorized`
224
+ - `has_credits`
225
+ - `is_expired`
226
+ - `can_use_tools`
227
+ - `remain_credits`
228
+ - `consumed_credits`
229
+ - `today_credits`
230
+ - `total_credits`
231
+ - `package_title`
232
+ - `next_reset_at`
233
+ - `expired_at`
234
+
189
235
  ## Request Defaults
190
236
 
191
237
  Common defaults:
@@ -208,6 +254,23 @@ Defaults may vary by API version.
208
254
  | `output.json.json_schema` | - | Optional |
209
255
  | `webhook.events` | `["started","completed","failed"]` | Optional callback events |
210
256
 
257
+ ## Preflight Checks
258
+
259
+ Before executing high-cost tools, the MCP server now performs a key and credits preflight check.
260
+
261
+ Current tools with preflight checks:
262
+
263
+ - `xcrawl_scrape`
264
+ - `xcrawl_search`
265
+ - `xcrawl_map`
266
+ - `xcrawl_crawl`
267
+
268
+ The preflight check verifies:
269
+
270
+ - the current API key is valid
271
+ - the current API key is authorized
272
+ - the account still has remaining credits
273
+
211
274
  ## Error Format
212
275
 
213
276
  Errors are returned in MCP format:
@@ -229,7 +292,7 @@ Errors are returned in MCP format:
229
292
  ```bash
230
293
  npm install
231
294
  npm run build
232
- XCRAWL_API_KEY=your-key npm run start:stdio:dev
295
+ XCRAWL_API_KEY=YOUR_API_KEY npm run start:stdio:dev
233
296
 
234
297
  npm run dev
235
298
  curl http://localhost:8787/health
@@ -0,0 +1,393 @@
1
+ # XCrawl MCP Server
2
+
3
+ > 通过 Model Context Protocol 使用 XCrawl API
4
+
5
+ XCrawl MCP Server 让您可以在支持 MCP 的客户端中直接调用 XCrawl 的网页抓取、搜索、发现与批量爬取能力。
6
+
7
+ ## 功能特性
8
+
9
+ - 网页抓取与爬取
10
+ - 搜索与发现
11
+ - 结构化提取
12
+ - 状态与额度检查
13
+ - 流式 HTTP
14
+ - 本地命令运行
15
+
16
+ ## 安装
17
+
18
+ 您可以使用我们的云端托管 URL,或在本地运行服务器。XCrawl API Key 可从 `https://dash.xcrawl.com/api-key` 获取。
19
+
20
+ ### 云端托管 URL
21
+
22
+ ```text
23
+ https://mcp.xcrawl.com/{XCRAWL_API_KEY}/mcp
24
+ ```
25
+
26
+ ### 使用 npx 运行
27
+
28
+ ```bash
29
+ XCRAWL_API_KEY=YOUR_API_KEY npx -y xcrawl-mcp
30
+ ```
31
+
32
+ ### 手动安装
33
+
34
+ ```bash
35
+ npm install -g xcrawl-mcp
36
+ ```
37
+
38
+ ### 在 Cursor 中使用
39
+
40
+ 如需查看最新的配置方式,也可以参考 Cursor 官方文档:
41
+ [Cursor MCP Server Configuration Guide](https://docs.cursor.com/context/model-context-protocol#configuring-mcp-servers)
42
+
43
+ 在 Cursor **v0.48.6** 中:
44
+
45
+ 1. 打开 Cursor 设置。
46
+ 2. 进入 `Features > MCP Servers`。
47
+ 3. 点击 `+ Add new global MCP server`。
48
+ 4. 加入以下配置:
49
+
50
+ ```json
51
+ {
52
+ "mcpServers": {
53
+ "xcrawl": {
54
+ "url": "https://mcp.xcrawl.com/{XCRAWL_API_KEY}/mcp"
55
+ }
56
+ }
57
+ }
58
+ ```
59
+
60
+ 如果当前版本或环境不支持 HTTP 方式,可使用本地 `npx`:
61
+
62
+ ```json
63
+ {
64
+ "mcpServers": {
65
+ "xcrawl": {
66
+ "command": "npx",
67
+ "args": ["-y", "xcrawl-mcp"],
68
+ "env": {
69
+ "XCRAWL_API_KEY": "YOUR_API_KEY"
70
+ }
71
+ }
72
+ }
73
+ }
74
+ ```
75
+
76
+ 在 Cursor **v0.45.6** 中:
77
+
78
+ 1. 打开 Cursor 设置。
79
+ 2. 进入 `Features > MCP Servers`。
80
+ 3. 点击 `+ Add New MCP Server`。
81
+ 4. 填入以下内容:
82
+
83
+ - Name: `xcrawl`
84
+ - Type: `command`
85
+ - Command: `env XCRAWL_API_KEY=YOUR_API_KEY npx -y xcrawl-mcp`
86
+
87
+ 如果您在 Windows 上遇到问题,也可以尝试:
88
+
89
+ ```text
90
+ cmd /c "set XCRAWL_API_KEY=YOUR_API_KEY && npx -y xcrawl-mcp"
91
+ ```
92
+
93
+ 添加完成后,刷新 MCP Server 列表即可看到 XCrawl 工具。
94
+
95
+ ### 在 VS Code 中使用
96
+
97
+ 在 VS Code 中按 `Ctrl + Shift + P`,输入并打开 `Preferences: Open User Settings (JSON)`,然后加入以下配置:
98
+
99
+ ```json
100
+ {
101
+ "mcp": {
102
+ "servers": {
103
+ "xcrawl": {
104
+ "url": "https://mcp.xcrawl.com/{XCRAWL_API_KEY}/mcp"
105
+ }
106
+ }
107
+ }
108
+ }
109
+ ```
110
+
111
+ 如果希望在当前工作区共享配置,也可以写入 `.vscode/mcp.json` 或客户端要求的 MCP 配置文件。
112
+
113
+ 如果当前 VS Code MCP 环境不支持 HTTP 方式,可使用本地 `npx`:
114
+
115
+ ```json
116
+ {
117
+ "mcp": {
118
+ "servers": {
119
+ "xcrawl": {
120
+ "command": "npx",
121
+ "args": ["-y", "xcrawl-mcp"],
122
+ "env": {
123
+ "XCRAWL_API_KEY": "YOUR_API_KEY"
124
+ }
125
+ }
126
+ }
127
+ }
128
+ }
129
+ ```
130
+
131
+ 保存后,刷新 MCP 服务列表或重启 VS Code。
132
+
133
+ **注意:** 部分用户反馈,在 VS Code 中直接添加 MCP Server 时,可能会因为 JSON schema 校验问题而加载失败。这一问题会影响多个 MCP 工具,XCrawl 也可能受到影响。
134
+
135
+ **临时解决方案:** 可以先关闭 VS Code 的 JSON 验证,再尝试加载 MCP Server。
136
+
137
+ 参考链接:
138
+ - [microsoft/vscode#155379](https://github.com/microsoft/vscode/issues/155379)
139
+ - [directus/directus#25906 (comment)](https://github.com/directus/directus/issues/25906#issuecomment-3369169513)
140
+
141
+ XCrawl MCP Server 本身仍可正常工作;这一问题主要发生在通过 VS Code 的 MCP Server 列表直接添加时。后续如果 VS Code 更新了相关 schema 校验,我们会补充更明确的说明。
142
+
143
+ ### 在 Claude Desktop 中使用
144
+
145
+ 打开 Claude Desktop 配置文件:
146
+
147
+ - macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`
148
+ - Windows: `%APPDATA%\Claude\claude_desktop_config.json`
149
+
150
+ 加入以下配置:
151
+
152
+ ```json
153
+ {
154
+ "mcpServers": {
155
+ "xcrawl": {
156
+ "url": "https://mcp.xcrawl.com/{XCRAWL_API_KEY}/mcp"
157
+ }
158
+ }
159
+ }
160
+ ```
161
+
162
+ 如果您收到“无法连接到 MCP 服务器”之类的错误,可能是当前 Claude Desktop 版本不支持 HTTP 方式。可以改用本地 `npx` 方式,这需要先安装 [**Node.js**](https://nodejs.org/)。
163
+
164
+ ```json
165
+ {
166
+ "mcpServers": {
167
+ "xcrawl": {
168
+ "command": "npx",
169
+ "args": ["-y", "xcrawl-mcp"],
170
+ "env": {
171
+ "XCRAWL_API_KEY": "YOUR_API_KEY"
172
+ }
173
+ }
174
+ }
175
+ }
176
+ ```
177
+
178
+ 如果出现 `spawn npx ENOENT` 错误,通常表示 Node.js 尚未安装,或未加入系统 PATH。请从 [nodejs.org](https://nodejs.org) 安装 Node.js(LTS 版本),然后完全重启 Claude Desktop。在 Windows 上,也可以在命令提示符中运行 `where npx`,并将返回的完整路径,例如 `C:\\Program Files\\nodejs\\npx.cmd`,填入 `command`。
179
+
180
+ ### 在 Claude Code 中使用
181
+
182
+ 在终端中运行:
183
+
184
+ ```bash
185
+ claude mcp add xcrawl --url https://mcp.xcrawl.com/{XCRAWL_API_KEY}/mcp
186
+ ```
187
+
188
+ 如果当前环境不支持 HTTP 方式,可使用本地命令方式:
189
+
190
+ ```bash
191
+ claude mcp add xcrawl -e XCRAWL_API_KEY=YOUR_API_KEY -- npx -y xcrawl-mcp
192
+ ```
193
+
194
+ ### 在 Windsurf 中使用
195
+
196
+ 打开 Windsurf 设置,进入 `Tools > Configure > View raw config`,然后加入以下配置:
197
+
198
+ ```json
199
+ {
200
+ "mcpServers": {
201
+ "xcrawl": {
202
+ "serverUrl": "https://mcp.xcrawl.com/{XCRAWL_API_KEY}/mcp"
203
+ }
204
+ }
205
+ }
206
+ ```
207
+
208
+ 如果当前环境不支持 HTTP 方式,可使用本地 `npx`:
209
+
210
+ ```json
211
+ {
212
+ "mcpServers": {
213
+ "xcrawl": {
214
+ "command": "npx",
215
+ "args": ["-y", "xcrawl-mcp"],
216
+ "env": {
217
+ "XCRAWL_API_KEY": "YOUR_API_KEY"
218
+ }
219
+ }
220
+ }
221
+ }
222
+ ```
223
+
224
+ ### 在 Google Antigravity 中使用
225
+
226
+ Google Antigravity 支持在 Agent 界面中直接配置 MCP Server。
227
+
228
+ 1. 打开编辑器中的 Agent 侧边栏,或进入 Agent Manager。
229
+ 2. 点击 `...`,选择 `MCP Servers`。
230
+ 3. 选择 `View raw config`,打开本地 `mcp_config.json`。
231
+ 4. 加入以下配置:
232
+
233
+ ```json
234
+ {
235
+ "mcpServers": {
236
+ "xcrawl": {
237
+ "command": "npx",
238
+ "args": ["-y", "xcrawl-mcp"],
239
+ "env": {
240
+ "XCRAWL_API_KEY": "YOUR_API_KEY"
241
+ }
242
+ }
243
+ }
244
+ }
245
+ ```
246
+
247
+ 5. 保存后,在 Antigravity 的 MCP 界面点击 `Refresh`,即可看到 XCrawl 工具。
248
+
249
+ ## 可用工具
250
+
251
+ ### 1. 抓取工具 `xcrawl_scrape`
252
+
253
+ 抓取单个网页内容,支持多种输出格式。
254
+ 详细参数请参考:<https://docs.xcrawl.com/doc/features/scrape/>
255
+
256
+ ```json
257
+ {
258
+ "name": "xcrawl_scrape",
259
+ "arguments": {
260
+ "url": "https://example.com",
261
+ "output": {
262
+ "formats": ["markdown", "screenshot"]
263
+ }
264
+ }
265
+ }
266
+ ```
267
+
268
+ ### 2. 搜索工具 `xcrawl_search`
269
+
270
+ 用于根据关键词、地区、语言等参数获取搜索结果,并支持高级 Google SERP 参数。
271
+ 详情请参考:<https://docs.xcrawl.com/doc/features/search/>
272
+
273
+ ```json
274
+ {
275
+ "name": "xcrawl_search",
276
+ "arguments": {
277
+ "query": "latest AI news",
278
+ "location": "New York",
279
+ "language": "en",
280
+ "limit": 10,
281
+ "serp_options": {
282
+ "tbs": "qdr:w",
283
+ "safe": 1
284
+ }
285
+ }
286
+ }
287
+ ```
288
+
289
+ ### 3. 发现工具 `xcrawl_map`
290
+
291
+ 用于快速获取站点内的 URL 列表。
292
+ 详情请参考:<https://docs.xcrawl.com/doc/features/map/>
293
+
294
+ ```json
295
+ {
296
+ "name": "xcrawl_map",
297
+ "arguments": {
298
+ "url": "https://example.com",
299
+ "filter": "blog/.*",
300
+ "limit": 1000,
301
+ "include_subdomains": true,
302
+ "ignore_query_parameters": true
303
+ }
304
+ }
305
+ ```
306
+
307
+ ### 4. 批量爬取工具 `xcrawl_crawl`
308
+
309
+ 用于按规则批量抓取站点页面。XCrawl 会根据指定的 URL 在站内发现所有链接并依次抓取。
310
+ 详情请参考:<https://docs.xcrawl.com/doc/features/crawl/>
311
+
312
+ ```json
313
+ {
314
+ "name": "xcrawl_crawl",
315
+ "arguments": {
316
+ "url": "https://example.com",
317
+ "output": {
318
+ "formats": ["markdown"]
319
+ }
320
+ }
321
+ }
322
+ ```
323
+
324
+ ### 5. 状态检查工具 `xcrawl_key_status`
325
+
326
+ 检查当前运行时 API Key 是否有效、是否已授权、是否还有可用积分,以及当前是否允许继续调用工具。
327
+
328
+ ```json
329
+ {
330
+ "name": "xcrawl_key_status",
331
+ "arguments": {}
332
+ }
333
+ ```
334
+
335
+ ### 6. 检查抓取状态 `xcrawl_check_status`
336
+
337
+ 查询异步抓取任务状态。
338
+
339
+ ```json
340
+ {
341
+ "name": "xcrawl_check_status",
342
+ "arguments": {
343
+ "scrape_id": "abc-123-def-456"
344
+ }
345
+ }
346
+ ```
347
+
348
+ ### 7. 检查批量爬取状态 `xcrawl_check_crawl_status`
349
+
350
+ 查询异步批量爬取任务状态。
351
+
352
+ ```json
353
+ {
354
+ "name": "xcrawl_check_crawl_status",
355
+ "arguments": {
356
+ "crawl_id": "xyz-789-abc-012"
357
+ }
358
+ }
359
+ ```
360
+
361
+ ## 错误处理
362
+
363
+ 错误按 MCP 工具格式返回,例如:
364
+
365
+ ```json
366
+ {
367
+ "content": [
368
+ {
369
+ "type": "text",
370
+ "text": "Error: XCrawl API error: 401 Unauthorized - Invalid API key"
371
+ }
372
+ ],
373
+ "isError": true
374
+ }
375
+ ```
376
+
377
+ ## 健康检查
378
+
379
+ 可通过以下地址做健康检查:
380
+
381
+ ```bash
382
+ curl https://mcp.xcrawl.com/health
383
+ ```
384
+
385
+ 成功时返回:
386
+
387
+ ```text
388
+ OK
389
+ ```
390
+
391
+ ## 许可证
392
+
393
+ MIT
@@ -0,0 +1,6 @@
1
+ import type { XCrawlKeyStatusResponse } from "../types.js";
2
+ export declare function fetchXCrawlKeyStatus(apiKey: string): Promise<XCrawlKeyStatusResponse>;
3
+ export declare function formatKeyStatusResponse(response: XCrawlKeyStatusResponse): string;
4
+ export declare function requiresCreditPreflight(toolName: string): boolean;
5
+ export declare function assertXCrawlToolPreflight(apiKey: string, toolName: string): Promise<void>;
6
+ //# sourceMappingURL=status.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../src/core/status.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAA6C,MAAM,aAAa,CAAC;AAiFtG,wBAAsB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,uBAAuB,CAAC,CAsD3F;AAED,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,uBAAuB,GAAG,MAAM,CAEjF;AAED,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEjE;AAED,wBAAsB,yBAAyB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAgB/F"}