browser-ref-mcp 0.1.0 → 0.1.1
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 +12 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// 入口:stdio MCP server。日志只进文件/stderr,stdout 专用于 MCP 协议。
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
3
4
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
4
5
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
5
6
|
import { loadConfig } from "./config.js";
|
|
@@ -7,12 +8,20 @@ import { BrowserManager } from "./browserManager.js";
|
|
|
7
8
|
import { RefRegistry } from "./snapshot.js";
|
|
8
9
|
import { registerTools } from "./tools.js";
|
|
9
10
|
import { initLogging, log } from "./util.js";
|
|
11
|
+
// 版本号只从 package.json 取一处,避免发版时漏改。
|
|
12
|
+
// dist/index.js 的上一级就是包根目录。
|
|
13
|
+
const pkg = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8"));
|
|
10
14
|
async function main() {
|
|
15
|
+
// --version (直接输出后退出,此时不进入 MCP 协议,可安全用 stdout)
|
|
16
|
+
if (process.argv.includes("--version") || process.argv.includes("-v")) {
|
|
17
|
+
process.stdout.write(`${pkg.version}\n`);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
11
20
|
// --help / --version
|
|
12
21
|
if (process.argv.includes("--help") || process.argv.includes("-h")) {
|
|
13
|
-
process.stderr.write(`browser-ref-mcp — 给 agent 用的可靠浏览器控制 MCP server
|
|
22
|
+
process.stderr.write(`browser-ref-mcp ${pkg.version} — 给 agent 用的可靠浏览器控制 MCP server
|
|
14
23
|
|
|
15
|
-
用法:
|
|
24
|
+
用法: npx browser-ref-mcp [选项]
|
|
16
25
|
--cdp-url <url> connect 模式:连接已开调试端口的浏览器(如 http://127.0.0.1:9222)
|
|
17
26
|
--headless 无头模式(默认有头)
|
|
18
27
|
--profile <dir> 指定 profile 用户数据目录(默认 ~/.browser-mcp/profile)
|
|
@@ -31,7 +40,7 @@ async function main() {
|
|
|
31
40
|
await log("info", "server starting", { pid: process.pid, mode: cfg.mode, headless: cfg.headless, profile: cfg.profileDir });
|
|
32
41
|
const manager = new BrowserManager(cfg);
|
|
33
42
|
const registry = new RefRegistry();
|
|
34
|
-
const server = new Server({ name: "browser-ref-mcp", version:
|
|
43
|
+
const server = new Server({ name: "browser-ref-mcp", version: pkg.version }, { capabilities: { tools: {} } });
|
|
35
44
|
registerTools(server, manager, registry);
|
|
36
45
|
// 优雅退出:关闭浏览器防止僵尸进程;connect 模式只断开
|
|
37
46
|
let shuttingDown = false;
|
package/package.json
CHANGED