viyv-browser-mcp 0.5.4 → 0.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +72 -18
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -683,9 +683,10 @@ function startBridge(options) {
|
|
|
683
683
|
|
|
684
684
|
// src/server.ts
|
|
685
685
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
686
|
-
import { existsSync, statSync } from "fs";
|
|
686
|
+
import { existsSync, mkdirSync, statSync, writeFileSync } from "fs";
|
|
687
687
|
import http from "http";
|
|
688
688
|
import { createConnection as createConnection2 } from "net";
|
|
689
|
+
import { dirname } from "path";
|
|
689
690
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
690
691
|
import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
|
|
691
692
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
@@ -2301,7 +2302,8 @@ var smExportTool = {
|
|
|
2301
2302
|
name: "sm_export",
|
|
2302
2303
|
description: SM_EXPORT_DESCRIPTION,
|
|
2303
2304
|
inputSchema: z.object({
|
|
2304
|
-
domain: z.string().optional().describe("Export only pages matching this domain (subdomain-aware). Omit for all.")
|
|
2305
|
+
domain: z.string().optional().describe("Export only pages matching this domain (subdomain-aware). Omit for all."),
|
|
2306
|
+
file_path: z.string().optional().describe("Save to this path and return metadata only (keeps data out of context)")
|
|
2305
2307
|
})
|
|
2306
2308
|
};
|
|
2307
2309
|
var smImportTool = {
|
|
@@ -2462,7 +2464,8 @@ var smReportExportTool = {
|
|
|
2462
2464
|
description: SM_REPORT_EXPORT_DESCRIPTION,
|
|
2463
2465
|
inputSchema: z.object({
|
|
2464
2466
|
report_id: z.string().describe("Report ID to export"),
|
|
2465
|
-
format: z.enum(["json", "csv"]).optional().describe("Export format (default: json)")
|
|
2467
|
+
format: z.enum(["json", "csv"]).optional().describe("Export format (default: json)"),
|
|
2468
|
+
file_path: z.string().optional().describe("Save to this path and return metadata only (keeps data out of context)")
|
|
2466
2469
|
})
|
|
2467
2470
|
};
|
|
2468
2471
|
var jobEntrySchema = z.object({
|
|
@@ -2532,7 +2535,8 @@ var smJobReportExportTool = {
|
|
|
2532
2535
|
description: SM_JOB_REPORT_EXPORT_DESCRIPTION,
|
|
2533
2536
|
inputSchema: z.object({
|
|
2534
2537
|
job_report_id: z.string().describe("Job report ID to export"),
|
|
2535
|
-
format: z.enum(["json", "csv"]).optional().describe("Export format (default: json)")
|
|
2538
|
+
format: z.enum(["json", "csv"]).optional().describe("Export format (default: json)"),
|
|
2539
|
+
file_path: z.string().optional().describe("Save to this path and return metadata only (keeps data out of context)")
|
|
2536
2540
|
})
|
|
2537
2541
|
};
|
|
2538
2542
|
var smJobHistoryTool = {
|
|
@@ -2766,6 +2770,32 @@ function coerceShape(shape) {
|
|
|
2766
2770
|
}
|
|
2767
2771
|
return result;
|
|
2768
2772
|
}
|
|
2773
|
+
var FILE_EXPORT_TOOLS = /* @__PURE__ */ new Set(["sm_report_export", "sm_job_report_export", "sm_export"]);
|
|
2774
|
+
function handleFileExport(filePath, result) {
|
|
2775
|
+
mkdirSync(dirname(filePath), { recursive: true });
|
|
2776
|
+
let content;
|
|
2777
|
+
let metadata;
|
|
2778
|
+
if (typeof result.data === "string") {
|
|
2779
|
+
const { data, ...rest } = result;
|
|
2780
|
+
content = data;
|
|
2781
|
+
metadata = { ...rest, file_path: filePath };
|
|
2782
|
+
if (result.format === "csv") {
|
|
2783
|
+
const lines = content.split("\n").filter((l) => l.trim());
|
|
2784
|
+
const headerLine = lines[0]?.replace(/^\uFEFF/, "") ?? "";
|
|
2785
|
+
const columns = headerLine.split(",").map((h) => h.replace(/^"|"$/g, "").trim());
|
|
2786
|
+
metadata.row_count = lines.length - 1;
|
|
2787
|
+
metadata.column_count = columns.length;
|
|
2788
|
+
metadata.columns = columns;
|
|
2789
|
+
}
|
|
2790
|
+
} else {
|
|
2791
|
+
content = JSON.stringify(result, null, 2);
|
|
2792
|
+
const pages = Array.isArray(result.pages) ? result.pages : [];
|
|
2793
|
+
metadata = { ok: true, file_path: filePath, page_count: pages.length };
|
|
2794
|
+
}
|
|
2795
|
+
writeFileSync(filePath, content, "utf-8");
|
|
2796
|
+
metadata.file_size = Buffer.byteLength(content, "utf-8");
|
|
2797
|
+
return metadata;
|
|
2798
|
+
}
|
|
2769
2799
|
function createConfiguredMcpServer() {
|
|
2770
2800
|
const server = new McpServer({
|
|
2771
2801
|
name: MCP_SERVER.NAME,
|
|
@@ -3428,9 +3458,34 @@ async function callExtensionTool(tool, input) {
|
|
|
3428
3458
|
]
|
|
3429
3459
|
});
|
|
3430
3460
|
}, toolTimeout);
|
|
3461
|
+
const { chromeProfile, file_path: filePath, ...cleanInput } = input;
|
|
3431
3462
|
pendingRequests.set(requestId, {
|
|
3432
3463
|
resolve: (result) => {
|
|
3433
3464
|
removeErrorListener();
|
|
3465
|
+
if (FILE_EXPORT_TOOLS.has(tool) && typeof filePath === "string" && ("data" in result || "pages" in result)) {
|
|
3466
|
+
try {
|
|
3467
|
+
const metadata = handleFileExport(filePath, result);
|
|
3468
|
+
resolve2({
|
|
3469
|
+
content: [{ type: "text", text: JSON.stringify(metadata) }]
|
|
3470
|
+
});
|
|
3471
|
+
} catch (e) {
|
|
3472
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
3473
|
+
resolve2({
|
|
3474
|
+
content: [
|
|
3475
|
+
{
|
|
3476
|
+
type: "text",
|
|
3477
|
+
text: JSON.stringify({
|
|
3478
|
+
error: {
|
|
3479
|
+
code: "FILE_WRITE_ERROR",
|
|
3480
|
+
message: `Failed to write ${filePath}: ${msg}`
|
|
3481
|
+
}
|
|
3482
|
+
})
|
|
3483
|
+
}
|
|
3484
|
+
]
|
|
3485
|
+
});
|
|
3486
|
+
}
|
|
3487
|
+
return;
|
|
3488
|
+
}
|
|
3434
3489
|
if (tool === "screenshot" && typeof result.data === "string") {
|
|
3435
3490
|
const { data, ...metadata } = result;
|
|
3436
3491
|
const mimeType = metadata.format === "png" ? "image/png" : "image/jpeg";
|
|
@@ -3461,7 +3516,6 @@ async function callExtensionTool(tool, input) {
|
|
|
3461
3516
|
},
|
|
3462
3517
|
timer
|
|
3463
3518
|
});
|
|
3464
|
-
const { chromeProfile, ...cleanInput } = input;
|
|
3465
3519
|
const request = {
|
|
3466
3520
|
id: requestId,
|
|
3467
3521
|
type: "tool_call",
|
|
@@ -3540,9 +3594,9 @@ async function handleSwitchBrowser() {
|
|
|
3540
3594
|
|
|
3541
3595
|
// src/setup.ts
|
|
3542
3596
|
import { execSync } from "child_process";
|
|
3543
|
-
import { chmodSync, existsSync as existsSync2, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
3597
|
+
import { chmodSync, existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync, writeFileSync as writeFileSync2 } from "fs";
|
|
3544
3598
|
import { homedir, platform } from "os";
|
|
3545
|
-
import { dirname, resolve } from "path";
|
|
3599
|
+
import { dirname as dirname2, resolve } from "path";
|
|
3546
3600
|
function runSetup(options = {}) {
|
|
3547
3601
|
const os = platform();
|
|
3548
3602
|
const binaryPath = getBinaryPath();
|
|
@@ -3569,11 +3623,11 @@ function runSetup(options = {}) {
|
|
|
3569
3623
|
allowed_origins: allowedOrigins
|
|
3570
3624
|
};
|
|
3571
3625
|
const manifestPath = getManifestPath(os);
|
|
3572
|
-
const manifestDir =
|
|
3626
|
+
const manifestDir = dirname2(manifestPath);
|
|
3573
3627
|
console.log(`Wrapper: ${wrapperPath}`);
|
|
3574
3628
|
console.log(`Manifest path: ${manifestPath}`);
|
|
3575
|
-
|
|
3576
|
-
|
|
3629
|
+
mkdirSync2(manifestDir, { recursive: true });
|
|
3630
|
+
writeFileSync2(manifestPath, JSON.stringify(manifest, null, 2));
|
|
3577
3631
|
chmodSync(manifestPath, 420);
|
|
3578
3632
|
console.log("\nNative Messaging Host registered successfully!");
|
|
3579
3633
|
console.log("\nNext steps:");
|
|
@@ -3595,18 +3649,18 @@ function getBinaryPath() {
|
|
|
3595
3649
|
return resolve(currentScript);
|
|
3596
3650
|
}
|
|
3597
3651
|
function createNativeHostWrapper(os, binaryPath) {
|
|
3598
|
-
const manifestDir =
|
|
3599
|
-
|
|
3652
|
+
const manifestDir = dirname2(getManifestPath(os));
|
|
3653
|
+
mkdirSync2(manifestDir, { recursive: true });
|
|
3600
3654
|
const nodePath = getNodePath();
|
|
3601
3655
|
if (os === "win32") {
|
|
3602
3656
|
const wrapperPath2 = resolve(manifestDir, `${NATIVE_HOST_NAME}.bat`);
|
|
3603
|
-
|
|
3657
|
+
writeFileSync2(wrapperPath2, `@echo off\r
|
|
3604
3658
|
"${nodePath}" "${binaryPath}" --native-host\r
|
|
3605
3659
|
`);
|
|
3606
3660
|
return wrapperPath2;
|
|
3607
3661
|
}
|
|
3608
3662
|
const wrapperPath = resolve(manifestDir, `${NATIVE_HOST_NAME}.sh`);
|
|
3609
|
-
|
|
3663
|
+
writeFileSync2(wrapperPath, `#!/bin/bash
|
|
3610
3664
|
exec "${nodePath}" "${binaryPath}" --native-host
|
|
3611
3665
|
`);
|
|
3612
3666
|
chmodSync(wrapperPath, 493);
|
|
@@ -3664,7 +3718,7 @@ function setupClaudeDesktopConfig() {
|
|
|
3664
3718
|
if (!config.mcpServers || typeof config.mcpServers !== "object") {
|
|
3665
3719
|
config.mcpServers = {};
|
|
3666
3720
|
}
|
|
3667
|
-
const nodeBinDir =
|
|
3721
|
+
const nodeBinDir = dirname2(getNodePath());
|
|
3668
3722
|
const defaultPath = "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin";
|
|
3669
3723
|
const envPath = nodeBinDir ? `${nodeBinDir}:${defaultPath}` : defaultPath;
|
|
3670
3724
|
config.mcpServers["viyv-browser"] = {
|
|
@@ -3672,9 +3726,9 @@ function setupClaudeDesktopConfig() {
|
|
|
3672
3726
|
args: ["-y", "viyv-browser-mcp@latest"],
|
|
3673
3727
|
env: { PATH: envPath }
|
|
3674
3728
|
};
|
|
3675
|
-
const configDir =
|
|
3676
|
-
|
|
3677
|
-
|
|
3729
|
+
const configDir = dirname2(configPath);
|
|
3730
|
+
mkdirSync2(configDir, { recursive: true });
|
|
3731
|
+
writeFileSync2(configPath, JSON.stringify(config, null, 2));
|
|
3678
3732
|
console.log(`npx path: ${npxPath}`);
|
|
3679
3733
|
console.log("\nClaude Desktop config updated successfully!");
|
|
3680
3734
|
console.log("Please restart Claude Desktop for changes to take effect.");
|