xcrawl-mcp 1.0.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/.editorconfig +12 -0
- package/.env.example +3 -0
- package/.prettierrc +6 -0
- package/README.md +244 -0
- package/claude.md +295 -0
- package/dist/core/crawl.d.ts +246 -0
- package/dist/core/crawl.d.ts.map +1 -0
- package/dist/core/crawl.js +141 -0
- package/dist/core/crawl.js.map +1 -0
- package/dist/core/map.d.ts +34 -0
- package/dist/core/map.d.ts.map +1 -0
- package/dist/core/map.js +50 -0
- package/dist/core/map.js.map +1 -0
- package/dist/core/scrape.d.ts +201 -0
- package/dist/core/scrape.d.ts.map +1 -0
- package/dist/core/scrape.js +148 -0
- package/dist/core/scrape.js.map +1 -0
- package/dist/core/search.d.ts +144 -0
- package/dist/core/search.d.ts.map +1 -0
- package/dist/core/search.js +75 -0
- package/dist/core/search.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +516 -0
- package/dist/index.js.map +1 -0
- package/dist/stdio.d.ts +3 -0
- package/dist/stdio.d.ts.map +1 -0
- package/dist/stdio.js +551 -0
- package/dist/stdio.js.map +1 -0
- package/dist/tools.d.ts +540 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +528 -0
- package/dist/tools.js.map +1 -0
- package/dist/types.d.ts +214 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/package.json +33 -0
- package/src/core/crawl.ts +149 -0
- package/src/core/map.ts +56 -0
- package/src/core/scrape.ts +156 -0
- package/src/core/search.ts +81 -0
- package/src/index.ts +565 -0
- package/src/stdio.ts +584 -0
- package/src/tools.ts +539 -0
- package/src/types.ts +221 -0
- package/tsconfig.build.json +14 -0
- package/tsconfig.json +45 -0
- package/vitest.config.mts +11 -0
- package/worker-configuration.d.ts +10848 -0
- package/wrangler.jsonc +26 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { XCrawlScrapeRequest, XCrawlScrapeResponse } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Zod schema for xcrawl_scrape tool parameters
|
|
5
|
+
*/
|
|
6
|
+
export declare const scrapeToolSchema: z.ZodObject<{
|
|
7
|
+
url: z.ZodString;
|
|
8
|
+
mode: z.ZodDefault<z.ZodEnum<["sync", "async"]>>;
|
|
9
|
+
proxy: z.ZodOptional<z.ZodObject<{
|
|
10
|
+
location: z.ZodOptional<z.ZodString>;
|
|
11
|
+
sticky_session: z.ZodOptional<z.ZodString>;
|
|
12
|
+
}, "strip", z.ZodTypeAny, {
|
|
13
|
+
location?: string | undefined;
|
|
14
|
+
sticky_session?: string | undefined;
|
|
15
|
+
}, {
|
|
16
|
+
location?: string | undefined;
|
|
17
|
+
sticky_session?: string | undefined;
|
|
18
|
+
}>>;
|
|
19
|
+
request: z.ZodOptional<z.ZodObject<{
|
|
20
|
+
locale: z.ZodOptional<z.ZodString>;
|
|
21
|
+
device: z.ZodOptional<z.ZodEnum<["desktop", "mobile"]>>;
|
|
22
|
+
cookies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
23
|
+
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
24
|
+
only_main_content: z.ZodOptional<z.ZodBoolean>;
|
|
25
|
+
block_ads: z.ZodOptional<z.ZodBoolean>;
|
|
26
|
+
skip_tls_verification: z.ZodOptional<z.ZodBoolean>;
|
|
27
|
+
}, "strip", z.ZodTypeAny, {
|
|
28
|
+
locale?: string | undefined;
|
|
29
|
+
device?: "desktop" | "mobile" | undefined;
|
|
30
|
+
cookies?: Record<string, string> | undefined;
|
|
31
|
+
headers?: Record<string, string> | undefined;
|
|
32
|
+
only_main_content?: boolean | undefined;
|
|
33
|
+
block_ads?: boolean | undefined;
|
|
34
|
+
skip_tls_verification?: boolean | undefined;
|
|
35
|
+
}, {
|
|
36
|
+
locale?: string | undefined;
|
|
37
|
+
device?: "desktop" | "mobile" | undefined;
|
|
38
|
+
cookies?: Record<string, string> | undefined;
|
|
39
|
+
headers?: Record<string, string> | undefined;
|
|
40
|
+
only_main_content?: boolean | undefined;
|
|
41
|
+
block_ads?: boolean | undefined;
|
|
42
|
+
skip_tls_verification?: boolean | undefined;
|
|
43
|
+
}>>;
|
|
44
|
+
js_render: z.ZodOptional<z.ZodObject<{
|
|
45
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
46
|
+
wait_until: z.ZodDefault<z.ZodEnum<["load", "domcontentloaded", "networkidle"]>>;
|
|
47
|
+
viewport: z.ZodOptional<z.ZodObject<{
|
|
48
|
+
width: z.ZodOptional<z.ZodNumber>;
|
|
49
|
+
height: z.ZodOptional<z.ZodNumber>;
|
|
50
|
+
}, "strip", z.ZodTypeAny, {
|
|
51
|
+
width?: number | undefined;
|
|
52
|
+
height?: number | undefined;
|
|
53
|
+
}, {
|
|
54
|
+
width?: number | undefined;
|
|
55
|
+
height?: number | undefined;
|
|
56
|
+
}>>;
|
|
57
|
+
}, "strip", z.ZodTypeAny, {
|
|
58
|
+
enabled: boolean;
|
|
59
|
+
wait_until: "load" | "domcontentloaded" | "networkidle";
|
|
60
|
+
viewport?: {
|
|
61
|
+
width?: number | undefined;
|
|
62
|
+
height?: number | undefined;
|
|
63
|
+
} | undefined;
|
|
64
|
+
}, {
|
|
65
|
+
viewport?: {
|
|
66
|
+
width?: number | undefined;
|
|
67
|
+
height?: number | undefined;
|
|
68
|
+
} | undefined;
|
|
69
|
+
enabled?: boolean | undefined;
|
|
70
|
+
wait_until?: "load" | "domcontentloaded" | "networkidle" | undefined;
|
|
71
|
+
}>>;
|
|
72
|
+
output: z.ZodOptional<z.ZodObject<{
|
|
73
|
+
formats: z.ZodDefault<z.ZodOptional<z.ZodArray<z.ZodEnum<["html", "raw_html", "markdown", "links", "summary", "screenshot", "json"]>, "many">>>;
|
|
74
|
+
screenshot: z.ZodOptional<z.ZodEnum<["full_page", "viewport"]>>;
|
|
75
|
+
json: z.ZodOptional<z.ZodObject<{
|
|
76
|
+
prompt: z.ZodOptional<z.ZodString>;
|
|
77
|
+
json_schema: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
78
|
+
}, "strip", z.ZodTypeAny, {
|
|
79
|
+
prompt?: string | undefined;
|
|
80
|
+
json_schema?: Record<string, any> | undefined;
|
|
81
|
+
}, {
|
|
82
|
+
prompt?: string | undefined;
|
|
83
|
+
json_schema?: Record<string, any> | undefined;
|
|
84
|
+
}>>;
|
|
85
|
+
}, "strip", z.ZodTypeAny, {
|
|
86
|
+
formats: ("html" | "raw_html" | "markdown" | "links" | "summary" | "screenshot" | "json")[];
|
|
87
|
+
screenshot?: "full_page" | "viewport" | undefined;
|
|
88
|
+
json?: {
|
|
89
|
+
prompt?: string | undefined;
|
|
90
|
+
json_schema?: Record<string, any> | undefined;
|
|
91
|
+
} | undefined;
|
|
92
|
+
}, {
|
|
93
|
+
screenshot?: "full_page" | "viewport" | undefined;
|
|
94
|
+
json?: {
|
|
95
|
+
prompt?: string | undefined;
|
|
96
|
+
json_schema?: Record<string, any> | undefined;
|
|
97
|
+
} | undefined;
|
|
98
|
+
formats?: ("html" | "raw_html" | "markdown" | "links" | "summary" | "screenshot" | "json")[] | undefined;
|
|
99
|
+
}>>;
|
|
100
|
+
webhook: z.ZodOptional<z.ZodObject<{
|
|
101
|
+
url: z.ZodOptional<z.ZodString>;
|
|
102
|
+
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
103
|
+
events: z.ZodOptional<z.ZodArray<z.ZodEnum<["started", "completed", "failed"]>, "many">>;
|
|
104
|
+
}, "strip", z.ZodTypeAny, {
|
|
105
|
+
url?: string | undefined;
|
|
106
|
+
headers?: Record<string, string> | undefined;
|
|
107
|
+
events?: ("started" | "completed" | "failed")[] | undefined;
|
|
108
|
+
}, {
|
|
109
|
+
url?: string | undefined;
|
|
110
|
+
headers?: Record<string, string> | undefined;
|
|
111
|
+
events?: ("started" | "completed" | "failed")[] | undefined;
|
|
112
|
+
}>>;
|
|
113
|
+
}, "strip", z.ZodTypeAny, {
|
|
114
|
+
url: string;
|
|
115
|
+
mode: "sync" | "async";
|
|
116
|
+
proxy?: {
|
|
117
|
+
location?: string | undefined;
|
|
118
|
+
sticky_session?: string | undefined;
|
|
119
|
+
} | undefined;
|
|
120
|
+
request?: {
|
|
121
|
+
locale?: string | undefined;
|
|
122
|
+
device?: "desktop" | "mobile" | undefined;
|
|
123
|
+
cookies?: Record<string, string> | undefined;
|
|
124
|
+
headers?: Record<string, string> | undefined;
|
|
125
|
+
only_main_content?: boolean | undefined;
|
|
126
|
+
block_ads?: boolean | undefined;
|
|
127
|
+
skip_tls_verification?: boolean | undefined;
|
|
128
|
+
} | undefined;
|
|
129
|
+
js_render?: {
|
|
130
|
+
enabled: boolean;
|
|
131
|
+
wait_until: "load" | "domcontentloaded" | "networkidle";
|
|
132
|
+
viewport?: {
|
|
133
|
+
width?: number | undefined;
|
|
134
|
+
height?: number | undefined;
|
|
135
|
+
} | undefined;
|
|
136
|
+
} | undefined;
|
|
137
|
+
output?: {
|
|
138
|
+
formats: ("html" | "raw_html" | "markdown" | "links" | "summary" | "screenshot" | "json")[];
|
|
139
|
+
screenshot?: "full_page" | "viewport" | undefined;
|
|
140
|
+
json?: {
|
|
141
|
+
prompt?: string | undefined;
|
|
142
|
+
json_schema?: Record<string, any> | undefined;
|
|
143
|
+
} | undefined;
|
|
144
|
+
} | undefined;
|
|
145
|
+
webhook?: {
|
|
146
|
+
url?: string | undefined;
|
|
147
|
+
headers?: Record<string, string> | undefined;
|
|
148
|
+
events?: ("started" | "completed" | "failed")[] | undefined;
|
|
149
|
+
} | undefined;
|
|
150
|
+
}, {
|
|
151
|
+
url: string;
|
|
152
|
+
mode?: "sync" | "async" | undefined;
|
|
153
|
+
proxy?: {
|
|
154
|
+
location?: string | undefined;
|
|
155
|
+
sticky_session?: string | undefined;
|
|
156
|
+
} | undefined;
|
|
157
|
+
request?: {
|
|
158
|
+
locale?: string | undefined;
|
|
159
|
+
device?: "desktop" | "mobile" | undefined;
|
|
160
|
+
cookies?: Record<string, string> | undefined;
|
|
161
|
+
headers?: Record<string, string> | undefined;
|
|
162
|
+
only_main_content?: boolean | undefined;
|
|
163
|
+
block_ads?: boolean | undefined;
|
|
164
|
+
skip_tls_verification?: boolean | undefined;
|
|
165
|
+
} | undefined;
|
|
166
|
+
js_render?: {
|
|
167
|
+
viewport?: {
|
|
168
|
+
width?: number | undefined;
|
|
169
|
+
height?: number | undefined;
|
|
170
|
+
} | undefined;
|
|
171
|
+
enabled?: boolean | undefined;
|
|
172
|
+
wait_until?: "load" | "domcontentloaded" | "networkidle" | undefined;
|
|
173
|
+
} | undefined;
|
|
174
|
+
output?: {
|
|
175
|
+
screenshot?: "full_page" | "viewport" | undefined;
|
|
176
|
+
json?: {
|
|
177
|
+
prompt?: string | undefined;
|
|
178
|
+
json_schema?: Record<string, any> | undefined;
|
|
179
|
+
} | undefined;
|
|
180
|
+
formats?: ("html" | "raw_html" | "markdown" | "links" | "summary" | "screenshot" | "json")[] | undefined;
|
|
181
|
+
} | undefined;
|
|
182
|
+
webhook?: {
|
|
183
|
+
url?: string | undefined;
|
|
184
|
+
headers?: Record<string, string> | undefined;
|
|
185
|
+
events?: ("started" | "completed" | "failed")[] | undefined;
|
|
186
|
+
} | undefined;
|
|
187
|
+
}>;
|
|
188
|
+
export type ScrapeToolParams = z.infer<typeof scrapeToolSchema>;
|
|
189
|
+
/**
|
|
190
|
+
* Call xCrawl API to scrape a URL
|
|
191
|
+
*/
|
|
192
|
+
export declare function callXCrawlAPI(apiKey: string, params: XCrawlScrapeRequest): Promise<XCrawlScrapeResponse>;
|
|
193
|
+
/**
|
|
194
|
+
* Format scrape response for MCP tool output
|
|
195
|
+
*/
|
|
196
|
+
export declare function formatScrapeResponse(response: XCrawlScrapeResponse): string;
|
|
197
|
+
/**
|
|
198
|
+
* Check status and get result of an async scrape task
|
|
199
|
+
*/
|
|
200
|
+
export declare function checkScrapeStatus(apiKey: string, scrapeId: string): Promise<XCrawlScrapeResponse>;
|
|
201
|
+
//# sourceMappingURL=scrape.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scrape.d.ts","sourceRoot":"","sources":["../../src/core/scrape.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE7E;;GAEG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0E3B,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAEhE;;GAEG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CA6B9G;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,oBAAoB,GAAG,MAAM,CAE3E;AAED;;GAEG;AACH,wBAAsB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC,CA2BvG"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Zod schema for xcrawl_scrape tool parameters
|
|
4
|
+
*/
|
|
5
|
+
export const scrapeToolSchema = z.object({
|
|
6
|
+
url: z.string().url().describe("The URL to scrape"),
|
|
7
|
+
mode: z
|
|
8
|
+
.enum(["sync", "async"])
|
|
9
|
+
.default("sync")
|
|
10
|
+
.describe("Sync mode returns results immediately, async mode returns a scrape_id for later retrieval"),
|
|
11
|
+
proxy: z
|
|
12
|
+
.object({
|
|
13
|
+
location: z.string().optional().describe("ISO-3166-1 alpha-2 country code (e.g., US, JP, SG)"),
|
|
14
|
+
sticky_session: z.string().optional().describe("Sticky session ID to reuse the same proxy exit"),
|
|
15
|
+
})
|
|
16
|
+
.optional()
|
|
17
|
+
.describe("Proxy configuration"),
|
|
18
|
+
request: z
|
|
19
|
+
.object({
|
|
20
|
+
locale: z.string().optional().describe("Accept-Language header value"),
|
|
21
|
+
device: z.enum(["desktop", "mobile"]).optional().describe("Device type for user agent and viewport"),
|
|
22
|
+
cookies: z.record(z.string()).optional().describe("Cookies to send with the request"),
|
|
23
|
+
headers: z.record(z.string()).optional().describe("Custom HTTP headers"),
|
|
24
|
+
only_main_content: z.boolean().optional().describe("Only return main content (default: true)"),
|
|
25
|
+
block_ads: z.boolean().optional().describe("Attempt to block ads (default: true)"),
|
|
26
|
+
skip_tls_verification: z.boolean().optional().describe("Skip TLS certificate verification (default: true)"),
|
|
27
|
+
})
|
|
28
|
+
.optional()
|
|
29
|
+
.describe("Request configuration"),
|
|
30
|
+
js_render: z
|
|
31
|
+
.object({
|
|
32
|
+
enabled: z.boolean().default(true).describe("Enable JavaScript rendering"),
|
|
33
|
+
wait_until: z
|
|
34
|
+
.enum(["load", "domcontentloaded", "networkidle"])
|
|
35
|
+
.default("load")
|
|
36
|
+
.describe("Wait condition for page load"),
|
|
37
|
+
viewport: z
|
|
38
|
+
.object({
|
|
39
|
+
width: z.number().optional().describe("Viewport width"),
|
|
40
|
+
height: z.number().optional().describe("Viewport height"),
|
|
41
|
+
})
|
|
42
|
+
.optional()
|
|
43
|
+
.describe("Viewport dimensions"),
|
|
44
|
+
})
|
|
45
|
+
.optional()
|
|
46
|
+
.describe("JavaScript rendering configuration"),
|
|
47
|
+
output: z
|
|
48
|
+
.object({
|
|
49
|
+
formats: z
|
|
50
|
+
.array(z.enum(["html", "raw_html", "markdown", "links", "summary", "screenshot", "json"]))
|
|
51
|
+
.optional()
|
|
52
|
+
.default(["markdown"])
|
|
53
|
+
.describe("Output formats: 'html' (cleaned HTML without scripts), 'raw_html' (original HTML with all scripts and styles), 'markdown' (Markdown format), 'links' (all page links), 'summary' (AI-generated summary), 'screenshot' (page screenshot), 'json' (structured data extraction). Set to [] to get only metadata."),
|
|
54
|
+
screenshot: z
|
|
55
|
+
.enum(["full_page", "viewport"])
|
|
56
|
+
.optional()
|
|
57
|
+
.describe("Screenshot type: 'viewport' (default, captures visible area) or 'full_page' (captures entire page). Only effective when 'screenshot' is in formats array."),
|
|
58
|
+
json: z
|
|
59
|
+
.object({
|
|
60
|
+
prompt: z.string().optional().describe("Natural language description of what data to extract. The AI engine automatically structures the output based on this prompt."),
|
|
61
|
+
json_schema: z.record(z.any()).optional().describe("Optional JSON Schema for strict output validation. Rarely needed - the prompt field is usually sufficient."),
|
|
62
|
+
})
|
|
63
|
+
.optional()
|
|
64
|
+
.describe("JSON extraction configuration. Use 'prompt' to describe what to extract - json_schema is optional."),
|
|
65
|
+
})
|
|
66
|
+
.optional()
|
|
67
|
+
.describe("Output configuration"),
|
|
68
|
+
webhook: z
|
|
69
|
+
.object({
|
|
70
|
+
url: z.string().optional().describe("Webhook callback URL for async task completion"),
|
|
71
|
+
headers: z.record(z.string()).optional().describe("Custom headers for webhook callback request"),
|
|
72
|
+
events: z
|
|
73
|
+
.array(z.enum(["started", "completed", "failed"]))
|
|
74
|
+
.optional()
|
|
75
|
+
.describe("Events to receive webhook callbacks for (default: ['started', 'completed', 'failed'])"),
|
|
76
|
+
})
|
|
77
|
+
.optional()
|
|
78
|
+
.describe("Webhook configuration for async mode callbacks"),
|
|
79
|
+
});
|
|
80
|
+
/**
|
|
81
|
+
* Call xCrawl API to scrape a URL
|
|
82
|
+
*/
|
|
83
|
+
export async function callXCrawlAPI(apiKey, params) {
|
|
84
|
+
const controller = new AbortController();
|
|
85
|
+
const timeoutId = setTimeout(() => controller.abort(), 300000); // 300 seconds timeout
|
|
86
|
+
try {
|
|
87
|
+
const response = await fetch("https://run.xcrawl.com/v1/scrape", {
|
|
88
|
+
method: "POST",
|
|
89
|
+
headers: {
|
|
90
|
+
"Content-Type": "application/json",
|
|
91
|
+
Authorization: `Bearer ${apiKey}`,
|
|
92
|
+
},
|
|
93
|
+
body: JSON.stringify(params),
|
|
94
|
+
signal: controller.signal,
|
|
95
|
+
});
|
|
96
|
+
if (!response.ok) {
|
|
97
|
+
const errorText = await response.text();
|
|
98
|
+
throw new Error(`xCrawl API error: ${response.status} ${response.statusText} - ${errorText}`);
|
|
99
|
+
}
|
|
100
|
+
return (await response.json());
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
104
|
+
throw new Error("Request timeout after 300 seconds");
|
|
105
|
+
}
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
finally {
|
|
109
|
+
clearTimeout(timeoutId);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Format scrape response for MCP tool output
|
|
114
|
+
*/
|
|
115
|
+
export function formatScrapeResponse(response) {
|
|
116
|
+
return JSON.stringify(response, null, 2);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Check status and get result of an async scrape task
|
|
120
|
+
*/
|
|
121
|
+
export async function checkScrapeStatus(apiKey, scrapeId) {
|
|
122
|
+
const controller = new AbortController();
|
|
123
|
+
const timeoutId = setTimeout(() => controller.abort(), 300000); // 300 seconds timeout
|
|
124
|
+
try {
|
|
125
|
+
const response = await fetch(`https://run.xcrawl.com/v1/scrape/${scrapeId}`, {
|
|
126
|
+
method: "GET",
|
|
127
|
+
headers: {
|
|
128
|
+
Authorization: `Bearer ${apiKey}`,
|
|
129
|
+
},
|
|
130
|
+
signal: controller.signal,
|
|
131
|
+
});
|
|
132
|
+
if (!response.ok) {
|
|
133
|
+
const errorText = await response.text();
|
|
134
|
+
throw new Error(`xCrawl API error: ${response.status} ${response.statusText} - ${errorText}`);
|
|
135
|
+
}
|
|
136
|
+
return (await response.json());
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
140
|
+
throw new Error("Request timeout after 300 seconds");
|
|
141
|
+
}
|
|
142
|
+
throw error;
|
|
143
|
+
}
|
|
144
|
+
finally {
|
|
145
|
+
clearTimeout(timeoutId);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=scrape.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scrape.js","sourceRoot":"","sources":["../../src/core/scrape.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,mBAAmB,CAAC;IACnD,IAAI,EAAE,CAAC;SACL,IAAI,CAAC,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;SACvB,OAAO,CAAC,MAAM,CAAC;SACf,QAAQ,CAAC,2FAA2F,CAAC;IACvG,KAAK,EAAE,CAAC;SACN,MAAM,CAAC;QACP,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,oDAAoD,CAAC;QAC9F,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,gDAAgD,CAAC;KAChG,CAAC;SACD,QAAQ,EAAE;SACV,QAAQ,CAAC,qBAAqB,CAAC;IACjC,OAAO,EAAE,CAAC;SACR,MAAM,CAAC;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KAAK,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;YAC3D,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;QACtD,CAAC;QACD,MAAM,KAAK,CAAC;IACb,CAAC;YAAS,CAAC;QACV,YAAY,CAAC,SAAS,CAAC,CAAC;IACzB,CAAC;AACF,CAAC"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { XCrawlSearchRequest, XCrawlSearchResponse } from "../types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Zod schema for xcrawl_search tool parameters
|
|
5
|
+
*/
|
|
6
|
+
export declare const searchToolSchema: z.ZodObject<{
|
|
7
|
+
query: z.ZodString;
|
|
8
|
+
location: z.ZodOptional<z.ZodString>;
|
|
9
|
+
language: z.ZodOptional<z.ZodString>;
|
|
10
|
+
limit: z.ZodOptional<z.ZodNumber>;
|
|
11
|
+
serp_options: z.ZodOptional<z.ZodObject<{
|
|
12
|
+
q: z.ZodOptional<z.ZodString>;
|
|
13
|
+
location: z.ZodOptional<z.ZodString>;
|
|
14
|
+
uule: z.ZodOptional<z.ZodString>;
|
|
15
|
+
google_domain: z.ZodOptional<z.ZodString>;
|
|
16
|
+
gl: z.ZodOptional<z.ZodString>;
|
|
17
|
+
hl: z.ZodOptional<z.ZodString>;
|
|
18
|
+
cr: z.ZodOptional<z.ZodString>;
|
|
19
|
+
lr: z.ZodOptional<z.ZodString>;
|
|
20
|
+
safe: z.ZodOptional<z.ZodNumber>;
|
|
21
|
+
nfpr: z.ZodOptional<z.ZodBoolean>;
|
|
22
|
+
filter: z.ZodOptional<z.ZodBoolean>;
|
|
23
|
+
tbs: z.ZodOptional<z.ZodString>;
|
|
24
|
+
start: z.ZodOptional<z.ZodNumber>;
|
|
25
|
+
num: z.ZodOptional<z.ZodNumber>;
|
|
26
|
+
ludocid: z.ZodOptional<z.ZodString>;
|
|
27
|
+
lsig: z.ZodOptional<z.ZodString>;
|
|
28
|
+
kgmid: z.ZodOptional<z.ZodString>;
|
|
29
|
+
si: z.ZodOptional<z.ZodString>;
|
|
30
|
+
ibp: z.ZodOptional<z.ZodString>;
|
|
31
|
+
uds: z.ZodOptional<z.ZodString>;
|
|
32
|
+
no_cache: z.ZodOptional<z.ZodBoolean>;
|
|
33
|
+
}, "strip", z.ZodTypeAny, {
|
|
34
|
+
location?: string | undefined;
|
|
35
|
+
filter?: boolean | undefined;
|
|
36
|
+
q?: string | undefined;
|
|
37
|
+
uule?: string | undefined;
|
|
38
|
+
google_domain?: string | undefined;
|
|
39
|
+
gl?: string | undefined;
|
|
40
|
+
hl?: string | undefined;
|
|
41
|
+
cr?: string | undefined;
|
|
42
|
+
lr?: string | undefined;
|
|
43
|
+
safe?: number | undefined;
|
|
44
|
+
nfpr?: boolean | undefined;
|
|
45
|
+
tbs?: string | undefined;
|
|
46
|
+
start?: number | undefined;
|
|
47
|
+
num?: number | undefined;
|
|
48
|
+
ludocid?: string | undefined;
|
|
49
|
+
lsig?: string | undefined;
|
|
50
|
+
kgmid?: string | undefined;
|
|
51
|
+
si?: string | undefined;
|
|
52
|
+
ibp?: string | undefined;
|
|
53
|
+
uds?: string | undefined;
|
|
54
|
+
no_cache?: boolean | undefined;
|
|
55
|
+
}, {
|
|
56
|
+
location?: string | undefined;
|
|
57
|
+
filter?: boolean | undefined;
|
|
58
|
+
q?: string | undefined;
|
|
59
|
+
uule?: string | undefined;
|
|
60
|
+
google_domain?: string | undefined;
|
|
61
|
+
gl?: string | undefined;
|
|
62
|
+
hl?: string | undefined;
|
|
63
|
+
cr?: string | undefined;
|
|
64
|
+
lr?: string | undefined;
|
|
65
|
+
safe?: number | undefined;
|
|
66
|
+
nfpr?: boolean | undefined;
|
|
67
|
+
tbs?: string | undefined;
|
|
68
|
+
start?: number | undefined;
|
|
69
|
+
num?: number | undefined;
|
|
70
|
+
ludocid?: string | undefined;
|
|
71
|
+
lsig?: string | undefined;
|
|
72
|
+
kgmid?: string | undefined;
|
|
73
|
+
si?: string | undefined;
|
|
74
|
+
ibp?: string | undefined;
|
|
75
|
+
uds?: string | undefined;
|
|
76
|
+
no_cache?: boolean | undefined;
|
|
77
|
+
}>>;
|
|
78
|
+
}, "strip", z.ZodTypeAny, {
|
|
79
|
+
query: string;
|
|
80
|
+
location?: string | undefined;
|
|
81
|
+
language?: string | undefined;
|
|
82
|
+
limit?: number | undefined;
|
|
83
|
+
serp_options?: {
|
|
84
|
+
location?: string | undefined;
|
|
85
|
+
filter?: boolean | undefined;
|
|
86
|
+
q?: string | undefined;
|
|
87
|
+
uule?: string | undefined;
|
|
88
|
+
google_domain?: string | undefined;
|
|
89
|
+
gl?: string | undefined;
|
|
90
|
+
hl?: string | undefined;
|
|
91
|
+
cr?: string | undefined;
|
|
92
|
+
lr?: string | undefined;
|
|
93
|
+
safe?: number | undefined;
|
|
94
|
+
nfpr?: boolean | undefined;
|
|
95
|
+
tbs?: string | undefined;
|
|
96
|
+
start?: number | undefined;
|
|
97
|
+
num?: number | undefined;
|
|
98
|
+
ludocid?: string | undefined;
|
|
99
|
+
lsig?: string | undefined;
|
|
100
|
+
kgmid?: string | undefined;
|
|
101
|
+
si?: string | undefined;
|
|
102
|
+
ibp?: string | undefined;
|
|
103
|
+
uds?: string | undefined;
|
|
104
|
+
no_cache?: boolean | undefined;
|
|
105
|
+
} | undefined;
|
|
106
|
+
}, {
|
|
107
|
+
query: string;
|
|
108
|
+
location?: string | undefined;
|
|
109
|
+
language?: string | undefined;
|
|
110
|
+
limit?: number | undefined;
|
|
111
|
+
serp_options?: {
|
|
112
|
+
location?: string | undefined;
|
|
113
|
+
filter?: boolean | undefined;
|
|
114
|
+
q?: string | undefined;
|
|
115
|
+
uule?: string | undefined;
|
|
116
|
+
google_domain?: string | undefined;
|
|
117
|
+
gl?: string | undefined;
|
|
118
|
+
hl?: string | undefined;
|
|
119
|
+
cr?: string | undefined;
|
|
120
|
+
lr?: string | undefined;
|
|
121
|
+
safe?: number | undefined;
|
|
122
|
+
nfpr?: boolean | undefined;
|
|
123
|
+
tbs?: string | undefined;
|
|
124
|
+
start?: number | undefined;
|
|
125
|
+
num?: number | undefined;
|
|
126
|
+
ludocid?: string | undefined;
|
|
127
|
+
lsig?: string | undefined;
|
|
128
|
+
kgmid?: string | undefined;
|
|
129
|
+
si?: string | undefined;
|
|
130
|
+
ibp?: string | undefined;
|
|
131
|
+
uds?: string | undefined;
|
|
132
|
+
no_cache?: boolean | undefined;
|
|
133
|
+
} | undefined;
|
|
134
|
+
}>;
|
|
135
|
+
export type SearchToolParams = z.infer<typeof searchToolSchema>;
|
|
136
|
+
/**
|
|
137
|
+
* Call xCrawl Search API to get Google SERP results
|
|
138
|
+
*/
|
|
139
|
+
export declare function callXCrawlSearchAPI(apiKey: string, params: XCrawlSearchRequest): Promise<XCrawlSearchResponse>;
|
|
140
|
+
/**
|
|
141
|
+
* Format search response for MCP tool output
|
|
142
|
+
*/
|
|
143
|
+
export declare function formatSearchResponse(response: XCrawlSearchResponse): string;
|
|
144
|
+
//# sourceMappingURL=search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/core/search.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAE7E;;GAEG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+B3B,CAAC;AAEH,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAEhE;;GAEG;AACH,wBAAsB,mBAAmB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CA6BpH;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,oBAAoB,GAAG,MAAM,CAE3E"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Zod schema for xcrawl_search tool parameters
|
|
4
|
+
*/
|
|
5
|
+
export const searchToolSchema = z.object({
|
|
6
|
+
query: z.string().min(1).describe("Search keywords"),
|
|
7
|
+
location: z.string().optional().describe("Search location (country/city name or ISO code)"),
|
|
8
|
+
language: z.string().optional().describe("Search language (ISO 639-1 code)"),
|
|
9
|
+
limit: z.number().int().min(1).max(100).optional().describe("Number of results to return (1-100)"),
|
|
10
|
+
serp_options: z
|
|
11
|
+
.object({
|
|
12
|
+
q: z.string().optional(),
|
|
13
|
+
location: z.string().optional(),
|
|
14
|
+
uule: z.string().optional(),
|
|
15
|
+
google_domain: z.string().optional(),
|
|
16
|
+
gl: z.string().optional(),
|
|
17
|
+
hl: z.string().optional(),
|
|
18
|
+
cr: z.string().optional(),
|
|
19
|
+
lr: z.string().optional(),
|
|
20
|
+
safe: z.number().int().optional(),
|
|
21
|
+
nfpr: z.boolean().optional(),
|
|
22
|
+
filter: z.boolean().optional(),
|
|
23
|
+
tbs: z.string().optional(),
|
|
24
|
+
start: z.number().int().optional(),
|
|
25
|
+
num: z.number().int().optional(),
|
|
26
|
+
ludocid: z.string().optional(),
|
|
27
|
+
lsig: z.string().optional(),
|
|
28
|
+
kgmid: z.string().optional(),
|
|
29
|
+
si: z.string().optional(),
|
|
30
|
+
ibp: z.string().optional(),
|
|
31
|
+
uds: z.string().optional(),
|
|
32
|
+
no_cache: z.boolean().optional(),
|
|
33
|
+
})
|
|
34
|
+
.optional()
|
|
35
|
+
.describe("Advanced Google SERP parameters"),
|
|
36
|
+
});
|
|
37
|
+
/**
|
|
38
|
+
* Call xCrawl Search API to get Google SERP results
|
|
39
|
+
*/
|
|
40
|
+
export async function callXCrawlSearchAPI(apiKey, params) {
|
|
41
|
+
const controller = new AbortController();
|
|
42
|
+
const timeoutId = setTimeout(() => controller.abort(), 300000); // 300 seconds timeout
|
|
43
|
+
try {
|
|
44
|
+
const response = await fetch("https://run.xcrawl.com/v1/search", {
|
|
45
|
+
method: "POST",
|
|
46
|
+
headers: {
|
|
47
|
+
"Content-Type": "application/json",
|
|
48
|
+
Authorization: `Bearer ${apiKey}`,
|
|
49
|
+
},
|
|
50
|
+
body: JSON.stringify(params),
|
|
51
|
+
signal: controller.signal,
|
|
52
|
+
});
|
|
53
|
+
if (!response.ok) {
|
|
54
|
+
const errorText = await response.text();
|
|
55
|
+
throw new Error(`xCrawl Search API error: ${response.status} ${response.statusText} - ${errorText}`);
|
|
56
|
+
}
|
|
57
|
+
return (await response.json());
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
61
|
+
throw new Error("Request timeout after 300 seconds");
|
|
62
|
+
}
|
|
63
|
+
throw error;
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
clearTimeout(timeoutId);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Format search response for MCP tool output
|
|
71
|
+
*/
|
|
72
|
+
export function formatSearchResponse(response) {
|
|
73
|
+
return JSON.stringify(response, null, 2);
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.js","sourceRoot":"","sources":["../../src/core/search.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,iBAA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