jtcrpa-mcp 0.6.1 → 0.7.0

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 CHANGED
@@ -23,7 +23,7 @@
23
23
  此 Codex CLI 流程需要支持浏览器实例绑定的扩展和 0.5.1 或更高版本的桥接器。开发测试可在本仓库运行 `npm run build` 后使用 `npm pack` 生成的本地安装包。
24
24
 
25
25
  3. **连接你要用的浏览器。** 在该浏览器的 **MCP 连接** 页面打开 **开启 MCP 连接** 开关,按提示允许本机通信,然后选择 **Codex** 查看首次接入命令。
26
- 4. **登记 MCP 服务。** 将页面给出的整条命令粘贴到终端运行。命令核对目标浏览器后,显示浏览器名称和 MCP 服务名,然后退出。Codex 加载这项配置后,你可以在自己的对话里提出任务。首次访问后,扩展会显示访问时间。要使用另一份浏览器配置,从那份配置的扩展页接入。[安装 Codex CLI](https://developers.openai.com/codex/cli/) · [使用 Claude Code 或 DeepSeek Harness](docs/usage.md#客户端配置)
26
+ 4. **登记 MCP 服务。** 将页面给出的整条命令粘贴到终端运行。命令核对目标浏览器后,显示浏览器名称和 MCP 服务名,然后退出。Codex 加载这项配置后,你可以在自己的对话里提出任务。首次访问后,扩展会显示访问时间。要使用另一份浏览器配置,从那份配置的扩展页接入。[安装 Codex CLI](https://developers.openai.com/codex/cli/) · [使用 Claude Code、DeepSeek Harness 或 WorkBuddy](docs/usage.md#客户端配置)
27
27
 
28
28
  ### 第一次用 MCP 采集书名和价格
29
29
 
@@ -77,7 +77,7 @@
77
77
  This Codex CLI flow requires an extension that supports browser instance binding and bridge version 0.5.1 or later. To test a development checkout, run `npm run build` and install the local package produced by `npm pack`.
78
78
 
79
79
  3. **Connect the browser you want to use.** In that profile, open **MCP connection**, turn on the connection switch and allow native messaging when prompted. Select **Codex** to see the first-time setup command.
80
- 4. **Register the MCP server.** Run the setup command in your terminal. It verifies the target browser, prints its display name and MCP server name, then exits. Once Codex has loaded the configuration, enter your task in your own conversation. The extension shows the time of the first access. To use another profile, start from its extension page. [Install the Codex CLI](https://developers.openai.com/codex/cli/) · [Use Claude Code or DeepSeek Harness](docs/usage.md#client-configuration)
80
+ 4. **Register the MCP server.** Run the setup command in your terminal. It verifies the target browser, prints its display name and MCP server name, then exits. Once Codex has loaded the configuration, enter your task in your own conversation. The extension shows the time of the first access. To use another profile, start from its extension page. [Install the Codex CLI](https://developers.openai.com/codex/cli/) · [Use Claude Code, DeepSeek Harness or WorkBuddy](docs/usage.md#client-configuration)
81
81
 
82
82
  ### Collect your first four books
83
83
 
package/bin/cli.mjs CHANGED
@@ -13,7 +13,7 @@ const usage = [
13
13
  ' connect-codex (--chrome-id <扩展ID> | --firefox-id <扩展ID>) --instance <UUID> --setup <UUID>',
14
14
  ' config (--connection <连接编号> | --instance <UUID>) [--client codex|claude|deepseek]',
15
15
  ' mcp (--connection <配置中的绑定UUID> | --instance <实例UUID>)',
16
- ' macOS Chrome 的 add 和 connect-codex 可加 --chrome-user-data-dir <用户数据根目录>',
16
+ ' macOS 版 Chrome 和 Edge 的 add 和 connect-codex 可加 --chrome-user-data-dir <用户数据根目录>',
17
17
  '维护',
18
18
  ' uninstall 清除当前用户的本机宿主登记',
19
19
  ' --version 显示桥接器版本',
@@ -51,7 +51,7 @@ export async function connectCodex(args) {
51
51
  const directory = values['chrome-user-data-dir'];
52
52
  if (directory !== undefined)
53
53
  registration.push('--chrome-user-data-dir', directory);
54
- await manageHostRegistration('add', registration);
54
+ await manageHostRegistration('add', registration, { fromRunningBrowser: true });
55
55
  console.log('正在等待发起接入的浏览器…');
56
56
  const setup = await bindCodexBrowser(target, instanceId, ticket);
57
57
  console.log(setup.displayName + ' 已就绪。Codex MCP 服务名为 ' + setup.name);
package/dist/install.js CHANGED
@@ -28,7 +28,7 @@ function installationPaths() {
28
28
  const launcher = process.platform === 'darwin' ? 'host.sh' : 'host.cmd';
29
29
  return { root, record: path.join(root, 'installation.json'), launcher: path.join(root, launcher) };
30
30
  }
31
- export async function manageHostRegistration(command, args) {
31
+ export async function manageHostRegistration(command, args, { fromRunningBrowser = false } = {}) {
32
32
  if (command === 'uninstall' && args.length)
33
33
  throw new Error('uninstall does not accept arguments. See jtcrpa-mcp uninstall --help.');
34
34
  const paths = installationPaths();
@@ -36,7 +36,7 @@ export async function manageHostRegistration(command, args) {
36
36
  if (command === 'uninstall')
37
37
  uninstallNativeHost(paths);
38
38
  else {
39
- const { targets, instanceId, chromeDataDir } = parseBrowserTargets(args);
39
+ const { targets, instanceId, chromeDataDir } = parseBrowserTargets(args, fromRunningBrowser);
40
40
  addNativeHost(paths, targets, instanceId, chromeDataDir);
41
41
  }
42
42
  });
@@ -151,7 +151,7 @@ function uninstallNativeHost(paths) {
151
151
  removeFileIfPresent(paths.launcher);
152
152
  console.log('Native host unregistered.');
153
153
  }
154
- function parseBrowserTargets(args) {
154
+ function parseBrowserTargets(args, fromRunningBrowser) {
155
155
  const { values } = parseArgs({ args, options: {
156
156
  'chrome-user-data-dir': { type: 'string' }, 'chrome-id': { type: 'string' }, 'firefox-id': { type: 'string' }, instance: { type: 'string' },
157
157
  } });
@@ -174,7 +174,7 @@ function parseBrowserTargets(args) {
174
174
  if (explicit !== undefined && (!chrome || process.platform !== 'darwin')) {
175
175
  throw new Error('--chrome-user-data-dir 仅适用于 macOS 上的 --chrome-id。');
176
176
  }
177
- const chromeDataDir = chrome && process.platform === 'darwin' ? resolveChromeDataDir(chrome, explicit) : undefined;
177
+ const chromeDataDir = chrome && process.platform === 'darwin' ? resolveChromeDataDir(chrome, explicit, fromRunningBrowser) : undefined;
178
178
  return { targets, instanceId: values.instance, chromeDataDir };
179
179
  }
180
180
  function prepareInstallationDirectory(root) {
@@ -6,11 +6,13 @@ export const defaultChromeDataDir = () => path.join(os.homedir(), 'Library/Appli
6
6
  // ps on macOS flattens argv. Keep spaces inside paths and ignore trailing
7
7
  // positional arguments (e.g. a URL) after an existing user data directory.
8
8
  function dataDirFromCommand(command) {
9
- if (!/^\/.*\/Google Chrome\.app\/Contents\/MacOS\/Google Chrome(?:\s|$)/.test(command))
9
+ const browser = /^\/.*\/(Google Chrome|Microsoft Edge)\.app\/Contents\/MacOS\/\1(?:\s|$)/.exec(command)?.[1];
10
+ if (!browser)
10
11
  return;
11
12
  const flag = /\s--user-data-dir(?:=|\s+)(.+?)(?=\s--|$)/.exec(command);
12
13
  if (!flag)
13
- return defaultChromeDataDir();
14
+ return browser === 'Microsoft Edge'
15
+ ? path.join(os.homedir(), 'Library/Application Support/Microsoft Edge') : defaultChromeDataDir();
14
16
  let value = flag[1].trim();
15
17
  while (path.isAbsolute(value)) {
16
18
  if (fs.statSync(path.join(value, 'Local State'), { throwIfNoEntry: false })?.isFile())
@@ -22,7 +24,7 @@ function dataDirFromCommand(command) {
22
24
  }
23
25
  }
24
26
  function runningChromeDirs() {
25
- const found = spawnSync('/usr/bin/pgrep', ['-u', String(process.getuid()), '-x', 'Google Chrome'], { encoding: 'utf8' });
27
+ const found = spawnSync('/usr/bin/pgrep', ['-u', String(process.getuid()), '-x', '(Google Chrome|Microsoft Edge)'], { encoding: 'utf8' });
26
28
  const pids = found.stdout?.trim().split(/\s+/);
27
29
  if (found.status !== 0 || !pids?.every(pid => /^\d+$/.test(pid)))
28
30
  return new Set();
@@ -61,7 +63,7 @@ function hasExtension(root, extensionId) {
61
63
  }
62
64
  return false;
63
65
  }
64
- export function resolveChromeDataDir(extensionId, explicit) {
66
+ export function resolveChromeDataDir(extensionId, explicit, fromRunningBrowser = false) {
65
67
  if (explicit !== undefined) {
66
68
  if (!path.isAbsolute(explicit) || !fs.statSync(path.join(explicit, 'Local State'), { throwIfNoEntry: false })?.isFile()) {
67
69
  throw new Error('--chrome-user-data-dir 需要现有 Chrome 用户数据根目录的绝对路径(含 Local State)。');
@@ -69,9 +71,13 @@ export function resolveChromeDataDir(extensionId, explicit) {
69
71
  return fs.realpathSync(explicit);
70
72
  }
71
73
  const dirs = runningChromeDirs();
74
+ // connect-codex originates in a live browser. A single root is sufficient
75
+ // even when macOS does not allow enumeration of the profile directory.
76
+ if (fromRunningBrowser && dirs.size === 1)
77
+ return [...dirs][0];
72
78
  const matches = [...dirs].filter(dir => hasExtension(dir, extensionId));
73
- if (matches.length > 1) {
74
- throw new Error('多个运行中的 Chrome 用户数据目录含此扩展,请用 --chrome-user-data-dir 指定目标目录。');
79
+ if (matches.length > 1 || (fromRunningBrowser && dirs.size > 1 && !matches.length)) {
80
+ throw new Error('无法唯一确定 Chrome 或 Edge 的用户数据目录,请用 --chrome-user-data-dir 指定目标目录。');
75
81
  }
76
82
  return matches[0] ?? defaultChromeDataDir();
77
83
  }
package/dist/methods.js CHANGED
@@ -1,2 +1,2 @@
1
1
  /** Native host 白名单与 MCP 工具面同步;不接受任意扩展 RPC。 */
2
- export const METHODS = ['connection_status', 'connection_ping', 'browser_context', 'page_open', 'page_close', 'workflow_contract', 'page_probe', 'workflow_list', 'workflow_get', 'workflow_save', 'workflow_run', 'run_get', 'run_control', 'dataset_list', 'dataset_read'];
2
+ export const METHODS = ['connection_status', 'connection_ping', 'browser_context', 'page_open', 'page_close', 'workflow_contract', 'capability_probe', 'page_probe', 'workflow_list', 'workflow_get', 'workflow_save', 'workflow_run', 'run_get', 'run_control', 'dataset_list', 'dataset_read'];
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod/v4';
2
2
  import { pageTargetFields } from "./definition.js";
3
- const probeNames = [
3
+ const pageProbeNames = [
4
4
  'snapshot',
5
5
  'queryFrames',
6
6
  'probeElement',
@@ -8,6 +8,7 @@ const probeNames = [
8
8
  'probeClick',
9
9
  'probeScroll',
10
10
  ];
11
+ const capabilityProbeNames = ['probeUserScript', 'probeFileAccess', 'probeFeishu'];
11
12
  export const authoringTools = [
12
13
  {
13
14
  name: 'browser_context',
@@ -39,18 +40,25 @@ export const authoringTools = [
39
40
  schema: z.object({
40
41
  includeGuide: z.boolean().optional(),
41
42
  nodeTools: z.array(z.string()).max(6).optional(),
42
- probeTools: z.array(z.enum(probeNames)).max(6).optional(),
43
+ probeTools: z.array(z.enum([...pageProbeNames, ...capabilityProbeNames])).max(6).optional(),
43
44
  }),
44
45
  readOnly: true,
45
46
  openWorld: false,
46
47
  },
48
+ {
49
+ name: 'capability_probe',
50
+ description: '检查绑定实例的用户脚本权限、本地文件读取能力或飞书凭据配置。仅查指定项,无需标签页。READY 只确认对应的本机条件;BLOCKED 按原因处理。检查失败时权限未知。设置改变后重新检查。',
51
+ schema: z.object({ tool: z.enum(capabilityProbeNames) }).strict(),
52
+ readOnly: true,
53
+ openWorld: false,
54
+ },
47
55
  {
48
56
  name: 'page_probe',
49
57
  description: '在明确的标签页及 Frame 中调用白名单编译期探针。先通过 workflow_contract 获取其 params Schema。' +
50
58
  '点击和滚动会真实操作页面,必须提供 requestId,且探测范围须在用户授权之内。' +
51
59
  'clean 通过现有沙箱执行。不提供任意 RPC 或 JavaScript 求值接口。',
52
60
  schema: z.object({
53
- tool: z.enum(probeNames),
61
+ tool: z.enum(pageProbeNames),
54
62
  ...pageTargetFields,
55
63
  frameId: z.number().int().nonnegative().optional(),
56
64
  params: z.record(z.string(), z.unknown()).optional(),
@@ -35,6 +35,9 @@ async function forwardToolCall(target, definition, params) {
35
35
  else if (failure.error === 'CONNECTION_INSTANCE_MISMATCH' || failure.error === 'CONNECTION_REMOVED') {
36
36
  failure.message = '原浏览器绑定已变更,请从目标浏览器重新接入。';
37
37
  }
38
+ else if (failure.error === 'UNKNOWN_METHOD' && definition.name === 'capability_probe') {
39
+ failure.message = '当前连接缺少能力检查工具,权限状态未知。请配套更新九头虫扩展和本机桥接器。';
40
+ }
38
41
  else if (failure.error === 'UNKNOWN_METHOD' && (definition.name === 'page_open' || definition.name === 'page_close')) {
39
42
  failure.message = '当前连接尚未提供此页面工具。请配套更新目标浏览器中的九头虫扩展和本机桥接器。';
40
43
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jtcrpa-mcp",
3
- "version": "0.6.1",
3
+ "version": "0.7.0",
4
4
  "type": "module",
5
5
  "description": "在 macOS 和 Windows 上用 Codex 等 AI 客户端连接九头虫 Agent,创建和运行网页采集工作流、读取数据集。Connect AI clients to Jiutouchong Agent on macOS and Windows via MCP to create and run web scraping workflows and read datasets.",
6
6
  "homepage": "https://jtcrpa.com/",