openclaw-navigator 4.3.4 → 4.3.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/cli.mjs +63 -43
- package/package.json +1 -1
package/cli.mjs
CHANGED
|
@@ -772,53 +772,73 @@ ${BOLD}How it works:${RESET}
|
|
|
772
772
|
ok(`MCP server started (PID ${mcpProcess.pid}) — bridge: http://localhost:${port}`);
|
|
773
773
|
|
|
774
774
|
// ── Auto-register MCP server with mcporter (if available) ─────────
|
|
775
|
-
//
|
|
776
|
-
//
|
|
775
|
+
// Writes directly to ~/.mcporter/mcporter.json for reliability.
|
|
776
|
+
//
|
|
777
|
+
// KEY FIX: We resolve stable paths instead of using process.execPath
|
|
778
|
+
// which may point to a temp npx cache (/Users/x/.npm/_npx/<hash>/node)
|
|
779
|
+
// that disappears after npx exits. We find the REAL node binary and
|
|
780
|
+
// the globally-installed mcp.mjs (or realpath of the current one).
|
|
777
781
|
try {
|
|
778
|
-
const
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
"--env",
|
|
789
|
-
`NAVIGATOR_BRIDGE_URL=http://localhost:${port}`,
|
|
790
|
-
"--description",
|
|
791
|
-
"Navigator browser control (15 tools: navigate, click, fill, read, etc.)",
|
|
792
|
-
"--scope",
|
|
793
|
-
"home",
|
|
794
|
-
],
|
|
795
|
-
{ stdio: ["ignore", "pipe", "pipe"] },
|
|
796
|
-
);
|
|
797
|
-
|
|
798
|
-
let regOut = "";
|
|
799
|
-
reg.stdout?.on("data", (d) => {
|
|
800
|
-
regOut += d.toString();
|
|
801
|
-
});
|
|
802
|
-
reg.stderr?.on("data", (d) => {
|
|
803
|
-
regOut += d.toString();
|
|
804
|
-
});
|
|
782
|
+
const { readFileSync, writeFileSync, mkdirSync, realpathSync } = await import("node:fs");
|
|
783
|
+
const { homedir } = await import("node:os");
|
|
784
|
+
|
|
785
|
+
// Resolve stable node binary (follow symlinks out of npx temp dir)
|
|
786
|
+
let stableNode;
|
|
787
|
+
try {
|
|
788
|
+
stableNode = realpathSync(process.execPath);
|
|
789
|
+
} catch {
|
|
790
|
+
stableNode = process.execPath;
|
|
791
|
+
}
|
|
805
792
|
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
793
|
+
// Resolve stable mcp.mjs path
|
|
794
|
+
let stableMcpPath;
|
|
795
|
+
try {
|
|
796
|
+
stableMcpPath = realpathSync(mcpPath);
|
|
797
|
+
} catch {
|
|
798
|
+
stableMcpPath = mcpPath;
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
// If paths are still in npx temp cache, try to find the real install
|
|
802
|
+
if (stableMcpPath.includes("_npx") || stableMcpPath.includes(".npm/_npx")) {
|
|
803
|
+
// Check if openclaw-navigator is installed globally
|
|
804
|
+
const nodeDir = dirname(stableNode);
|
|
805
|
+
const globalMcp = join(dirname(nodeDir), "lib/node_modules/openclaw-navigator/mcp.mjs");
|
|
806
|
+
if (existsSync(globalMcp)) {
|
|
807
|
+
stableMcpPath = globalMcp;
|
|
814
808
|
}
|
|
815
|
-
|
|
809
|
+
// If still temp, that's OK — mcporter will use the path we give it
|
|
810
|
+
// and the bridge running alongside keeps the MCP server alive anyway
|
|
811
|
+
}
|
|
816
812
|
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
813
|
+
info(` mcporter: node=${stableNode}`);
|
|
814
|
+
info(` mcporter: mcp=${stableMcpPath}`);
|
|
815
|
+
|
|
816
|
+
// Write directly to ~/.mcporter/mcporter.json
|
|
817
|
+
const mcporterDir = join(homedir(), ".mcporter");
|
|
818
|
+
const mcporterConfigPath = join(mcporterDir, "mcporter.json");
|
|
819
|
+
|
|
820
|
+
let mcporterConfig = { mcpServers: {}, imports: [] };
|
|
821
|
+
try {
|
|
822
|
+
mcporterConfig = JSON.parse(readFileSync(mcporterConfigPath, "utf8"));
|
|
823
|
+
if (!mcporterConfig.mcpServers) mcporterConfig.mcpServers = {};
|
|
824
|
+
} catch {
|
|
825
|
+
// File doesn't exist or invalid — start fresh
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
// Set/update the navigator entry with stable paths
|
|
829
|
+
mcporterConfig.mcpServers.navigator = {
|
|
830
|
+
command: stableNode,
|
|
831
|
+
args: [stableMcpPath],
|
|
832
|
+
env: { NAVIGATOR_BRIDGE_URL: `http://localhost:${port}` },
|
|
833
|
+
};
|
|
834
|
+
|
|
835
|
+
mkdirSync(mcporterDir, { recursive: true });
|
|
836
|
+
writeFileSync(mcporterConfigPath, JSON.stringify(mcporterConfig, null, 2) + "\n", "utf8");
|
|
837
|
+
ok("Registered MCP server with mcporter (15 browser tools available)");
|
|
838
|
+
info(` Config: ${mcporterConfigPath}`);
|
|
839
|
+
} catch (err) {
|
|
840
|
+
warn(`mcporter registration failed: ${err.message}`);
|
|
841
|
+
info(" You can manually configure mcporter for Navigator MCP");
|
|
822
842
|
}
|
|
823
843
|
|
|
824
844
|
console.log("");
|