@attson/atwebpilot-mcp 0.0.79 → 0.0.80

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
@@ -17,11 +17,11 @@ Claude Code:
17
17
  **不需要手填端口。** 从 Plan 33 起是配对流程:
18
18
 
19
19
  1. 会话启动时**不绑任何端口** —— 不碰网页的会话零副作用。
20
- 2. AI 第一次调 `list_tabs` / `pairing_status` 时才绑一个空闲端口,通过 MCP URL elicitation 请宿主打开配对页,并立即返回 `pairing_required + pair_url`,不阻塞等待;不支持该能力的宿主回退到系统默认浏览器。
21
- 3. 你在浏览器里点「允许」,扩展即接入;AI 用轻量 `pairing_status` 确认连接后再读取 tab,不重复阻塞式调用。
20
+ 2. AI 第一次调 `list_tabs` 时才绑一个空闲端口,通过 MCP URL elicitation 请宿主打开配对页;不支持该能力的宿主回退到系统默认浏览器。`list_tabs` 最多等待 45 秒。
21
+ 3. 你在浏览器里点「允许」,扩展即接入;同一次 `list_tabs` 调用直接返回 tab,AI 无需让你回复「已连接」。只有等待超时才返回 `pairing_required + pair_url`;`pairing_status` 始终是立即返回的非阻塞状态检查。
22
22
  4. 之后本机的会话都免确认(信任是安装级的);端口能复用时连配对页都不会弹。
23
23
 
24
- 若宿主和系统都未弹出浏览器,可直接打开返回结果中的 `pair_url`。授权成功只以扩展实际建立连接并发送 `HELLO` 为准;打开配对页本身不代表已连接。
24
+ 若宿主和系统都未弹出浏览器,可在超时结果中打开 `pair_url`。授权成功只以扩展实际建立连接并发送 `HELLO` 为准;打开配对页本身不代表已连接。
25
25
 
26
26
  多个 Codex / Claude Code 会话可以同时接入同一个浏览器,各自一条连接。可在扩展设置 →
27
27
  Coordinator 查看已接入的会话、单独断开,或撤销信任。
package/dist/index.js CHANGED
@@ -953,7 +953,7 @@ var CONTROL_TOOLS = [
953
953
  },
954
954
  {
955
955
  name: "list_tabs",
956
- description: "List browser tabs. If pairing is needed, opens the pair page and immediately returns pairing_required with its URL; wait for user approval, then call pairing_status instead of retrying this tool.",
956
+ description: "List browser tabs. On first use, opens the pairing page and waits up to 45 seconds for authorization, normally returning connected tabs in the same call. Returns pairing_required with the URL only on timeout.",
957
957
  inputSchema: { type: "object", properties: {}, additionalProperties: false }
958
958
  },
