mcp-scraper 0.2.6 → 0.2.7
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 +7 -2
- package/dist/bin/api-server.cjs +219 -10
- package/dist/bin/api-server.cjs.map +1 -1
- package/dist/bin/api-server.js +1 -1
- package/dist/bin/browser-agent-stdio-server.cjs +442 -9
- package/dist/bin/browser-agent-stdio-server.cjs.map +1 -1
- package/dist/bin/browser-agent-stdio-server.js +2 -2
- package/dist/bin/mcp-scraper-combined-stdio-server.cjs +452 -19
- package/dist/bin/mcp-scraper-combined-stdio-server.cjs.map +1 -1
- package/dist/bin/mcp-scraper-combined-stdio-server.js +3 -3
- package/dist/bin/mcp-scraper-install.cjs +1 -1
- package/dist/bin/mcp-scraper-install.cjs.map +1 -1
- package/dist/bin/mcp-scraper-install.js +1 -1
- package/dist/bin/mcp-stdio-server.cjs +1 -1
- package/dist/bin/mcp-stdio-server.cjs.map +1 -1
- package/dist/bin/mcp-stdio-server.js +2 -2
- package/dist/chunk-3TF6UT2P.js +793 -0
- package/dist/chunk-3TF6UT2P.js.map +1 -0
- package/dist/{chunk-7WB2W6FO.js → chunk-7SI6XIR3.js} +2 -2
- package/dist/chunk-IZE5UW7Y.js +7 -0
- package/dist/chunk-IZE5UW7Y.js.map +1 -0
- package/dist/{server-MKCU3M7Y.js → server-RIKRBDOI.js} +221 -12
- package/dist/{server-MKCU3M7Y.js.map → server-RIKRBDOI.js.map} +1 -1
- package/package.json +1 -1
- package/dist/chunk-T6SIPPOQ.js +0 -7
- package/dist/chunk-T6SIPPOQ.js.map +0 -1
- package/dist/chunk-XL4V7VKD.js +0 -360
- package/dist/chunk-XL4V7VKD.js.map +0 -1
- /package/dist/{chunk-7WB2W6FO.js.map → chunk-7SI6XIR3.js.map} +0 -0
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
// bin/mcp-scraper-combined-stdio-server.ts
|
|
5
5
|
var import_node_fs4 = require("fs");
|
|
6
|
-
var
|
|
7
|
-
var
|
|
6
|
+
var import_node_os4 = require("os");
|
|
7
|
+
var import_node_path5 = require("path");
|
|
8
8
|
var import_mcp3 = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
9
9
|
var import_stdio = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
10
10
|
|
|
@@ -134,11 +134,11 @@ var HttpMcpToolExecutor = class {
|
|
|
134
134
|
// src/mcp/browser-agent-mcp-server.ts
|
|
135
135
|
var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
136
136
|
var import_node_fs = require("fs");
|
|
137
|
-
var
|
|
138
|
-
var
|
|
137
|
+
var import_node_os2 = require("os");
|
|
138
|
+
var import_node_path2 = require("path");
|
|
139
139
|
|
|
140
140
|
// src/version.ts
|
|
141
|
-
var PACKAGE_VERSION = "0.2.
|
|
141
|
+
var PACKAGE_VERSION = "0.2.7";
|
|
142
142
|
|
|
143
143
|
// src/mcp/browser-agent-tool-schemas.ts
|
|
144
144
|
var import_zod = require("zod");
|
|
@@ -151,6 +151,19 @@ var BrowserOpenInputSchema = {
|
|
|
151
151
|
var BrowserSessionInputSchema = {
|
|
152
152
|
session_id: import_zod.z.string().describe("The session id returned by browser_open.")
|
|
153
153
|
};
|
|
154
|
+
var BrowserLocateTargetSchema = import_zod.z.object({
|
|
155
|
+
name: import_zod.z.string().optional().describe("Optional label for this target, echoed in the result."),
|
|
156
|
+
selector: import_zod.z.string().optional().describe('CSS selector for the exact DOM element to locate, for example h1, input[name="q"], or [data-testid="result"].'),
|
|
157
|
+
text: import_zod.z.string().optional().describe("Visible text to locate when a selector is not known. The tool returns the text range bounds when possible."),
|
|
158
|
+
match: import_zod.z.enum(["contains", "exact"]).default("contains").describe("How to match text targets. Defaults to contains."),
|
|
159
|
+
index: import_zod.z.number().int().min(0).default(0).describe("Zero-based match index when multiple elements match.")
|
|
160
|
+
}).refine((value) => Boolean(value.selector || value.text), {
|
|
161
|
+
message: "target requires selector or text"
|
|
162
|
+
});
|
|
163
|
+
var BrowserLocateInputSchema = {
|
|
164
|
+
session_id: import_zod.z.string().describe("The session id returned by browser_open."),
|
|
165
|
+
targets: import_zod.z.array(BrowserLocateTargetSchema).min(1).max(20).describe("DOM targets to locate in the current viewport. Use selectors for exact elements, or text for visible text ranges.")
|
|
166
|
+
};
|
|
154
167
|
var BrowserGotoInputSchema = {
|
|
155
168
|
session_id: import_zod.z.string().describe("The session id returned by browser_open."),
|
|
156
169
|
url: import_zod.z.string().url().describe("URL to navigate the browser to.")
|
|
@@ -187,16 +200,315 @@ var BrowserReplayDownloadInputSchema = {
|
|
|
187
200
|
replay_id: import_zod.z.string().describe("The replay id returned by browser_replay_start or browser_list_replays."),
|
|
188
201
|
filename: import_zod.z.string().optional().describe("Optional local MP4 filename. Defaults to a timestamped replay filename.")
|
|
189
202
|
};
|
|
203
|
+
var BrowserReplayAnnotationSchema = import_zod.z.object({
|
|
204
|
+
type: import_zod.z.enum(["box", "circle", "underline", "arrow", "label"]).default("box").describe("Annotation style to draw over the replay."),
|
|
205
|
+
start_seconds: import_zod.z.number().min(0).default(0).describe("When the annotation should appear in the replay."),
|
|
206
|
+
end_seconds: import_zod.z.number().min(0).optional().describe("When the annotation should disappear. Defaults to two seconds after start_seconds."),
|
|
207
|
+
left: import_zod.z.number().optional().describe("Target left edge in browser screenshot pixels. Use element.left from browser_screenshot/browser_read."),
|
|
208
|
+
top: import_zod.z.number().optional().describe("Target top edge in browser screenshot pixels. Use element.top from browser_screenshot/browser_read."),
|
|
209
|
+
width: import_zod.z.number().positive().optional().describe("Target width in browser screenshot pixels. Use element.width from browser_screenshot/browser_read."),
|
|
210
|
+
height: import_zod.z.number().positive().optional().describe("Target height in browser screenshot pixels. Use element.height from browser_screenshot/browser_read."),
|
|
211
|
+
x: import_zod.z.number().optional().describe("Point target x coordinate in browser screenshot pixels when no box is available."),
|
|
212
|
+
y: import_zod.z.number().optional().describe("Point target y coordinate in browser screenshot pixels when no box is available."),
|
|
213
|
+
from_x: import_zod.z.number().optional().describe("Arrow start x coordinate in browser screenshot pixels. Defaults near the target."),
|
|
214
|
+
from_y: import_zod.z.number().optional().describe("Arrow start y coordinate in browser screenshot pixels. Defaults near the target."),
|
|
215
|
+
to_x: import_zod.z.number().optional().describe("Arrow target x coordinate in browser screenshot pixels. Defaults to the target box center."),
|
|
216
|
+
to_y: import_zod.z.number().optional().describe("Arrow target y coordinate in browser screenshot pixels. Defaults to the target box center."),
|
|
217
|
+
label: import_zod.z.string().max(120).optional().describe("Optional text callout to render near the annotation."),
|
|
218
|
+
color: import_zod.z.string().regex(/^#?[0-9a-fA-F]{6}$/).optional().describe("Annotation color as hex, for example #ff3b30."),
|
|
219
|
+
thickness: import_zod.z.number().min(1).max(24).optional().describe("Stroke thickness in pixels. Defaults to 5.")
|
|
220
|
+
});
|
|
221
|
+
var BrowserReplayMarkInputSchema = {
|
|
222
|
+
session_id: import_zod.z.string().describe("The session id returned by browser_open. A replay must already be recording."),
|
|
223
|
+
target: BrowserLocateTargetSchema.describe("The exact DOM element or text range to mark in the current viewport."),
|
|
224
|
+
type: import_zod.z.enum(["box", "circle", "underline", "arrow"]).default("box").describe("Annotation style to generate. Labels are included on the returned annotation when label is provided."),
|
|
225
|
+
label: import_zod.z.string().max(120).optional().describe("Optional callout text to render near the target."),
|
|
226
|
+
color: import_zod.z.string().regex(/^#?[0-9a-fA-F]{6}$/).optional().describe("Annotation color as hex, for example #ff3b30."),
|
|
227
|
+
thickness: import_zod.z.number().min(1).max(24).optional().describe("Stroke thickness in pixels. Defaults to 5."),
|
|
228
|
+
padding: import_zod.z.number().min(0).max(80).default(8).describe("Pixels to expand the DOM bounds so the highlight does not touch the text edge."),
|
|
229
|
+
start_offset_seconds: import_zod.z.number().min(-5).max(10).default(-0.25).describe("Offset from the current replay time. Negative values make the callout appear just before the mark action is captured."),
|
|
230
|
+
duration_seconds: import_zod.z.number().min(0.5).max(30).default(4).describe("How long the generated annotation should remain visible.")
|
|
231
|
+
};
|
|
232
|
+
var BrowserReplayAnnotateInputSchema = {
|
|
233
|
+
session_id: import_zod.z.string().describe("The session id returned by browser_open."),
|
|
234
|
+
replay_id: import_zod.z.string().describe("The replay id returned by browser_replay_start or browser_list_replays."),
|
|
235
|
+
annotations: import_zod.z.array(BrowserReplayAnnotationSchema).min(1).max(50).describe("Timed overlay annotations to render on the replay. Prefer annotations returned by browser_replay_mark; otherwise use exact DOM bounds from browser_locate/browser_screenshot/browser_read."),
|
|
236
|
+
filename: import_zod.z.string().optional().describe("Optional output MP4 filename. Defaults to a timestamped annotated replay filename."),
|
|
237
|
+
source_width: import_zod.z.number().positive().optional().describe("Width of the screenshot coordinate space used for annotations. Defaults to the replay video width."),
|
|
238
|
+
source_height: import_zod.z.number().positive().optional().describe("Height of the coordinate space used for annotations. When this is a page viewport height smaller than the replay video height, the annotator infers the browser chrome top offset."),
|
|
239
|
+
source_left_offset: import_zod.z.number().min(0).optional().describe("Optional explicit X offset from annotation coordinates to replay video coordinates. Usually omitted."),
|
|
240
|
+
source_top_offset: import_zod.z.number().min(0).optional().describe("Optional explicit Y offset from annotation coordinates to replay video coordinates. Usually omitted because browser chrome offset is inferred when source_height is a page viewport height.")
|
|
241
|
+
};
|
|
190
242
|
var BrowserListInputSchema = {
|
|
191
243
|
include_closed: import_zod.z.boolean().default(false).describe("Include closed sessions in the list.")
|
|
192
244
|
};
|
|
193
245
|
|
|
246
|
+
// src/mcp/replay-annotator.ts
|
|
247
|
+
var import_node_child_process = require("child_process");
|
|
248
|
+
var import_promises = require("fs/promises");
|
|
249
|
+
var import_node_os = require("os");
|
|
250
|
+
var import_node_path = require("path");
|
|
251
|
+
var import_node_util = require("util");
|
|
252
|
+
var execFileAsync = (0, import_node_util.promisify)(import_node_child_process.execFile);
|
|
253
|
+
function finiteNumber(value) {
|
|
254
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
255
|
+
}
|
|
256
|
+
function clamp(value, min, max) {
|
|
257
|
+
return Math.min(max, Math.max(min, value));
|
|
258
|
+
}
|
|
259
|
+
function formatAssTime(seconds) {
|
|
260
|
+
const safe = Math.max(0, seconds);
|
|
261
|
+
const hours = Math.floor(safe / 3600);
|
|
262
|
+
const minutes = Math.floor(safe % 3600 / 60);
|
|
263
|
+
const wholeSeconds = Math.floor(safe % 60);
|
|
264
|
+
const centiseconds = Math.floor((safe - Math.floor(safe)) * 100);
|
|
265
|
+
return `${hours}:${String(minutes).padStart(2, "0")}:${String(wholeSeconds).padStart(2, "0")}.${String(centiseconds).padStart(2, "0")}`;
|
|
266
|
+
}
|
|
267
|
+
function cssHexToAssColor(color) {
|
|
268
|
+
const normalized = color?.trim().match(/^#?([0-9a-fA-F]{6})$/)?.[1] ?? "ff3b30";
|
|
269
|
+
const red = normalized.slice(0, 2);
|
|
270
|
+
const green = normalized.slice(2, 4);
|
|
271
|
+
const blue = normalized.slice(4, 6);
|
|
272
|
+
return `&H${blue}${green}${red}&`;
|
|
273
|
+
}
|
|
274
|
+
function escapeAssText(value) {
|
|
275
|
+
return value.replace(/\\/g, "\\\\").replace(/\{/g, "\\{").replace(/\}/g, "\\}").replace(/\r?\n/g, "\\N");
|
|
276
|
+
}
|
|
277
|
+
function resolveCoordinateTransform(video, source, options) {
|
|
278
|
+
const explicitOffsetX = finiteNumber(options.sourceLeftOffset) ? options.sourceLeftOffset : null;
|
|
279
|
+
const explicitOffsetY = finiteNumber(options.sourceTopOffset) ? options.sourceTopOffset : null;
|
|
280
|
+
const inferredTopOffset = explicitOffsetY == null && Math.round(source.width) === Math.round(video.width) && source.height < video.height && video.height - source.height <= 220 ? video.height - source.height : 0;
|
|
281
|
+
const offsetX = explicitOffsetX ?? 0;
|
|
282
|
+
const offsetY = explicitOffsetY ?? inferredTopOffset;
|
|
283
|
+
return {
|
|
284
|
+
scaleX: (video.width - offsetX) / source.width,
|
|
285
|
+
scaleY: (video.height - offsetY) / source.height,
|
|
286
|
+
offsetX,
|
|
287
|
+
offsetY
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
function transformPoint(x, y, transform) {
|
|
291
|
+
return {
|
|
292
|
+
x: x * transform.scaleX + transform.offsetX,
|
|
293
|
+
y: y * transform.scaleY + transform.offsetY
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
function scaleRect(annotation, transform) {
|
|
297
|
+
if (finiteNumber(annotation.left) && finiteNumber(annotation.top) && finiteNumber(annotation.width) && finiteNumber(annotation.height)) {
|
|
298
|
+
const origin = transformPoint(annotation.left, annotation.top, transform);
|
|
299
|
+
return {
|
|
300
|
+
left: origin.x,
|
|
301
|
+
top: origin.y,
|
|
302
|
+
width: annotation.width * transform.scaleX,
|
|
303
|
+
height: annotation.height * transform.scaleY
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
if (finiteNumber(annotation.x) && finiteNumber(annotation.y)) {
|
|
307
|
+
const radius = finiteNumber(annotation.width) ? annotation.width / 2 : 28;
|
|
308
|
+
const point = transformPoint(annotation.x, annotation.y, transform);
|
|
309
|
+
return {
|
|
310
|
+
left: point.x - radius * transform.scaleX,
|
|
311
|
+
top: point.y - radius * transform.scaleY,
|
|
312
|
+
width: radius * 2 * transform.scaleX,
|
|
313
|
+
height: radius * 2 * transform.scaleY
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
throw new Error("annotation needs either left/top/width/height or x/y");
|
|
317
|
+
}
|
|
318
|
+
function rectPath(rect) {
|
|
319
|
+
const x1 = Math.round(rect.left);
|
|
320
|
+
const y1 = Math.round(rect.top);
|
|
321
|
+
const x2 = Math.round(rect.left + rect.width);
|
|
322
|
+
const y2 = Math.round(rect.top + rect.height);
|
|
323
|
+
return `m ${x1} ${y1} l ${x2} ${y1} l ${x2} ${y2} l ${x1} ${y2} l ${x1} ${y1}`;
|
|
324
|
+
}
|
|
325
|
+
function ellipsePath(rect) {
|
|
326
|
+
const cx = rect.left + rect.width / 2;
|
|
327
|
+
const cy = rect.top + rect.height / 2;
|
|
328
|
+
const rx = Math.max(4, rect.width / 2);
|
|
329
|
+
const ry = Math.max(4, rect.height / 2);
|
|
330
|
+
const points = [];
|
|
331
|
+
for (let i = 0; i <= 32; i += 1) {
|
|
332
|
+
const t = Math.PI * 2 * i / 32;
|
|
333
|
+
const x = Math.round(cx + Math.cos(t) * rx);
|
|
334
|
+
const y = Math.round(cy + Math.sin(t) * ry);
|
|
335
|
+
points.push(`${i === 0 ? "m" : "l"} ${x} ${y}`);
|
|
336
|
+
}
|
|
337
|
+
return points.join(" ");
|
|
338
|
+
}
|
|
339
|
+
function filledRectPath(left, top, width, height) {
|
|
340
|
+
return rectPath({ left, top, width, height });
|
|
341
|
+
}
|
|
342
|
+
function arrowPath(fromX, fromY, toX, toY, thickness) {
|
|
343
|
+
const dx = toX - fromX;
|
|
344
|
+
const dy = toY - fromY;
|
|
345
|
+
const length = Math.max(1, Math.hypot(dx, dy));
|
|
346
|
+
const ux = dx / length;
|
|
347
|
+
const uy = dy / length;
|
|
348
|
+
const px = -uy;
|
|
349
|
+
const py = ux;
|
|
350
|
+
const half = thickness / 2;
|
|
351
|
+
const head = Math.max(14, thickness * 4);
|
|
352
|
+
const baseX = toX - ux * head;
|
|
353
|
+
const baseY = toY - uy * head;
|
|
354
|
+
const p1x = Math.round(fromX + px * half);
|
|
355
|
+
const p1y = Math.round(fromY + py * half);
|
|
356
|
+
const p2x = Math.round(baseX + px * half);
|
|
357
|
+
const p2y = Math.round(baseY + py * half);
|
|
358
|
+
const p3x = Math.round(baseX + px * head * 0.55);
|
|
359
|
+
const p3y = Math.round(baseY + py * head * 0.55);
|
|
360
|
+
const p4x = Math.round(toX);
|
|
361
|
+
const p4y = Math.round(toY);
|
|
362
|
+
const p5x = Math.round(baseX - px * head * 0.55);
|
|
363
|
+
const p5y = Math.round(baseY - py * head * 0.55);
|
|
364
|
+
const p6x = Math.round(baseX - px * half);
|
|
365
|
+
const p6y = Math.round(baseY - py * half);
|
|
366
|
+
const p7x = Math.round(fromX - px * half);
|
|
367
|
+
const p7y = Math.round(fromY - py * half);
|
|
368
|
+
return `m ${p1x} ${p1y} l ${p2x} ${p2y} l ${p3x} ${p3y} l ${p4x} ${p4y} l ${p5x} ${p5y} l ${p6x} ${p6y} l ${p7x} ${p7y} l ${p1x} ${p1y}`;
|
|
369
|
+
}
|
|
370
|
+
function eventLine(start, end, body) {
|
|
371
|
+
return `Dialogue: 0,${formatAssTime(start)},${formatAssTime(end)},Default,,0,0,0,,${body}`;
|
|
372
|
+
}
|
|
373
|
+
function labelLine(start, end, x, y, label) {
|
|
374
|
+
const safeX = Math.round(x);
|
|
375
|
+
const safeY = Math.round(y);
|
|
376
|
+
return eventLine(
|
|
377
|
+
start,
|
|
378
|
+
end,
|
|
379
|
+
`{\\an7\\pos(${safeX},${safeY})\\fs30\\bord4\\shad0\\c&HFFFFFF&\\3c&H000000&}${escapeAssText(label)}`
|
|
380
|
+
);
|
|
381
|
+
}
|
|
382
|
+
function shapeLine(start, end, path, color, thickness, filled = false) {
|
|
383
|
+
const fillAlpha = filled ? "&H00&" : "&HFF&";
|
|
384
|
+
const border = filled ? 0 : thickness;
|
|
385
|
+
return eventLine(
|
|
386
|
+
start,
|
|
387
|
+
end,
|
|
388
|
+
`{\\an7\\pos(0,0)\\p1\\bord${border}\\shad0\\1a${fillAlpha}\\1c${color}\\3c${color}}${path}`
|
|
389
|
+
);
|
|
390
|
+
}
|
|
391
|
+
function buildAssSubtitle(options, video) {
|
|
392
|
+
const source = {
|
|
393
|
+
width: options.sourceWidth && options.sourceWidth > 0 ? options.sourceWidth : video.width,
|
|
394
|
+
height: options.sourceHeight && options.sourceHeight > 0 ? options.sourceHeight : video.height
|
|
395
|
+
};
|
|
396
|
+
const transform = resolveCoordinateTransform(video, source, options);
|
|
397
|
+
const lines = [];
|
|
398
|
+
for (const annotation of options.annotations) {
|
|
399
|
+
const start = Math.max(0, annotation.start_seconds ?? 0);
|
|
400
|
+
const end = annotation.end_seconds && annotation.end_seconds > start ? annotation.end_seconds : start + 2;
|
|
401
|
+
const type = annotation.type ?? "box";
|
|
402
|
+
const color = cssHexToAssColor(annotation.color);
|
|
403
|
+
const thickness = Math.round(clamp(annotation.thickness ?? 5, 2, 24));
|
|
404
|
+
if (type === "label") {
|
|
405
|
+
if (!annotation.label) throw new Error("label annotation needs label");
|
|
406
|
+
const rect2 = scaleRect(annotation, transform);
|
|
407
|
+
lines.push(labelLine(start, end, rect2.left, Math.max(8, rect2.top), annotation.label));
|
|
408
|
+
continue;
|
|
409
|
+
}
|
|
410
|
+
if (type === "arrow") {
|
|
411
|
+
const rect2 = finiteNumber(annotation.to_x) && finiteNumber(annotation.to_y) ? null : scaleRect(annotation, transform);
|
|
412
|
+
const toPoint = finiteNumber(annotation.to_x) && finiteNumber(annotation.to_y) ? transformPoint(annotation.to_x, annotation.to_y, transform) : null;
|
|
413
|
+
const toX = toPoint ? toPoint.x : rect2.left + rect2.width / 2;
|
|
414
|
+
const toY = toPoint ? toPoint.y : rect2.top + rect2.height / 2;
|
|
415
|
+
const fromPoint = finiteNumber(annotation.from_x) && finiteNumber(annotation.from_y) ? transformPoint(annotation.from_x, annotation.from_y, transform) : null;
|
|
416
|
+
const fromX = fromPoint ? fromPoint.x : clamp(toX - 120, 12, video.width - 12);
|
|
417
|
+
const fromY = fromPoint ? fromPoint.y : clamp(toY - 90, 12, video.height - 12);
|
|
418
|
+
lines.push(shapeLine(start, end, arrowPath(fromX, fromY, toX, toY, thickness), color, thickness, true));
|
|
419
|
+
if (annotation.label) lines.push(labelLine(start, end, fromX + 8, Math.max(96, fromY - 36), annotation.label));
|
|
420
|
+
continue;
|
|
421
|
+
}
|
|
422
|
+
const rect = scaleRect(annotation, transform);
|
|
423
|
+
if (type === "underline") {
|
|
424
|
+
const underlineTop = rect.top + rect.height + thickness;
|
|
425
|
+
lines.push(shapeLine(start, end, filledRectPath(rect.left, underlineTop, rect.width, thickness), color, 0, true));
|
|
426
|
+
} else if (type === "circle") {
|
|
427
|
+
lines.push(shapeLine(start, end, ellipsePath(rect), color, thickness));
|
|
428
|
+
} else {
|
|
429
|
+
lines.push(shapeLine(start, end, rectPath(rect), color, thickness));
|
|
430
|
+
}
|
|
431
|
+
if (annotation.label) lines.push(labelLine(start, end, rect.left, Math.max(8, rect.top - 38), annotation.label));
|
|
432
|
+
}
|
|
433
|
+
return [
|
|
434
|
+
"[Script Info]",
|
|
435
|
+
"ScriptType: v4.00+",
|
|
436
|
+
`PlayResX: ${Math.round(video.width)}`,
|
|
437
|
+
`PlayResY: ${Math.round(video.height)}`,
|
|
438
|
+
"ScaledBorderAndShadow: yes",
|
|
439
|
+
"",
|
|
440
|
+
"[V4+ Styles]",
|
|
441
|
+
"Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding",
|
|
442
|
+
"Style: Default,Arial,30,&H00FFFFFF,&H000000FF,&H00000000,&H90000000,0,0,0,0,100,100,0,0,1,2,0,7,0,0,0,1",
|
|
443
|
+
"",
|
|
444
|
+
"[Events]",
|
|
445
|
+
"Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text",
|
|
446
|
+
...lines,
|
|
447
|
+
""
|
|
448
|
+
].join("\n");
|
|
449
|
+
}
|
|
450
|
+
async function videoSize(inputFilePath) {
|
|
451
|
+
const { stdout } = await execFileAsync("ffprobe", [
|
|
452
|
+
"-v",
|
|
453
|
+
"error",
|
|
454
|
+
"-select_streams",
|
|
455
|
+
"v:0",
|
|
456
|
+
"-show_entries",
|
|
457
|
+
"stream=width,height",
|
|
458
|
+
"-of",
|
|
459
|
+
"json",
|
|
460
|
+
inputFilePath
|
|
461
|
+
], { maxBuffer: 1024 * 1024 });
|
|
462
|
+
const parsed = JSON.parse(stdout);
|
|
463
|
+
const stream = parsed.streams?.[0];
|
|
464
|
+
if (!stream?.width || !stream.height) throw new Error("could not read replay video dimensions");
|
|
465
|
+
return { width: stream.width, height: stream.height };
|
|
466
|
+
}
|
|
467
|
+
function ffmpegFilterPath(path) {
|
|
468
|
+
return path.replace(/\\/g, "\\\\").replace(/:/g, "\\:");
|
|
469
|
+
}
|
|
470
|
+
async function annotateReplayVideo(inputFilePath, outputFilePath, options) {
|
|
471
|
+
if (!options.annotations.length) throw new Error("annotations must include at least one item");
|
|
472
|
+
const size = await videoSize(inputFilePath);
|
|
473
|
+
const tmp = await (0, import_promises.mkdtemp)((0, import_node_path.join)((0, import_node_os.tmpdir)(), "mcp-scraper-ass-"));
|
|
474
|
+
const assPath = (0, import_node_path.join)(tmp, "annotations.ass");
|
|
475
|
+
try {
|
|
476
|
+
await (0, import_promises.writeFile)(assPath, buildAssSubtitle(options, size), "utf8");
|
|
477
|
+
await execFileAsync("ffmpeg", [
|
|
478
|
+
"-y",
|
|
479
|
+
"-i",
|
|
480
|
+
inputFilePath,
|
|
481
|
+
"-vf",
|
|
482
|
+
`ass=${ffmpegFilterPath(assPath)}`,
|
|
483
|
+
"-c:v",
|
|
484
|
+
"libx264",
|
|
485
|
+
"-pix_fmt",
|
|
486
|
+
"yuv420p",
|
|
487
|
+
"-movflags",
|
|
488
|
+
"+faststart",
|
|
489
|
+
"-c:a",
|
|
490
|
+
"copy",
|
|
491
|
+
outputFilePath
|
|
492
|
+
], { maxBuffer: 1024 * 1024 * 20 });
|
|
493
|
+
const out = await (0, import_promises.stat)(outputFilePath);
|
|
494
|
+
return {
|
|
495
|
+
filePath: outputFilePath,
|
|
496
|
+
bytes: out.size,
|
|
497
|
+
width: size.width,
|
|
498
|
+
height: size.height,
|
|
499
|
+
annotationCount: options.annotations.length
|
|
500
|
+
};
|
|
501
|
+
} finally {
|
|
502
|
+
await (0, import_promises.rm)(tmp, { recursive: true, force: true });
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
194
506
|
// src/mcp/browser-agent-mcp-server.ts
|
|
195
507
|
function textResult(value, isError = false) {
|
|
196
508
|
return { content: [{ type: "text", text: JSON.stringify(value) }], isError };
|
|
197
509
|
}
|
|
198
510
|
function outputBaseDir() {
|
|
199
|
-
return process.env.MCP_SCRAPER_OUTPUT_DIR?.trim() || (0,
|
|
511
|
+
return process.env.MCP_SCRAPER_OUTPUT_DIR?.trim() || (0, import_node_path2.join)((0, import_node_os2.homedir)(), "Downloads", "mcp-scraper");
|
|
200
512
|
}
|
|
201
513
|
function safeFilePart(value) {
|
|
202
514
|
return value.replace(/[^a-zA-Z0-9._-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 120) || "replay";
|
|
@@ -205,7 +517,32 @@ function replayFilePath(sessionId, replayId, filename) {
|
|
|
205
517
|
const requested = filename?.trim();
|
|
206
518
|
const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
207
519
|
const name = requested ? safeFilePart(requested).replace(/\.mp4$/i, "") : `${stamp}-${safeFilePart(sessionId)}-${safeFilePart(replayId)}`;
|
|
208
|
-
return (0,
|
|
520
|
+
return (0, import_node_path2.join)(outputBaseDir(), "browser-replays", `${name}.mp4`);
|
|
521
|
+
}
|
|
522
|
+
function annotatedReplayFilePath(sessionId, replayId, filename) {
|
|
523
|
+
const requested = filename?.trim();
|
|
524
|
+
if (requested) return replayFilePath(sessionId, replayId, requested);
|
|
525
|
+
const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
526
|
+
return replayFilePath(sessionId, replayId, `${stamp}-${safeFilePart(sessionId)}-${safeFilePart(replayId)}-annotated`);
|
|
527
|
+
}
|
|
528
|
+
function finiteNumber2(value) {
|
|
529
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
530
|
+
}
|
|
531
|
+
function expandElementBounds(element, viewport, padding) {
|
|
532
|
+
const sourceWidth = finiteNumber2(viewport?.width) && viewport.width > 0 ? viewport.width : 1920;
|
|
533
|
+
const sourceHeight = finiteNumber2(viewport?.height) && viewport.height > 0 ? viewport.height : 1080;
|
|
534
|
+
const left = Math.max(0, element.left - padding);
|
|
535
|
+
const top = Math.max(0, element.top - padding);
|
|
536
|
+
const right = Math.min(sourceWidth, element.left + element.width + padding);
|
|
537
|
+
const bottom = Math.min(sourceHeight, element.top + element.height + padding);
|
|
538
|
+
return {
|
|
539
|
+
left,
|
|
540
|
+
top,
|
|
541
|
+
width: Math.max(1, right - left),
|
|
542
|
+
height: Math.max(1, bottom - top),
|
|
543
|
+
sourceWidth,
|
|
544
|
+
sourceHeight
|
|
545
|
+
};
|
|
209
546
|
}
|
|
210
547
|
function registerBrowserAgentMcpTools(server2, opts) {
|
|
211
548
|
const baseUrl2 = opts.baseUrl.replace(/\/$/, "");
|
|
@@ -239,7 +576,7 @@ function registerBrowserAgentMcpTools(server2, opts) {
|
|
|
239
576
|
}
|
|
240
577
|
const bytes = Buffer.from(await res.arrayBuffer());
|
|
241
578
|
const filePath = replayFilePath(sessionId, replayId, filename);
|
|
242
|
-
(0, import_node_fs.mkdirSync)((0,
|
|
579
|
+
(0, import_node_fs.mkdirSync)((0, import_node_path2.join)(outputBaseDir(), "browser-replays"), { recursive: true });
|
|
243
580
|
(0, import_node_fs.writeFileSync)(filePath, bytes);
|
|
244
581
|
return {
|
|
245
582
|
ok: true,
|
|
@@ -323,6 +660,19 @@ function registerBrowserAgentMcpTools(server2, opts) {
|
|
|
323
660
|
return textResult(res.data, !res.ok);
|
|
324
661
|
}
|
|
325
662
|
);
|
|
663
|
+
server2.registerTool(
|
|
664
|
+
"browser_locate",
|
|
665
|
+
{
|
|
666
|
+
title: "Locate DOM Targets",
|
|
667
|
+
description: "Locate exact visible DOM elements or text ranges in the current browser viewport and return left/top/width/height bounds in screenshot pixels. Use this before drawing annotations or when a callout must literally circle, box, underline, or point to a real element. Prefer CSS selectors for exact UI elements; use text when selector is unknown. When a replay is actively recording, the result includes replay_elapsed_seconds for timing.",
|
|
668
|
+
inputSchema: BrowserLocateInputSchema,
|
|
669
|
+
annotations: annotations("Locate DOM Targets", true)
|
|
670
|
+
},
|
|
671
|
+
async (input) => {
|
|
672
|
+
const res = await req("POST", `/agent/sessions/${input.session_id}/locate`, { targets: input.targets });
|
|
673
|
+
return textResult(res.data, !res.ok);
|
|
674
|
+
}
|
|
675
|
+
);
|
|
326
676
|
server2.registerTool(
|
|
327
677
|
"browser_goto",
|
|
328
678
|
{
|
|
@@ -450,6 +800,89 @@ function registerBrowserAgentMcpTools(server2, opts) {
|
|
|
450
800
|
return textResult(res.data, !res.ok);
|
|
451
801
|
}
|
|
452
802
|
);
|
|
803
|
+
server2.registerTool(
|
|
804
|
+
"browser_replay_mark",
|
|
805
|
+
{
|
|
806
|
+
title: "Mark Replay Annotation",
|
|
807
|
+
description: "While a replay is actively recording, locate one exact DOM target and return a ready-to-use annotation object with DOM bounds and replay-relative timing. Use this instead of guessing start_seconds or drawing rough rectangles. Workflow: start browser_replay_start, navigate until the target is visible and stable, call browser_replay_mark for each callout, then stop the replay and pass the returned annotations to browser_replay_annotate.",
|
|
808
|
+
inputSchema: BrowserReplayMarkInputSchema,
|
|
809
|
+
annotations: annotations("Mark Replay Annotation", true)
|
|
810
|
+
},
|
|
811
|
+
async (input) => {
|
|
812
|
+
const res = await req("POST", `/agent/sessions/${input.session_id}/locate`, { targets: [input.target] });
|
|
813
|
+
if (!res.ok) return textResult(res.data, true);
|
|
814
|
+
const target = res.data?.targets?.[0];
|
|
815
|
+
const element = target?.element;
|
|
816
|
+
const elapsed = res.data?.replay?.replay_elapsed_seconds;
|
|
817
|
+
if (!target?.found || !element) {
|
|
818
|
+
return textResult({ error: target?.error ?? "target not found in current viewport", target }, true);
|
|
819
|
+
}
|
|
820
|
+
if (!finiteNumber2(elapsed)) {
|
|
821
|
+
return textResult({ error: "no active replay clock found; call browser_replay_start before browser_replay_mark" }, true);
|
|
822
|
+
}
|
|
823
|
+
const padded = expandElementBounds(element, res.data?.viewport, input.padding ?? 8);
|
|
824
|
+
const start = Math.max(0, elapsed + (input.start_offset_seconds ?? -0.25));
|
|
825
|
+
const duration = input.duration_seconds ?? 4;
|
|
826
|
+
const annotation = {
|
|
827
|
+
type: input.type ?? "box",
|
|
828
|
+
start_seconds: Number(start.toFixed(3)),
|
|
829
|
+
end_seconds: Number((start + duration).toFixed(3)),
|
|
830
|
+
left: Math.round(padded.left),
|
|
831
|
+
top: Math.round(padded.top),
|
|
832
|
+
width: Math.round(padded.width),
|
|
833
|
+
height: Math.round(padded.height),
|
|
834
|
+
...input.label ? { label: input.label } : {},
|
|
835
|
+
...input.color ? { color: input.color } : {},
|
|
836
|
+
...input.thickness ? { thickness: input.thickness } : {}
|
|
837
|
+
};
|
|
838
|
+
return textResult({
|
|
839
|
+
annotation,
|
|
840
|
+
source_width: padded.sourceWidth,
|
|
841
|
+
source_height: padded.sourceHeight,
|
|
842
|
+
replay: res.data.replay,
|
|
843
|
+
target,
|
|
844
|
+
hint: "Append annotation to your annotations array. Use source_width/source_height with browser_replay_annotate."
|
|
845
|
+
});
|
|
846
|
+
}
|
|
847
|
+
);
|
|
848
|
+
server2.registerTool(
|
|
849
|
+
"browser_replay_annotate",
|
|
850
|
+
{
|
|
851
|
+
title: "Annotate Replay MP4",
|
|
852
|
+
description: "Download a browser replay MP4, render visual annotations over it, and save a new annotated MP4 locally. Use this after browser_replay_stop when the user wants proof videos with circles, boxes, arrows, underlines, or labels. For accurate timing and placement, prefer annotations returned by browser_replay_mark while the replay is recording; otherwise use exact left/top/width/height bounds from browser_locate. If the replay video size differs from the screenshot coordinate space, pass source_width and source_height.",
|
|
853
|
+
inputSchema: BrowserReplayAnnotateInputSchema,
|
|
854
|
+
annotations: annotations("Annotate Replay MP4", true)
|
|
855
|
+
},
|
|
856
|
+
async (input) => {
|
|
857
|
+
const sourceName = input.filename ? `${input.filename}-source` : void 0;
|
|
858
|
+
const downloaded = await downloadReplay(input.session_id, input.replay_id, sourceName);
|
|
859
|
+
if (!downloaded.ok) return textResult(downloaded.data, true);
|
|
860
|
+
try {
|
|
861
|
+
const sourcePath = String(downloaded.data.file_path);
|
|
862
|
+
const outputPath = annotatedReplayFilePath(input.session_id, input.replay_id, input.filename);
|
|
863
|
+
(0, import_node_fs.mkdirSync)((0, import_node_path2.join)(outputBaseDir(), "browser-replays"), { recursive: true });
|
|
864
|
+
const result = await annotateReplayVideo(sourcePath, outputPath, {
|
|
865
|
+
annotations: input.annotations,
|
|
866
|
+
sourceWidth: input.source_width,
|
|
867
|
+
sourceHeight: input.source_height,
|
|
868
|
+
sourceLeftOffset: input.source_left_offset,
|
|
869
|
+
sourceTopOffset: input.source_top_offset
|
|
870
|
+
});
|
|
871
|
+
return textResult({
|
|
872
|
+
replay_id: input.replay_id,
|
|
873
|
+
source_file_path: sourcePath,
|
|
874
|
+
annotated_file_path: result.filePath,
|
|
875
|
+
bytes: result.bytes,
|
|
876
|
+
width: result.width,
|
|
877
|
+
height: result.height,
|
|
878
|
+
annotation_count: result.annotationCount,
|
|
879
|
+
mime_type: "video/mp4"
|
|
880
|
+
});
|
|
881
|
+
} catch (err) {
|
|
882
|
+
return textResult({ error: err instanceof Error ? err.message : String(err) }, true);
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
);
|
|
453
886
|
server2.registerTool(
|
|
454
887
|
"browser_close",
|
|
455
888
|
{
|
|
@@ -483,12 +916,12 @@ function registerBrowserAgentMcpTools(server2, opts) {
|
|
|
483
916
|
// src/mcp/paa-mcp-server.ts
|
|
484
917
|
var import_mcp2 = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
485
918
|
var import_node_fs3 = require("fs");
|
|
486
|
-
var
|
|
919
|
+
var import_node_path4 = require("path");
|
|
487
920
|
|
|
488
921
|
// src/mcp/mcp-response-formatter.ts
|
|
489
922
|
var import_node_fs2 = require("fs");
|
|
490
|
-
var
|
|
491
|
-
var
|
|
923
|
+
var import_node_os3 = require("os");
|
|
924
|
+
var import_node_path3 = require("path");
|
|
492
925
|
|
|
493
926
|
// src/errors.ts
|
|
494
927
|
function sanitizeVendorName(message) {
|
|
@@ -510,7 +943,7 @@ function reportTitle(full) {
|
|
|
510
943
|
return title?.replace(/^#\s+/, "").trim() || "MCP Scraper Report";
|
|
511
944
|
}
|
|
512
945
|
function outputBaseDir2() {
|
|
513
|
-
return process.env.MCP_SCRAPER_OUTPUT_DIR?.trim() || (0,
|
|
946
|
+
return process.env.MCP_SCRAPER_OUTPUT_DIR?.trim() || (0, import_node_path3.join)((0, import_node_os3.homedir)(), "Downloads", "mcp-scraper");
|
|
514
947
|
}
|
|
515
948
|
function saveFullReport(full) {
|
|
516
949
|
if (!reportSavingEnabled || process.env.MCP_SCRAPER_SAVE_REPORTS === "false") return null;
|
|
@@ -518,7 +951,7 @@ function saveFullReport(full) {
|
|
|
518
951
|
try {
|
|
519
952
|
(0, import_node_fs2.mkdirSync)(outDir, { recursive: true });
|
|
520
953
|
const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
521
|
-
const file = (0,
|
|
954
|
+
const file = (0, import_node_path3.join)(outDir, `${stamp}-${slugifyReportName(reportTitle(full))}.md`);
|
|
522
955
|
(0, import_node_fs2.writeFileSync)(file, full, "utf8");
|
|
523
956
|
return file;
|
|
524
957
|
} catch {
|
|
@@ -528,11 +961,11 @@ function saveFullReport(full) {
|
|
|
528
961
|
function persistScreenshotLocally(base64, url) {
|
|
529
962
|
if (!reportSavingEnabled || process.env.MCP_SCRAPER_SAVE_REPORTS === "false") return null;
|
|
530
963
|
try {
|
|
531
|
-
const dir = (0,
|
|
964
|
+
const dir = (0, import_node_path3.join)(outputBaseDir2(), "screenshots");
|
|
532
965
|
(0, import_node_fs2.mkdirSync)(dir, { recursive: true });
|
|
533
966
|
const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
|
|
534
967
|
const slug = url.replace(/^https?:\/\//, "").replace(/[^a-z0-9]+/gi, "-").replace(/^-+|-+$/g, "").slice(0, 60);
|
|
535
|
-
const filePath = (0,
|
|
968
|
+
const filePath = (0, import_node_path3.join)(dir, `${stamp}-${slug}.png`);
|
|
536
969
|
(0, import_node_fs2.writeFileSync)(filePath, Buffer.from(base64, "base64"));
|
|
537
970
|
return filePath;
|
|
538
971
|
} catch {
|
|
@@ -2198,7 +2631,7 @@ function localPlanningToolAnnotations(title) {
|
|
|
2198
2631
|
function listSavedReports() {
|
|
2199
2632
|
try {
|
|
2200
2633
|
const dir = outputBaseDir2();
|
|
2201
|
-
return (0, import_node_fs3.readdirSync)(dir).filter((f) => f.endsWith(".md")).map((f) => ({ filename: f, mtimeMs: (0, import_node_fs3.statSync)((0,
|
|
2634
|
+
return (0, import_node_fs3.readdirSync)(dir).filter((f) => f.endsWith(".md")).map((f) => ({ filename: f, mtimeMs: (0, import_node_fs3.statSync)((0, import_node_path4.join)(dir, f)).mtimeMs })).sort((a, b) => b.mtimeMs - a.mtimeMs).slice(0, 100);
|
|
2202
2635
|
} catch {
|
|
2203
2636
|
return [];
|
|
2204
2637
|
}
|
|
@@ -2222,9 +2655,9 @@ function registerSavedReportResources(server2) {
|
|
|
2222
2655
|
},
|
|
2223
2656
|
async (uri, variables) => {
|
|
2224
2657
|
const requested = Array.isArray(variables.filename) ? variables.filename[0] : variables.filename;
|
|
2225
|
-
const filename = (0,
|
|
2658
|
+
const filename = (0, import_node_path4.basename)(decodeURIComponent(String(requested ?? "")));
|
|
2226
2659
|
if (!filename.endsWith(".md")) throw new Error("Only saved .md reports can be read");
|
|
2227
|
-
const text = (0, import_node_fs3.readFileSync)((0,
|
|
2660
|
+
const text = (0, import_node_fs3.readFileSync)((0, import_node_path4.join)(outputBaseDir2(), filename), "utf8");
|
|
2228
2661
|
return { contents: [{ uri: uri.href, mimeType: "text/markdown", text }] };
|
|
2229
2662
|
}
|
|
2230
2663
|
);
|
|
@@ -2348,7 +2781,7 @@ function registerPaaExtractorMcpTools(server2, executor, options = {}) {
|
|
|
2348
2781
|
// bin/mcp-scraper-combined-stdio-server.ts
|
|
2349
2782
|
function readApiKeyFile() {
|
|
2350
2783
|
const explicitPath = process.env.MCP_SCRAPER_KEY_PATH?.trim();
|
|
2351
|
-
const paths = [explicitPath, (0,
|
|
2784
|
+
const paths = [explicitPath, (0, import_node_path5.join)((0, import_node_os4.homedir)(), ".mcp-scraper-key")].filter(Boolean);
|
|
2352
2785
|
for (const path of paths) {
|
|
2353
2786
|
try {
|
|
2354
2787
|
const value = (0, import_node_fs4.readFileSync)(path, "utf8").trim();
|