@thinkingos/vsl-mcp-server 1.2.16 → 1.2.17
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/dist/index.js +188 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -2365,6 +2365,159 @@ async function handleGetTextBlock(args, session) {
|
|
|
2365
2365
|
}
|
|
2366
2366
|
}
|
|
2367
2367
|
|
|
2368
|
+
// src/tools/clickCoordinates.ts
|
|
2369
|
+
async function handleClickCoordinates(args, browser, session) {
|
|
2370
|
+
const startTime = Date.now();
|
|
2371
|
+
try {
|
|
2372
|
+
let findObjectById2 = function(objects, targetId) {
|
|
2373
|
+
for (const obj of objects) {
|
|
2374
|
+
const o = obj;
|
|
2375
|
+
if (o.id === targetId) return o;
|
|
2376
|
+
if (o.ch && Array.isArray(o.ch)) {
|
|
2377
|
+
const found = findObjectById2(o.ch, targetId);
|
|
2378
|
+
if (found) return found;
|
|
2379
|
+
}
|
|
2380
|
+
}
|
|
2381
|
+
return null;
|
|
2382
|
+
};
|
|
2383
|
+
var findObjectById = findObjectById2;
|
|
2384
|
+
if (!args.target_id || typeof args.target_id !== "string") {
|
|
2385
|
+
return { status: "error", error: "target_id is required" };
|
|
2386
|
+
}
|
|
2387
|
+
if (!args.clicks || !Array.isArray(args.clicks) || args.clicks.length === 0) {
|
|
2388
|
+
return { status: "error", error: "clicks array is required and must not be empty" };
|
|
2389
|
+
}
|
|
2390
|
+
for (let i = 0; i < args.clicks.length; i++) {
|
|
2391
|
+
const click = args.clicks[i];
|
|
2392
|
+
if (typeof click.x !== "number" || typeof click.y !== "number") {
|
|
2393
|
+
return { status: "error", error: `clicks[${i}]: x and y must be numbers` };
|
|
2394
|
+
}
|
|
2395
|
+
if (click.delay_after_ms !== void 0 && typeof click.delay_after_ms !== "number") {
|
|
2396
|
+
return { status: "error", error: `clicks[${i}]: delay_after_ms must be a number` };
|
|
2397
|
+
}
|
|
2398
|
+
}
|
|
2399
|
+
if (args.return_state !== void 0 && typeof args.return_state !== "boolean") {
|
|
2400
|
+
return { status: "error", error: "return_state must be a boolean (true or false)" };
|
|
2401
|
+
}
|
|
2402
|
+
if (!session.hasSnapshot()) {
|
|
2403
|
+
return {
|
|
2404
|
+
status: "error",
|
|
2405
|
+
error: "No snapshot available. Call vsl_get_snapshot first."
|
|
2406
|
+
};
|
|
2407
|
+
}
|
|
2408
|
+
const isAvailable = await browser.isAvailable();
|
|
2409
|
+
if (!isAvailable) {
|
|
2410
|
+
return {
|
|
2411
|
+
status: "error",
|
|
2412
|
+
error: "Playwright is not installed. Install it with: npm install playwright"
|
|
2413
|
+
};
|
|
2414
|
+
}
|
|
2415
|
+
const page = await browser.getPage();
|
|
2416
|
+
let targetFrame = null;
|
|
2417
|
+
let localShortId = args.target_id;
|
|
2418
|
+
const frameMatch = args.target_id.match(/^iframe_(\d+):(.+)$/);
|
|
2419
|
+
if (frameMatch) {
|
|
2420
|
+
const frameIndex = parseInt(frameMatch[1], 10);
|
|
2421
|
+
localShortId = frameMatch[2];
|
|
2422
|
+
const frameUrl = iframeFrameRegistry.get(frameIndex);
|
|
2423
|
+
if (!frameUrl) {
|
|
2424
|
+
return {
|
|
2425
|
+
status: "error",
|
|
2426
|
+
error: `Frame iframe_${frameIndex} not found in registry. Call vsl_get_snapshot first.`
|
|
2427
|
+
};
|
|
2428
|
+
}
|
|
2429
|
+
const frames = await browser.getFrames();
|
|
2430
|
+
targetFrame = frames.find((f) => {
|
|
2431
|
+
const u = f.url();
|
|
2432
|
+
return u === frameUrl || u.includes(frameUrl) || frameUrl.includes(u);
|
|
2433
|
+
}) || null;
|
|
2434
|
+
if (!targetFrame) {
|
|
2435
|
+
return {
|
|
2436
|
+
status: "error",
|
|
2437
|
+
error: `Frame with URL "${frameUrl}" not found. Available frames: ${frames.map((f) => f.url()).join(", ")}`
|
|
2438
|
+
};
|
|
2439
|
+
}
|
|
2440
|
+
}
|
|
2441
|
+
const idMap = session.getIdMap();
|
|
2442
|
+
const resolvedId = idMap.get(args.target_id) || localShortId;
|
|
2443
|
+
const snapshotDoc = session.getSnapshot();
|
|
2444
|
+
const snapshotObjects = snapshotDoc.objects ?? [];
|
|
2445
|
+
const snapshotObj = findObjectById2(snapshotObjects, resolvedId);
|
|
2446
|
+
if (!snapshotObj || !snapshotObj.rect) {
|
|
2447
|
+
return {
|
|
2448
|
+
status: "error",
|
|
2449
|
+
error: `Element "${args.target_id}" (resolved: "${resolvedId}") not found in snapshot or has no rect. Call vsl_get_snapshot first.`
|
|
2450
|
+
};
|
|
2451
|
+
}
|
|
2452
|
+
const elementRect = snapshotObj.rect;
|
|
2453
|
+
const target = targetFrame || page;
|
|
2454
|
+
let actionsCompleted = 0;
|
|
2455
|
+
for (const click of args.clicks) {
|
|
2456
|
+
const absoluteX = elementRect.x + click.x;
|
|
2457
|
+
const absoluteY = elementRect.y + click.y;
|
|
2458
|
+
const elementFound = await target.evaluate(
|
|
2459
|
+
([x, y]) => {
|
|
2460
|
+
const el = document.elementFromPoint(x, y);
|
|
2461
|
+
if (el) {
|
|
2462
|
+
el.click();
|
|
2463
|
+
return true;
|
|
2464
|
+
}
|
|
2465
|
+
return false;
|
|
2466
|
+
},
|
|
2467
|
+
[absoluteX, absoluteY]
|
|
2468
|
+
);
|
|
2469
|
+
if (!elementFound) {
|
|
2470
|
+
console.warn(`[vsl_click_coordinates] No element found at (${absoluteX}, ${absoluteY}), skipping`);
|
|
2471
|
+
}
|
|
2472
|
+
actionsCompleted++;
|
|
2473
|
+
if (click.delay_after_ms && click.delay_after_ms > 0) {
|
|
2474
|
+
await page.waitForTimeout(click.delay_after_ms);
|
|
2475
|
+
}
|
|
2476
|
+
}
|
|
2477
|
+
await page.waitForTimeout(100);
|
|
2478
|
+
const returnState = args.return_state !== false;
|
|
2479
|
+
const result = {
|
|
2480
|
+
status: "success",
|
|
2481
|
+
data: {
|
|
2482
|
+
actions_completed: actionsCompleted
|
|
2483
|
+
},
|
|
2484
|
+
metadata: computeToolMetrics(
|
|
2485
|
+
{ actions_completed: actionsCompleted, target_id: args.target_id },
|
|
2486
|
+
startTime
|
|
2487
|
+
)
|
|
2488
|
+
};
|
|
2489
|
+
if (returnState) {
|
|
2490
|
+
const currentUrl = await browser.evaluate(() => window.location.href);
|
|
2491
|
+
const state = await getStateAfterAction(session, browser, currentUrl);
|
|
2492
|
+
if (state.error) {
|
|
2493
|
+
result.data.diff = void 0;
|
|
2494
|
+
result.data.snapshot = void 0;
|
|
2495
|
+
} else {
|
|
2496
|
+
result.data.diff = state.diff;
|
|
2497
|
+
result.data.snapshot = state.snapshot;
|
|
2498
|
+
result.data.scrollable = state.scrollable;
|
|
2499
|
+
}
|
|
2500
|
+
try {
|
|
2501
|
+
const screenshotBuffer = await page.screenshot({ type: "png", fullPage: false });
|
|
2502
|
+
const base64Image = screenshotBuffer.toString("base64");
|
|
2503
|
+
result.data.screenshot = {
|
|
2504
|
+
type: "image",
|
|
2505
|
+
data: base64Image,
|
|
2506
|
+
mimeType: "image/png"
|
|
2507
|
+
};
|
|
2508
|
+
} catch (screenshotError) {
|
|
2509
|
+
console.error("[vsl_click_coordinates] Screenshot failed:", screenshotError);
|
|
2510
|
+
}
|
|
2511
|
+
}
|
|
2512
|
+
return result;
|
|
2513
|
+
} catch (error) {
|
|
2514
|
+
return {
|
|
2515
|
+
status: "error",
|
|
2516
|
+
error: `vsl_click_coordinates failed: ${error instanceof Error ? error.message : String(error)}`
|
|
2517
|
+
};
|
|
2518
|
+
}
|
|
2519
|
+
}
|
|
2520
|
+
|
|
2368
2521
|
// src/tools/index.ts
|
|
2369
2522
|
var VSL_TOOLS = [
|
|
2370
2523
|
{
|
|
@@ -2498,6 +2651,37 @@ var VSL_TOOLS = [
|
|
|
2498
2651
|
},
|
|
2499
2652
|
required: ["block_id"]
|
|
2500
2653
|
}
|
|
2654
|
+
},
|
|
2655
|
+
{
|
|
2656
|
+
name: "vsl_click_coordinates",
|
|
2657
|
+
description: '\u0412\u044B\u043F\u043E\u043B\u043D\u0438\u0442\u044C \u043C\u043D\u043E\u0436\u0435\u0441\u0442\u0432\u0435\u043D\u043D\u044B\u0435 \u043A\u043B\u0438\u043A\u0438 \u043F\u043E \u043A\u043E\u043E\u0440\u0434\u0438\u043D\u0430\u0442\u0430\u043C \u043E\u0442\u043D\u043E\u0441\u0438\u0442\u0435\u043B\u044C\u043D\u043E \u0446\u0435\u043B\u0435\u0432\u043E\u0433\u043E \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u0430. \u041A\u043E\u043E\u0440\u0434\u0438\u043D\u0430\u0442\u044B (x, y) \u0437\u0430\u0434\u0430\u044E\u0442\u0441\u044F \u0432 \u043F\u0438\u043A\u0441\u0435\u043B\u044F\u0445 \u043E\u0442 \u043B\u0435\u0432\u043E\u0433\u043E \u0432\u0435\u0440\u0445\u043D\u0435\u0433\u043E \u0443\u0433\u043B\u0430 \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u0430 (\u0438\u0441\u043F\u043E\u043B\u044C\u0437\u0443\u0439\u0442\u0435 bbox \u0438\u0437 snapshot). \u041F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0437\u0430\u0434\u0435\u0440\u0436\u043A\u0438 \u043C\u0435\u0436\u0434\u0443 \u043A\u043B\u0438\u043A\u0430\u043C\u0438. \u0412\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 diff + snapshot + screenshot \u043F\u043E\u0441\u043B\u0435 \u0432\u0441\u0435\u0445 \u043A\u043B\u0438\u043A\u043E\u0432. \u041F\u0440\u0438\u043C\u0435\u0440: {target_id: "iframe_2", clicks: [{x: 50, y: 50, delay_after_ms: 500}, {x: 150, y: 50}]}.',
|
|
2658
|
+
inputSchema: {
|
|
2659
|
+
type: "object",
|
|
2660
|
+
properties: {
|
|
2661
|
+
target_id: {
|
|
2662
|
+
type: "string",
|
|
2663
|
+
description: "ID \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u0430 \u0432 VSL JSON (\u043D\u0430\u043F\u0440\u0438\u043C\u0435\u0440, iframe_2 \u0434\u043B\u044F reCAPTCHA challenge iframe)"
|
|
2664
|
+
},
|
|
2665
|
+
clicks: {
|
|
2666
|
+
type: "array",
|
|
2667
|
+
description: "\u041C\u0430\u0441\u0441\u0438\u0432 \u043A\u043B\u0438\u043A\u043E\u0432. \u041A\u0430\u0436\u0434\u044B\u0439 \u043A\u043B\u0438\u043A: {x: number, y: number, delay_after_ms?: number}. \u041A\u043E\u043E\u0440\u0434\u0438\u043D\u0430\u0442\u044B \u0432 \u043F\u0438\u043A\u0441\u0435\u043B\u044F\u0445 \u043E\u0442 \u043B\u0435\u0432\u043E\u0433\u043E \u0432\u0435\u0440\u0445\u043D\u0435\u0433\u043E \u0443\u0433\u043B\u0430 \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u0430.",
|
|
2668
|
+
items: {
|
|
2669
|
+
type: "object",
|
|
2670
|
+
properties: {
|
|
2671
|
+
x: { type: "number", description: "X \u043A\u043E\u043E\u0440\u0434\u0438\u043D\u0430\u0442\u0430 (pixels \u043E\u0442 \u043B\u0435\u0432\u043E\u0433\u043E \u043A\u0440\u0430\u044F \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u0430)" },
|
|
2672
|
+
y: { type: "number", description: "Y \u043A\u043E\u043E\u0440\u0434\u0438\u043D\u0430\u0442\u0430 (pixels \u043E\u0442 \u0432\u0435\u0440\u0445\u043D\u0435\u0433\u043E \u043A\u0440\u0430\u044F \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u0430)" },
|
|
2673
|
+
delay_after_ms: { type: "number", description: "\u0417\u0430\u0434\u0435\u0440\u0436\u043A\u0430 \u043F\u043E\u0441\u043B\u0435 \u043A\u043B\u0438\u043A\u0430 (\u043C\u0441)" }
|
|
2674
|
+
},
|
|
2675
|
+
required: ["x", "y"]
|
|
2676
|
+
}
|
|
2677
|
+
},
|
|
2678
|
+
return_state: {
|
|
2679
|
+
type: "boolean",
|
|
2680
|
+
description: "\u0415\u0441\u043B\u0438 true (default), \u0432\u043E\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 diff + snapshot + screenshot \u043F\u043E\u0441\u043B\u0435 \u0432\u0441\u0435\u0445 \u043A\u043B\u0438\u043A\u043E\u0432."
|
|
2681
|
+
}
|
|
2682
|
+
},
|
|
2683
|
+
required: ["target_id", "clicks"]
|
|
2684
|
+
}
|
|
2501
2685
|
}
|
|
2502
2686
|
];
|
|
2503
2687
|
function registerTools(server, config, sessionManager) {
|
|
@@ -2534,6 +2718,9 @@ function registerTools(server, config, sessionManager) {
|
|
|
2534
2718
|
case "vsl_get_text_block":
|
|
2535
2719
|
result = await handleGetTextBlock(args, session);
|
|
2536
2720
|
break;
|
|
2721
|
+
case "vsl_click_coordinates":
|
|
2722
|
+
result = await handleClickCoordinates(args, browser, session);
|
|
2723
|
+
break;
|
|
2537
2724
|
default:
|
|
2538
2725
|
return {
|
|
2539
2726
|
content: [
|
|
@@ -3319,7 +3506,7 @@ var SessionManager = class {
|
|
|
3319
3506
|
};
|
|
3320
3507
|
|
|
3321
3508
|
// src/version.ts
|
|
3322
|
-
var VSL_MCP_SERVER_VERSION = "1.2.
|
|
3509
|
+
var VSL_MCP_SERVER_VERSION = "1.2.17";
|
|
3323
3510
|
|
|
3324
3511
|
// src/index.ts
|
|
3325
3512
|
async function main() {
|