959
959
  {
@@ -2325,7 +2325,18 @@ function locate(source, offset) {
2325
2325
  return { line, col };
2326
2326
  }
2327
2327
 
2328
+ // src/pairing-errors.ts
2329
+ var PairingWaitTimeoutError = class extends Error {
2330
+ constructor(timeoutMs, pairUrl) {
2331
+ super(
2332
+ `\u7B49\u5F85\u6D4F\u89C8\u5668\u6388\u6743\u8D85\u65F6\uFF08${Math.ceil(timeoutMs / 1e3)} \u79D2\uFF09\u3002` + (pairUrl ? `\u8BF7\u6253\u5F00\u914D\u5BF9\u9875 ${pairUrl} \u5B8C\u6210\u6388\u6743\u540E\u91CD\u8BD5\u3002` : "")
2333
+ );
2334
+ this.name = "PairingWaitTimeoutError";
2335
+ }
2336
+ };
2337
+
2328
2338
  // src/handlers.ts
2339
+ var LIST_TABS_PAIRING_TIMEOUT_MS = 45e3;
2329
2340
  function singleWorkerId(c, pairUrl) {
2330
2341
  const workers = c.workers.list();
2331
2342
  if (workers.length === 0) {
@@ -2349,17 +2360,32 @@ async function handlePairingStatus(deps) {
2349
2360
  if (!pairUrl) throw new Error("PAIRING_REQUIRED: \u914D\u5BF9\u670D\u52A1\u5DF2\u542F\u52A8\uFF0C\u4F46\u914D\u5BF9\u9875\u5C1A\u4E0D\u53EF\u7528");
2350
2361
  return { status: "pairing_required", pair_url: pairUrl };
2351
2362
  }
2352
- async function handleListTabs(deps) {
2363
+ async function handleListTabs(deps, onPairingRequired, timeoutMs = LIST_TABS_PAIRING_TIMEOUT_MS) {
2353
2364
  const { coordinator } = await deps.ensure();
2354
2365
  const workers = coordinator.workers.list();
2355
2366
  if (workers.length > 1) {
2356
2367
  throw new Error("\u68C0\u6D4B\u5230\u591A\u4E2A\u6D4F\u89C8\u5668\u8FDE\u5165\uFF1Bv1 \u4EC5\u652F\u6301\u5355 worker\uFF0C\u8BF7\u53EA\u4FDD\u7559\u4E00\u4E2A\u8FDE\u63A5");
2357
2368
  }
2358
- const worker = workers[0];
2369
+ let worker = workers[0];
2359
2370
  if (!worker) {
2360
2371
  const pairUrl = deps.pairUrl();
2361
2372
  if (!pairUrl) throw new Error("PAIRING_REQUIRED: \u914D\u5BF9\u670D\u52A1\u5DF2\u542F\u52A8\uFF0C\u4F46\u914D\u5BF9\u9875\u5C1A\u4E0D\u53EF\u7528");
2362
- return { status: "pairing_required", pair_url: pairUrl, tabs: [] };
2373
+ try {
2374
+ await deps.waitForWorker(timeoutMs, onPairingRequired);
2375
+ } catch (error) {
2376
+ if (error instanceof PairingWaitTimeoutError) {
2377
+ return { status: "pairing_required", pair_url: pairUrl, tabs: [] };
2378
+ }
2379
+ throw error;
2380
+ }
2381
+ const connectedWorkers = coordinator.workers.list();
2382
+ if (connectedWorkers.length > 1) {
2383
+ throw new Error("\u68C0\u6D4B\u5230\u591A\u4E2A\u6D4F\u89C8\u5668\u8FDE\u5165\uFF1Bv1 \u4EC5\u652F\u6301\u5355 worker\uFF0C\u8BF7\u53EA\u4FDD\u7559\u4E00\u4E2A\u8FDE\u63A5");
2384
+ }
2385
+ worker = connectedWorkers[0];
2386
+ if (!worker) {
2387
+ return { status: "pairing_required", pair_url: pairUrl, tabs: [] };
2388
+ }
2363
2389
  }
2364
2390
  return { status: "connected", tabs: worker.available_tabs };
2365
2391
  }
@@ -2460,16 +2486,16 @@ var SKILL_DESCRIPTION = "Strategy + scenarios + safety rails for driving the AtW
2460
2486
  var TOPICS = {
2461
2487
  quickstart: `# AtWebPilot quickstart
2462
2488
 
2463
- 1. Call list_tabs once. If it returns pairing_required, show pair_url and wait for the user to approve.
2464
- 2. After approval, call pairing_status. Do not retry list_tabs while status is unchanged.
2465
- 3. Call list_tabs when connected, choose a tab, then open_session with its tab_id.
2489
+ 1. Call list_tabs once. On first use it opens the pairing page and waits for authorization, then normally returns connected tabs in the same call.
2490
+ 2. If list_tabs times out and returns pairing_required, show pair_url and wait for browser approval. Use pairing_status for a later non-blocking status check; do not ask the user to reply just to continue.
2491
+ 3. Choose a returned tab, then call open_session with its tab_id.
2466
2492
  4. For interaction use browser_getPageInfo then browser_takeSnapshot; for broad reading use browser_createPageIndex.
2467
2493
  5. Prefer purpose-built tools and verified results. Use browser_discoverTools only for capabilities outside the connected core surface. Its response always includes the selected schemas. If a newly enabled native tool is not visible in the current turn, call it immediately with browser_call; do not ask the user to send "continue".
2468
2494
  6. Close the session when finished.
2469
2495
  `,
2470
2496
  pairing: `# AtWebPilot pairing
2471
2497
 
2472
- list_tabs and pairing_status never wait for browser authorization. A pairing_required result includes pair_url. Show that URL once and wait for the user to approve in the browser. Then call pairing_status; only call list_tabs after it reports connected. Never poll list_tabs or inspect the pair-page HTML.
2498
+ list_tabs opens the pairing page when needed and waits up to 45 seconds for the extension's HELLO, so successful authorization normally returns connected tabs in the same call. pairing_status remains immediate and non-blocking. A pairing_required result from list_tabs means the bounded wait expired; show pair_url once and use pairing_status for a later check. Never ask the user to reply merely to continue, poll list_tabs, or inspect the pair-page HTML.
2473
2499
  `,
2474
2500
  reading: `# AtWebPilot reading
2475
2501
 
@@ -2543,7 +2569,7 @@ var SKILL_TOOL = {
2543
2569
  // package.json
2544
2570
  var package_default = {
2545
2571
  name: "@attson/atwebpilot-mcp",
2546
- version: "0.0.79",
2572
+ version: "0.0.80",
2547
2573
  license: "Apache-2.0",
2548
2574
  description: "MCP server for the atwebpilot browser extension - let Codex or Claude Code drive your browser.",
2549
2575
  homepage: "https://github.com/attson/atwebpilot#readme",
@@ -2744,9 +2770,8 @@ async function dispatchCall(deps, name, args, state = DEFAULT_STATE, onListChang
2744
2770
  return ok(result);
2745
2771
  }
2746
2772
  if (name === "list_tabs") {
2747
- const result = await handleListTabs(deps);
2773
+ const result = await handleListTabs(deps, onPairingRequired);
2748
2774
  if (result.status === "connected") await revealBrowserSurface(state, onListChanged);
2749
- else onPairingRequired?.(result.pair_url);
2750
2775
  return ok(result);
2751
2776
  }
2752
2777
  if (name === "open_session") {
@@ -3440,6 +3465,14 @@ function createHubEnsurer(d) {
3440
3465
  );
3441
3466
  }
3442
3467
  if (pairUrlValue) await onWaiting?.(pairUrlValue);
3468
+ const connectedAfterPresentation = connectedWorkerId(coordinator);
3469
+ if (connectedAfterPresentation) return connectedAfterPresentation;
3470
+ if (pendingDenial) {
3471
+ pendingDenial = false;
3472
+ throw new Error(
3473
+ "\u7528\u6237\u62D2\u7EDD\u4E86\u6D4F\u89C8\u5668\u914D\u5BF9\u6388\u6743\u3002" + (pairUrlValue ? `\u914D\u5BF9\u9875\uFF1A${pairUrlValue}` : "")
3474
+ );
3475
+ }
3443
3476
  if (workerWait) return workerWait.promise;
3444
3477
  let resolve;
3445
3478
  let reject;
@@ -3449,9 +3482,7 @@ function createHubEnsurer(d) {
3449
3482
  });
3450
3483
  const timer = setTimeout(() => {
3451
3484
  finishWorkerWait({
3452
- error: new Error(
3453
- `\u7B49\u5F85\u6D4F\u89C8\u5668\u6388\u6743\u8D85\u65F6\uFF08${Math.ceil(timeoutMs / 1e3)} \u79D2\uFF09\u3002` + (pairUrlValue ? `\u8BF7\u6253\u5F00\u914D\u5BF9\u9875 ${pairUrlValue} \u5B8C\u6210\u6388\u6743\u540E\u91CD\u8BD5\u3002` : "")
3454
- )
3485
+ error: new PairingWaitTimeoutError(timeoutMs, pairUrlValue)
3455
3486
  });
3456
3487
  }, timeoutMs);
3457
3488
  timer.unref?.();
@@ -13,8 +13,9 @@ When this skill is loaded, you can drive any open tab through these tools
13
13
  ### Control plane
14
14
 
15
15
  - `pairing_status` — start/check pairing without waiting. When it reports
16
- `pairing_required`, show `pair_url` once and wait for browser approval.
17
- - `list_tabs` — enumerate Chrome tabs you can operate on. Entries carry `busy`
16
+ `pairing_required`, show `pair_url` once; use it only as a later status check.
17
+ - `list_tabs` — on first use, open the pairing page and wait up to 45 seconds
18
+ for browser authorization, normally returning tabs from the same call. Entries carry `busy`
18
19
  and `busy_label` when **another** Claude Code session is already driving that
19
20
  tab, and `mine` for tabs you hold. This is advisory — nothing blocks you — but
20
21
  contending for a tab another agent is typing into is rarely what you want.
@@ -87,7 +88,7 @@ compatibility path; use the native tool once the host exposes it.
87
88
 
88
89
  ## Recommended flow
89
90
 
90
- 1. **先建立连接**:调一次 `list_tabs`;若返回 `pairing_required`,展示 `pair_url` 并等待用户批准。批准后只调 `pairing_status`,它报告 `connected` 后再调 `list_tabs`,不要轮询 `list_tabs`。
91
+ 1. **先建立连接**:调一次 `list_tabs`;首次配对时它会打开授权页并等待最多 45 秒,授权成功后同一次调用直接返回 tab,不要让用户回复「已连接」。只有超时才会返回 `pairing_required`;此时展示 `pair_url`,稍后用非阻塞的 `pairing_status` 检查,不要轮询 `list_tabs`。
91
92
  2. **探查先于操作**:每次进入新页面,先 `getPageInfo` 确认位置,再 `takeSnapshot`(要点击/填表)或 `createPageIndex`(要读内容/抽字段);`snapshotDOM` / `querySelector` 属于 legacy-dom 组,只在需要分析整页结构时通过 `browser_discoverTools` 启用。
92
93
  3. **最少充分验证**:危险或不可逆操作保持单步;多个独立字段用 `fillForm`。工具已返回 `verified` 或明确后置状态时,不要再用 `runJS` 重复验证。
93
94
  4. **dangerous 工具会被人工审核**:调用前用 `extractText` 给用户看上下文,让审批更顺。
@@ -260,12 +261,13 @@ not the whole history.
260
261
  Several Claude Code sessions can be attached to the same browser at once, each
261
262
  through its own connection. Two consequences worth knowing:
262
263
 
263
- - **Pairing is non-blocking.** `list_tabs` lazily binds the port and opens a
264
- confirmation page, then immediately returns `pairing_required` with
265
- `pair_url`. Ask the user to click Allow. After they confirm, call
266
- `pairing_status`; call `list_tabs` again only when it reports `connected`.
267
- Never inspect the pair-page HTML or retry `list_tabs` while state is unchanged.
268
- Once approved, later sessions on that machine connect silently.
264
+ - **Pairing continues in the same call.** `list_tabs` lazily binds the port,
265
+ opens a confirmation page, and waits up to 45 seconds for the extension's
266
+ `HELLO`. Successful approval returns connected tabs directly; do not ask the
267
+ user to reply just to continue. On timeout it returns `pairing_required` with
268
+ `pair_url`; use non-blocking `pairing_status` for a later check. Never inspect
269
+ the pair-page HTML or poll `list_tabs`. Once approved, later sessions on that
270
+ machine connect silently.
269
271
  - **Pick a free tab.** `list_tabs` marks tabs held by other sessions as `busy`.
270
272
  Prefer an unowned tab, or open your own — two agents typing into one form
271
273
  produces failures that look like your own tool calls not working.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@attson/atwebpilot-mcp",
3
- "version": "0.0.79",
3
+ "version": "0.0.80",
4
4
  "license": "Apache-2.0",
5
5
  "description": "MCP server for the atwebpilot browser extension - let Codex or Claude Code drive your browser.",
6
6
  "homepage": "https://github.com/attson/atwebpilot#readme",