mcpscraper-sdk 0.3.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/README.md +77 -0
- package/dist/index.cjs +371 -0
- package/dist/index.d.cts +3471 -0
- package/dist/index.d.ts +3471 -0
- package/dist/index.js +359 -0
- package/package.json +47 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
// src/errors.ts
|
|
2
|
+
function readString(body, key) {
|
|
3
|
+
if (body && typeof body === "object" && key in body) {
|
|
4
|
+
const value = body[key];
|
|
5
|
+
if (typeof value === "string") return value;
|
|
6
|
+
}
|
|
7
|
+
return void 0;
|
|
8
|
+
}
|
|
9
|
+
var ScraperApiError = class extends Error {
|
|
10
|
+
status;
|
|
11
|
+
code;
|
|
12
|
+
body;
|
|
13
|
+
constructor(status, body) {
|
|
14
|
+
super(readString(body, "message") ?? `mcpscraper.dev API request failed with status ${status}`);
|
|
15
|
+
this.name = "ScraperApiError";
|
|
16
|
+
this.status = status;
|
|
17
|
+
this.code = readString(body, "error_code") ?? readString(body, "error");
|
|
18
|
+
this.body = body;
|
|
19
|
+
}
|
|
20
|
+
isInsufficientBalance() {
|
|
21
|
+
return this.code === "insufficient_balance";
|
|
22
|
+
}
|
|
23
|
+
isConcurrencyLimitExceeded() {
|
|
24
|
+
return this.code === "concurrency_limit_exceeded";
|
|
25
|
+
}
|
|
26
|
+
isStructuredError() {
|
|
27
|
+
return typeof readString(this.body, "error_type") === "string";
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// src/client.ts
|
|
32
|
+
import {
|
|
33
|
+
AccessNamespace,
|
|
34
|
+
CaptureNamespace,
|
|
35
|
+
ChannelsNamespace,
|
|
36
|
+
FactsNamespace,
|
|
37
|
+
GraphNamespace,
|
|
38
|
+
LibraryNamespace,
|
|
39
|
+
MemoryNamespace as MemoryToolNamespace,
|
|
40
|
+
RecallNamespace,
|
|
41
|
+
ScheduleNamespace,
|
|
42
|
+
StorageNamespace,
|
|
43
|
+
TablesNamespace,
|
|
44
|
+
TagsNamespace,
|
|
45
|
+
VaultsNamespace,
|
|
46
|
+
VideoNamespace as MemoryVideoNamespace,
|
|
47
|
+
WebhooksNamespace
|
|
48
|
+
} from "mcpscraper-memory-sdk";
|
|
49
|
+
var Requester = class {
|
|
50
|
+
constructor(apiKey, baseUrl, fetchImpl) {
|
|
51
|
+
this.apiKey = apiKey;
|
|
52
|
+
this.baseUrl = baseUrl;
|
|
53
|
+
this.fetchImpl = fetchImpl;
|
|
54
|
+
}
|
|
55
|
+
apiKey;
|
|
56
|
+
baseUrl;
|
|
57
|
+
fetchImpl;
|
|
58
|
+
async call(method, path, body) {
|
|
59
|
+
const res = await this.fetchImpl(`${this.baseUrl}${path}`, {
|
|
60
|
+
method,
|
|
61
|
+
headers: {
|
|
62
|
+
"x-api-key": this.apiKey,
|
|
63
|
+
...body !== void 0 ? { "content-type": "application/json" } : {}
|
|
64
|
+
},
|
|
65
|
+
body: body !== void 0 ? JSON.stringify(body) : void 0
|
|
66
|
+
});
|
|
67
|
+
const data = await res.json().catch(() => void 0);
|
|
68
|
+
if (!res.ok) throw new ScraperApiError(res.status, data);
|
|
69
|
+
return data;
|
|
70
|
+
}
|
|
71
|
+
async callRaw(method, path) {
|
|
72
|
+
const res = await this.fetchImpl(`${this.baseUrl}${path}`, { method, headers: { "x-api-key": this.apiKey } });
|
|
73
|
+
if (!res.ok) {
|
|
74
|
+
const data = await res.json().catch(() => void 0);
|
|
75
|
+
throw new ScraperApiError(res.status, data);
|
|
76
|
+
}
|
|
77
|
+
return res.arrayBuffer();
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
var YoutubeNamespace = class {
|
|
81
|
+
constructor(r) {
|
|
82
|
+
this.r = r;
|
|
83
|
+
}
|
|
84
|
+
r;
|
|
85
|
+
harvest(params) {
|
|
86
|
+
return this.r.call("POST", "/youtube/harvest", params);
|
|
87
|
+
}
|
|
88
|
+
transcribe(params) {
|
|
89
|
+
return this.r.call("POST", "/youtube/transcribe", params);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
var ScreenshotNamespace = class {
|
|
93
|
+
constructor(r) {
|
|
94
|
+
this.r = r;
|
|
95
|
+
}
|
|
96
|
+
r;
|
|
97
|
+
capture(params) {
|
|
98
|
+
return this.r.call("POST", "/screenshot", params);
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
var FacebookNamespace = class {
|
|
102
|
+
constructor(r) {
|
|
103
|
+
this.r = r;
|
|
104
|
+
}
|
|
105
|
+
r;
|
|
106
|
+
ad(params) {
|
|
107
|
+
return this.r.call("POST", "/facebook/ad", params);
|
|
108
|
+
}
|
|
109
|
+
pageIntel(params) {
|
|
110
|
+
return this.r.call("POST", "/facebook/page-intel", params);
|
|
111
|
+
}
|
|
112
|
+
adTranscribe(params) {
|
|
113
|
+
return this.r.call("POST", "/facebook/transcribe", params);
|
|
114
|
+
}
|
|
115
|
+
videoTranscribe(params) {
|
|
116
|
+
return this.r.call("POST", "/facebook/video-transcribe", params);
|
|
117
|
+
}
|
|
118
|
+
search(params) {
|
|
119
|
+
return this.r.call("POST", "/facebook/search", params);
|
|
120
|
+
}
|
|
121
|
+
media(params) {
|
|
122
|
+
return this.r.call("POST", "/facebook/media", params);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
var GoogleAdsNamespace = class {
|
|
126
|
+
constructor(r) {
|
|
127
|
+
this.r = r;
|
|
128
|
+
}
|
|
129
|
+
r;
|
|
130
|
+
search(params) {
|
|
131
|
+
return this.r.call("POST", "/google-ads/search", params);
|
|
132
|
+
}
|
|
133
|
+
pageIntel(params) {
|
|
134
|
+
return this.r.call("POST", "/google-ads/page-intel", params);
|
|
135
|
+
}
|
|
136
|
+
transcribe(params) {
|
|
137
|
+
return this.r.call("POST", "/google-ads/transcribe", params);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
var InstagramNamespace = class {
|
|
141
|
+
constructor(r) {
|
|
142
|
+
this.r = r;
|
|
143
|
+
}
|
|
144
|
+
r;
|
|
145
|
+
profileContent(params) {
|
|
146
|
+
return this.r.call("POST", "/instagram/profile-content", params);
|
|
147
|
+
}
|
|
148
|
+
mediaDownload(params) {
|
|
149
|
+
return this.r.call("POST", "/instagram/media-download", params);
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
var RedditNamespace = class {
|
|
153
|
+
constructor(r) {
|
|
154
|
+
this.r = r;
|
|
155
|
+
}
|
|
156
|
+
r;
|
|
157
|
+
thread(params) {
|
|
158
|
+
return this.r.call("POST", "/reddit/thread", params);
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
var VideoNamespace = class {
|
|
162
|
+
constructor(r) {
|
|
163
|
+
this.r = r;
|
|
164
|
+
}
|
|
165
|
+
r;
|
|
166
|
+
analyze(params) {
|
|
167
|
+
return this.r.call("POST", "/video/analyze", params);
|
|
168
|
+
}
|
|
169
|
+
status(params) {
|
|
170
|
+
return this.r.call("POST", "/video/status", params);
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
var MapsNamespace = class {
|
|
174
|
+
constructor(r) {
|
|
175
|
+
this.r = r;
|
|
176
|
+
}
|
|
177
|
+
r;
|
|
178
|
+
search(params) {
|
|
179
|
+
return this.r.call("POST", "/maps/search", params);
|
|
180
|
+
}
|
|
181
|
+
place(params) {
|
|
182
|
+
return this.r.call("POST", "/maps/place", params);
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
var DirectoryNamespace = class {
|
|
186
|
+
constructor(r) {
|
|
187
|
+
this.r = r;
|
|
188
|
+
}
|
|
189
|
+
r;
|
|
190
|
+
run(params) {
|
|
191
|
+
return this.r.call("POST", "/directory/run", params);
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
var SerpIntelligenceNamespace = class {
|
|
195
|
+
constructor(r) {
|
|
196
|
+
this.r = r;
|
|
197
|
+
}
|
|
198
|
+
r;
|
|
199
|
+
capture(params) {
|
|
200
|
+
return this.r.call("POST", "/serp-intelligence/capture", params);
|
|
201
|
+
}
|
|
202
|
+
pageSnapshots(params) {
|
|
203
|
+
return this.r.call("POST", "/serp-intelligence/page-snapshots", params);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
var WorkflowsNamespace = class {
|
|
207
|
+
constructor(r) {
|
|
208
|
+
this.r = r;
|
|
209
|
+
}
|
|
210
|
+
r;
|
|
211
|
+
listDefinitions() {
|
|
212
|
+
return this.r.call("GET", "/workflows/definitions");
|
|
213
|
+
}
|
|
214
|
+
run(params) {
|
|
215
|
+
return this.r.call("POST", "/workflows/run", params);
|
|
216
|
+
}
|
|
217
|
+
advanceStep(id) {
|
|
218
|
+
return this.r.call("POST", `/workflows/runs/${encodeURIComponent(id)}/step`);
|
|
219
|
+
}
|
|
220
|
+
listRuns() {
|
|
221
|
+
return this.r.call("GET", "/workflows/runs");
|
|
222
|
+
}
|
|
223
|
+
getRun(id) {
|
|
224
|
+
return this.r.call("GET", `/workflows/runs/${encodeURIComponent(id)}`);
|
|
225
|
+
}
|
|
226
|
+
getRunArtifact(id, artifactId) {
|
|
227
|
+
return this.r.callRaw(
|
|
228
|
+
"GET",
|
|
229
|
+
`/workflows/runs/${encodeURIComponent(id)}/artifacts/${encodeURIComponent(artifactId)}`
|
|
230
|
+
);
|
|
231
|
+
}
|
|
232
|
+
createSchedule(params) {
|
|
233
|
+
return this.r.call("POST", "/workflows/schedules", params);
|
|
234
|
+
}
|
|
235
|
+
listSchedules() {
|
|
236
|
+
return this.r.call("GET", "/workflows/schedules");
|
|
237
|
+
}
|
|
238
|
+
patchSchedule(id, params) {
|
|
239
|
+
return this.r.call("PATCH", `/workflows/schedules/${encodeURIComponent(id)}`, params);
|
|
240
|
+
}
|
|
241
|
+
deleteSchedule(id) {
|
|
242
|
+
return this.r.call("DELETE", `/workflows/schedules/${encodeURIComponent(id)}`);
|
|
243
|
+
}
|
|
244
|
+
runScheduleNow(id) {
|
|
245
|
+
return this.r.call("POST", `/workflows/schedules/${encodeURIComponent(id)}/run`);
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
var MemoryTools = class {
|
|
249
|
+
access;
|
|
250
|
+
capture;
|
|
251
|
+
channels;
|
|
252
|
+
facts;
|
|
253
|
+
graph;
|
|
254
|
+
library;
|
|
255
|
+
memory;
|
|
256
|
+
recall;
|
|
257
|
+
schedule;
|
|
258
|
+
storage;
|
|
259
|
+
tables;
|
|
260
|
+
tags;
|
|
261
|
+
vaults;
|
|
262
|
+
video;
|
|
263
|
+
webhooks;
|
|
264
|
+
constructor(callTool) {
|
|
265
|
+
this.access = new AccessNamespace(callTool);
|
|
266
|
+
this.capture = new CaptureNamespace(callTool);
|
|
267
|
+
this.channels = new ChannelsNamespace(callTool);
|
|
268
|
+
this.facts = new FactsNamespace(callTool);
|
|
269
|
+
this.graph = new GraphNamespace(callTool);
|
|
270
|
+
this.library = new LibraryNamespace(callTool);
|
|
271
|
+
this.memory = new MemoryToolNamespace(callTool);
|
|
272
|
+
this.recall = new RecallNamespace(callTool);
|
|
273
|
+
this.schedule = new ScheduleNamespace(callTool);
|
|
274
|
+
this.storage = new StorageNamespace(callTool);
|
|
275
|
+
this.tables = new TablesNamespace(callTool);
|
|
276
|
+
this.tags = new TagsNamespace(callTool);
|
|
277
|
+
this.vaults = new VaultsNamespace(callTool);
|
|
278
|
+
this.video = new MemoryVideoNamespace(callTool);
|
|
279
|
+
this.webhooks = new WebhooksNamespace(callTool);
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
var ScraperClient = class {
|
|
283
|
+
r;
|
|
284
|
+
youtube;
|
|
285
|
+
screenshot;
|
|
286
|
+
facebook;
|
|
287
|
+
googleAds;
|
|
288
|
+
instagram;
|
|
289
|
+
reddit;
|
|
290
|
+
video;
|
|
291
|
+
maps;
|
|
292
|
+
directory;
|
|
293
|
+
serpIntelligence;
|
|
294
|
+
workflows;
|
|
295
|
+
memoryTools;
|
|
296
|
+
constructor(options) {
|
|
297
|
+
this.r = new Requester(options.apiKey, options.baseUrl ?? "https://mcpscraper.dev", options.fetch ?? globalThis.fetch);
|
|
298
|
+
this.youtube = new YoutubeNamespace(this.r);
|
|
299
|
+
this.screenshot = new ScreenshotNamespace(this.r);
|
|
300
|
+
this.facebook = new FacebookNamespace(this.r);
|
|
301
|
+
this.googleAds = new GoogleAdsNamespace(this.r);
|
|
302
|
+
this.instagram = new InstagramNamespace(this.r);
|
|
303
|
+
this.reddit = new RedditNamespace(this.r);
|
|
304
|
+
this.video = new VideoNamespace(this.r);
|
|
305
|
+
this.maps = new MapsNamespace(this.r);
|
|
306
|
+
this.directory = new DirectoryNamespace(this.r);
|
|
307
|
+
this.serpIntelligence = new SerpIntelligenceNamespace(this.r);
|
|
308
|
+
this.workflows = new WorkflowsNamespace(this.r);
|
|
309
|
+
this.memoryTools = new MemoryTools(this.callMemoryTool.bind(this));
|
|
310
|
+
}
|
|
311
|
+
async callMemoryTool(toolName, args) {
|
|
312
|
+
const result = await this.r.call("POST", "/memory/mcp-call", {
|
|
313
|
+
toolName,
|
|
314
|
+
args: args ?? {}
|
|
315
|
+
});
|
|
316
|
+
if (result && typeof result === "object" && result.ok === false) {
|
|
317
|
+
const failure = result;
|
|
318
|
+
throw new ScraperApiError(200, { message: failure.error, ...failure });
|
|
319
|
+
}
|
|
320
|
+
return result;
|
|
321
|
+
}
|
|
322
|
+
searchSerp(params) {
|
|
323
|
+
return this.r.call("POST", "/harvest/sync", { ...params, serpOnly: true });
|
|
324
|
+
}
|
|
325
|
+
harvestPaa(params) {
|
|
326
|
+
return this.r.call("POST", "/harvest/sync", params);
|
|
327
|
+
}
|
|
328
|
+
extractUrl(params) {
|
|
329
|
+
return this.r.call("POST", "/extract-url", params);
|
|
330
|
+
}
|
|
331
|
+
mapSiteUrls(params) {
|
|
332
|
+
return this.r.call("POST", "/map-urls", params);
|
|
333
|
+
}
|
|
334
|
+
extractSite(params) {
|
|
335
|
+
return this.r.call("POST", "/extract-site", params);
|
|
336
|
+
}
|
|
337
|
+
auditSite(params) {
|
|
338
|
+
return this.extractSite(params);
|
|
339
|
+
}
|
|
340
|
+
getExtractSiteStatus(id) {
|
|
341
|
+
return this.r.call("GET", `/extract-site/status/${encodeURIComponent(id)}`);
|
|
342
|
+
}
|
|
343
|
+
listJobs() {
|
|
344
|
+
return this.r.call("GET", "/jobs");
|
|
345
|
+
}
|
|
346
|
+
getJob(id) {
|
|
347
|
+
return this.r.call("GET", `/jobs/${encodeURIComponent(id)}`);
|
|
348
|
+
}
|
|
349
|
+
getHistory() {
|
|
350
|
+
return this.r.call("GET", "/history");
|
|
351
|
+
}
|
|
352
|
+
getLedger() {
|
|
353
|
+
return this.r.call("GET", "/ledger");
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
export {
|
|
357
|
+
ScraperApiError,
|
|
358
|
+
ScraperClient
|
|
359
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mcpscraper-sdk",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Official TypeScript/JavaScript client for the mcpscraper.dev REST API",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"require": "./dist/index.cjs"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist",
|
|
19
|
+
"README.md"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"generate": "openapi-typescript ../../contracts/scraper.openapi.yaml -o src/schema.ts",
|
|
23
|
+
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
24
|
+
"typecheck": "tsc --noEmit",
|
|
25
|
+
"test": "tsx --test test/*.test.ts"
|
|
26
|
+
},
|
|
27
|
+
"keywords": [
|
|
28
|
+
"mcp-scraper",
|
|
29
|
+
"serp",
|
|
30
|
+
"web-scraping",
|
|
31
|
+
"seo-api"
|
|
32
|
+
],
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"mcpscraper-memory-sdk": "^0.2.0"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"openapi-typescript": "^7.13.0"
|
|
38
|
+
},
|
|
39
|
+
"repository": {
|
|
40
|
+
"type": "git",
|
|
41
|
+
"url": "git+https://github.com/VilovietaSEO/mcpscraper-sdk.git",
|
|
42
|
+
"directory": "packages/scraper"
|
|
43
|
+
},
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public"
|
|
46
|
+
}
|
|
47
|
+
}
|