mcp-browser-dev-tools 0.2.0 → 0.2.2

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
@@ -93,6 +93,40 @@ A `run_steps` call that dismisses a cookie banner if one is showing, fills in an
93
93
 
94
94
  The result has each step's outcome: which branch the `if` took, which `anyOf` alternative matched, and the message element with its text. Locators can be CSS, `text=`, `role=` with an accessible name, or `name=`. The full semantics of `run_steps`, `if`, `repeat`, and conditions are in [Tools](docs/tools.md#batched-steps).
95
95
 
96
+ ## Many Pages At Once
97
+
98
+ ![An AI agent sends one run_tabs call with four URLs, the browser loads and reads them side by side, and one reply comes back with every page's text](docs/images/run-tabs.svg)
99
+
100
+ A research step usually means opening several pages and reading each one. `read_text` with `links: true` collects the result links from a search page; then one `run_tabs` call opens them all and reads them side by side:
101
+
102
+ ```json
103
+ {
104
+ "browserFamily": "chromium",
105
+ "tabs": [
106
+ {
107
+ "url": "https://docs.example.com/a",
108
+ "steps": [{ "tool": "read_text", "arguments": { "maxChars": 4000 } }]
109
+ },
110
+ {
111
+ "url": "https://blog.example.com/b",
112
+ "steps": [{ "tool": "read_text", "arguments": { "maxChars": 4000 } }]
113
+ },
114
+ {
115
+ "url": "https://news.example.com/d",
116
+ "steps": [
117
+ { "tool": "wait_for", "arguments": { "selector": "article" } },
118
+ {
119
+ "tool": "read_text",
120
+ "arguments": { "selector": "article", "maxChars": 4000 }
121
+ }
122
+ ]
123
+ }
124
+ ]
125
+ }
126
+ ```
127
+
128
+ The result lists every tab in the order given, each with its steps' results: here, each page's main text, cut to `maxChars`. Each tab opens a new tab, loads its URL, and runs its steps at the same time as the others, so the call takes about as long as the slowest page; the tabs close afterwards. Steps are the same as in `run_steps`, including `if` and `repeat`, and a tab that fails or runs past its `timeoutMs` does not stop the others. `browserFamily` picks the browser for the new tabs when the server runs in its default `auto` mode. The details are in [Tools](docs/tools.md#several-tabs-at-once).
129
+
96
130
  ## Measured
97
131
 
98
132
  Model turns per task, median of 3 runs, from the benchmark in [PERFORMANCE.md](PERFORMANCE.md):
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-browser-dev-tools",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Browser MCP server for AI agents: batch actions, waits, and checks into one call on Chrome, Edge, or Firefox (CDP and WebDriver BiDi)",
5
5
  "author": "Hinaser <rindo.hinase@gmail.com>",
6
6
  "license": "MIT",
@@ -31,6 +31,7 @@
31
31
  "src/doctor.mjs",
32
32
  "src/firefox-bidi-client.mjs",
33
33
  "src/index.mjs",
34
+ "src/input-delivery.mjs",
34
35
  "src/json-rpc-stdio.mjs",
35
36
  "src/keyboard.mjs",
36
37
  "src/logger.mjs",
@@ -8,9 +8,11 @@ import { waitForPageCondition } from "./wait-for.mjs";
8
8
  import {
9
9
  assertEnabled,
10
10
  assertPointerTarget,
11
+ buildInputRecorderExpression,
11
12
  buildPageContextExpression,
12
13
  } from "./page-context.mjs";
13
14
  import { buildCdpKeyEvents } from "./keyboard.mjs";
15
+ import { sendCheckedInput } from "./input-delivery.mjs";
14
16
 
15
17
  function toErrorMessage(error) {
16
18
  return error instanceof Error ? error.message : String(error);
@@ -466,6 +468,7 @@ export class CdpSession {
466
468
  this.send("Network.enable"),
467
469
  ]);
468
470
 
471
+ await this.installInputRecorder();
469
472
  await this.seedBufferedState();
470
473
 
471
474
  return this.getSummary();
@@ -894,15 +897,36 @@ export class CdpSession {
894
897
  });
895
898
  }
896
899
 
897
- async resolvePointerTarget(selector) {
900
+ async resolvePointerTarget(selector, options = {}) {
898
901
  const target = await this.runPageAction({
899
902
  action: "pointer_target",
900
903
  selector,
904
+ ...(options.inputProbe ? { inputProbe: options.inputProbe } : {}),
901
905
  });
902
906
  assertPointerTarget(target);
903
907
  return target;
904
908
  }
905
909
 
910
+ async readInputProbe(token, disarm) {
911
+ try {
912
+ const probe = await this.runPageAction({
913
+ action: "input_probe",
914
+ token,
915
+ disarm,
916
+ });
917
+ return probe.armed ? probe : null;
918
+ } catch {
919
+ return null;
920
+ }
921
+ }
922
+
923
+ async dispatchClick(point) {
924
+ const press = { button: "left", clickCount: 1 };
925
+ await this.dispatchMouse("mouseMoved", point);
926
+ await this.dispatchMouse("mousePressed", point, { ...press, buttons: 1 });
927
+ await this.dispatchMouse("mouseReleased", point, { ...press, buttons: 0 });
928
+ }
929
+
906
930
  async dispatchMouse(type, point, extra = {}) {
907
931
  await this.send("Input.dispatchMouseEvent", {
908
932
  type,
@@ -919,21 +943,20 @@ export class CdpSession {
919
943
  }
920
944
 
921
945
  async click(selector) {
922
- const target = await this.resolvePointerTarget(selector);
946
+ const token = crypto.randomUUID();
947
+ const target = await this.resolvePointerTarget(selector, {
948
+ inputProbe: token,
949
+ });
923
950
  if (!target.found) {
924
951
  return target;
925
952
  }
926
953
  assertEnabled(target);
927
954
 
928
- const press = { button: "left", clickCount: 1 };
929
- await this.dispatchMouse("mouseMoved", target.point);
930
- await this.dispatchMouse("mousePressed", target.point, {
931
- ...press,
932
- buttons: 1,
933
- });
934
- await this.dispatchMouse("mouseReleased", target.point, {
935
- ...press,
936
- buttons: 0,
955
+ const delivery = await sendCheckedInput({
956
+ send: () => this.dispatchClick(target.point),
957
+ readProbe: (disarm) => this.readInputProbe(token, disarm),
958
+ recover: () => this.bringToFront(),
959
+ describe: `The click on "${selector}"`,
937
960
  });
938
961
 
939
962
  return {
@@ -941,11 +964,18 @@ export class CdpSession {
941
964
  selector,
942
965
  found: true,
943
966
  clicked: true,
967
+ ...(delivery.resent ? { resent: true } : {}),
944
968
  point: target.point,
945
- node: target.node,
969
+ node: delivery.node ?? target.node,
946
970
  };
947
971
  }
948
972
 
973
+ // Bringing the tab to the front makes Chrome render it again, which is
974
+ // the one recovery tried before resending input the page never received.
975
+ async bringToFront() {
976
+ await this.send("Page.bringToFront").catch(() => {});
977
+ }
978
+
949
979
  async hover(selector) {
950
980
  const target = await this.resolvePointerTarget(selector);
951
981
  if (!target.found) {
@@ -965,12 +995,14 @@ export class CdpSession {
965
995
  }
966
996
 
967
997
  async type(selector, text, options = {}) {
998
+ const token = crypto.randomUUID();
968
999
  const prepared = await this.runPageAction(
969
1000
  {
970
1001
  action: "prepare_type",
971
1002
  selector,
972
1003
  text,
973
1004
  clear: options.clear,
1005
+ inputProbe: token,
974
1006
  },
975
1007
  { userGesture: true },
976
1008
  );
@@ -982,32 +1014,51 @@ export class CdpSession {
982
1014
  // see trusted beforeinput/input events and the real value change.
983
1015
  // Newlines become Enter presses, matching the Firefox path: a line break
984
1016
  // in a textarea, implicit submission in a single-line input.
985
- if (text) {
986
- const lines = text.replace(/\r\n?/g, "\n").split("\n");
987
- for (const [index, line] of lines.entries()) {
988
- if (index > 0) {
989
- await this.dispatchKeyEvents(buildCdpKeyEvents("Enter"));
990
- }
991
- if (line) {
992
- await this.send("Input.insertText", { text: line });
1017
+ const sendText = async () => {
1018
+ if (text) {
1019
+ const lines = text.replace(/\r\n?/g, "\n").split("\n");
1020
+ for (const [index, line] of lines.entries()) {
1021
+ if (index > 0) {
1022
+ await this.dispatchKeyEvents(buildCdpKeyEvents("Enter"));
1023
+ }
1024
+ if (line) {
1025
+ await this.send("Input.insertText", { text: line });
1026
+ }
993
1027
  }
1028
+ } else if (options.clear !== false) {
1029
+ await this.dispatchKeyEvents(buildCdpKeyEvents("Delete"));
994
1030
  }
995
- } else if (options.clear !== false) {
996
- await this.dispatchKeyEvents(buildCdpKeyEvents("Delete"));
1031
+ };
1032
+
1033
+ let delivery = { node: null, resent: false };
1034
+ if (text || options.clear !== false) {
1035
+ delivery = await sendCheckedInput({
1036
+ send: sendText,
1037
+ readProbe: (disarm) => this.readInputProbe(token, disarm),
1038
+ recover: () => this.bringToFront(),
1039
+ describe: `The text for "${selector}"`,
1040
+ });
1041
+ } else {
1042
+ await this.readInputProbe(token, true);
997
1043
  }
998
1044
 
999
- const typed = await this.runPageAction({
1000
- action: "inspect",
1001
- selector,
1002
- scrollIntoView: false,
1003
- });
1045
+ let node = delivery.node;
1046
+ if (!node) {
1047
+ const typed = await this.runPageAction({
1048
+ action: "inspect",
1049
+ selector,
1050
+ scrollIntoView: false,
1051
+ });
1052
+ node = typed.found ? typed.node : prepared.node;
1053
+ }
1004
1054
 
1005
1055
  return {
1006
1056
  browserFamily: cdpBrowserFamily(this.config),
1007
1057
  selector,
1008
1058
  found: true,
1009
1059
  typedText: text,
1010
- node: typed.found ? typed.node : prepared.node,
1060
+ ...(delivery.resent ? { resent: true } : {}),
1061
+ node,
1011
1062
  };
1012
1063
  }
1013
1064
 
@@ -1025,10 +1076,12 @@ export class CdpSession {
1025
1076
 
1026
1077
  async pressKey(key, selector = null) {
1027
1078
  const events = buildCdpKeyEvents(key);
1079
+ const token = crypto.randomUUID();
1028
1080
  const focused = await this.runPageAction(
1029
1081
  {
1030
1082
  action: "focus",
1031
1083
  selector,
1084
+ inputProbe: token,
1032
1085
  },
1033
1086
  { userGesture: true },
1034
1087
  );
@@ -1036,12 +1089,18 @@ export class CdpSession {
1036
1089
  return focused;
1037
1090
  }
1038
1091
 
1039
- await this.dispatchKeyEvents(events);
1092
+ const delivery = await sendCheckedInput({
1093
+ send: () => this.dispatchKeyEvents(events),
1094
+ readProbe: (disarm) => this.readInputProbe(token, disarm),
1095
+ recover: () => this.bringToFront(),
1096
+ describe: `The key press "${key}"`,
1097
+ });
1040
1098
 
1041
1099
  return {
1042
1100
  browserFamily: cdpBrowserFamily(this.config),
1043
1101
  key,
1044
1102
  dispatched: true,
1103
+ ...(delivery.resent ? { resent: true } : {}),
1045
1104
  target: focused.target,
1046
1105
  };
1047
1106
  }
@@ -1153,6 +1212,23 @@ export class CdpSession {
1153
1212
  };
1154
1213
  }
1155
1214
 
1215
+ // Counts trusted input from the start of every later document, and from
1216
+ // now on in the current one, so input actions can check that their input
1217
+ // arrived. Without it they are reported as sent, unchecked.
1218
+ async installInputRecorder() {
1219
+ try {
1220
+ await this.send("Page.addScriptToEvaluateOnNewDocument", {
1221
+ source: buildInputRecorderExpression(true),
1222
+ });
1223
+ await this.evaluateRuntime(buildInputRecorderExpression(false), {
1224
+ awaitPromise: false,
1225
+ replMode: false,
1226
+ });
1227
+ } catch {
1228
+ // Ignore recorder failures so attach still succeeds.
1229
+ }
1230
+ }
1231
+
1156
1232
  async seedBufferedState() {
1157
1233
  try {
1158
1234
  const snapshot = await this.runPageAction({
@@ -9,9 +9,11 @@ import { waitForPageCondition } from "./wait-for.mjs";
9
9
  import {
10
10
  assertEnabled,
11
11
  assertPointerTarget,
12
+ buildInputRecorderExpression,
12
13
  buildPageContextExpression,
13
14
  } from "./page-context.mjs";
14
15
  import { buildBidiKeyActions, buildBidiTextActions } from "./keyboard.mjs";
16
+ import { sendCheckedInput } from "./input-delivery.mjs";
15
17
 
16
18
  const POINTER_SOURCE = {
17
19
  type: "pointer",
@@ -826,6 +828,7 @@ export class FirefoxBidiSessionManager {
826
828
 
827
829
  session.subscription = subscription.subscription ?? null;
828
830
  this.sessions.set(session.id, session);
831
+ await this.installInputRecorder(session);
829
832
  await this.seedBufferedState(session);
830
833
  return session.getSummary();
831
834
  }
@@ -838,6 +841,11 @@ export class FirefoxBidiSessionManager {
838
841
  subscriptions: [session.subscription],
839
842
  }).catch(() => {});
840
843
  }
844
+ if (session.inputRecorderScript) {
845
+ await this.send("script.removePreloadScript", {
846
+ script: session.inputRecorderScript,
847
+ }).catch(() => {});
848
+ }
841
849
 
842
850
  session.closed = true;
843
851
  this.sessions.delete(sessionId);
@@ -1053,41 +1061,64 @@ export class FirefoxBidiSessionManager {
1053
1061
  ]);
1054
1062
  }
1055
1063
 
1056
- async resolvePointerTarget(session, selector) {
1064
+ async resolvePointerTarget(session, selector, options = {}) {
1057
1065
  const target = await this.runPageAction(session, {
1058
1066
  action: "pointer_target",
1059
1067
  selector,
1068
+ ...(options.inputProbe ? { inputProbe: options.inputProbe } : {}),
1060
1069
  });
1061
1070
  assertPointerTarget(target);
1062
1071
  return target;
1063
1072
  }
1064
1073
 
1074
+ async readInputProbe(session, token, disarm) {
1075
+ try {
1076
+ const probe = await this.runPageAction(session, {
1077
+ action: "input_probe",
1078
+ token,
1079
+ disarm,
1080
+ });
1081
+ return probe.armed ? probe : null;
1082
+ } catch {
1083
+ return null;
1084
+ }
1085
+ }
1086
+
1065
1087
  async click(sessionId, selector) {
1066
1088
  const session = this.getSession(sessionId);
1067
- const target = await this.resolvePointerTarget(session, selector);
1089
+ const token = crypto.randomUUID();
1090
+ const target = await this.resolvePointerTarget(session, selector, {
1091
+ inputProbe: token,
1092
+ });
1068
1093
  if (!target.found) {
1069
1094
  return target;
1070
1095
  }
1071
1096
  assertEnabled(target);
1072
1097
 
1073
- await this.performActions(session, [
1074
- {
1075
- ...POINTER_SOURCE,
1076
- actions: [
1077
- pointerMove(target.point),
1078
- { type: "pointerDown", button: 0 },
1079
- { type: "pointerUp", button: 0 },
1080
- ],
1081
- },
1082
- ]);
1098
+ const delivery = await sendCheckedInput({
1099
+ send: () =>
1100
+ this.performActions(session, [
1101
+ {
1102
+ ...POINTER_SOURCE,
1103
+ actions: [
1104
+ pointerMove(target.point),
1105
+ { type: "pointerDown", button: 0 },
1106
+ { type: "pointerUp", button: 0 },
1107
+ ],
1108
+ },
1109
+ ]),
1110
+ readProbe: (disarm) => this.readInputProbe(session, token, disarm),
1111
+ describe: `The click on "${selector}"`,
1112
+ });
1083
1113
 
1084
1114
  return {
1085
1115
  browserFamily: "firefox",
1086
1116
  selector,
1087
1117
  found: true,
1088
1118
  clicked: true,
1119
+ ...(delivery.resent ? { resent: true } : {}),
1089
1120
  point: target.point,
1090
- node: target.node,
1121
+ node: delivery.node ?? target.node,
1091
1122
  };
1092
1123
  }
1093
1124
 
@@ -1114,6 +1145,7 @@ export class FirefoxBidiSessionManager {
1114
1145
 
1115
1146
  async type(sessionId, selector, text, options = {}) {
1116
1147
  const session = this.getSession(sessionId);
1148
+ const token = crypto.randomUUID();
1117
1149
  const prepared = await this.runPageAction(
1118
1150
  session,
1119
1151
  {
@@ -1121,6 +1153,7 @@ export class FirefoxBidiSessionManager {
1121
1153
  selector,
1122
1154
  text,
1123
1155
  clear: options.clear,
1156
+ inputProbe: token,
1124
1157
  },
1125
1158
  { userActivation: true },
1126
1159
  );
@@ -1128,24 +1161,37 @@ export class FirefoxBidiSessionManager {
1128
1161
  return prepared;
1129
1162
  }
1130
1163
 
1131
- if (text) {
1132
- await this.performKeyActions(session, buildBidiTextActions(text));
1133
- } else if (options.clear !== false) {
1134
- await this.performKeyActions(session, buildBidiKeyActions("Backspace"));
1164
+ let delivery = { node: null, resent: false };
1165
+ if (text || options.clear !== false) {
1166
+ const actions = text
1167
+ ? buildBidiTextActions(text)
1168
+ : buildBidiKeyActions("Backspace");
1169
+ delivery = await sendCheckedInput({
1170
+ send: () => this.performKeyActions(session, actions),
1171
+ readProbe: (disarm) => this.readInputProbe(session, token, disarm),
1172
+ describe: `The text for "${selector}"`,
1173
+ });
1174
+ } else {
1175
+ await this.readInputProbe(session, token, true);
1135
1176
  }
1136
1177
 
1137
- const typed = await this.runPageAction(session, {
1138
- action: "inspect",
1139
- selector,
1140
- scrollIntoView: false,
1141
- });
1178
+ let node = delivery.node;
1179
+ if (!node) {
1180
+ const typed = await this.runPageAction(session, {
1181
+ action: "inspect",
1182
+ selector,
1183
+ scrollIntoView: false,
1184
+ });
1185
+ node = typed.found ? typed.node : prepared.node;
1186
+ }
1142
1187
 
1143
1188
  return {
1144
1189
  browserFamily: "firefox",
1145
1190
  selector,
1146
1191
  found: true,
1147
1192
  typedText: text,
1148
- node: typed.found ? typed.node : prepared.node,
1193
+ ...(delivery.resent ? { resent: true } : {}),
1194
+ node,
1149
1195
  };
1150
1196
  }
1151
1197
 
@@ -1165,11 +1211,13 @@ export class FirefoxBidiSessionManager {
1165
1211
  async pressKey(sessionId, key, selector = null) {
1166
1212
  const session = this.getSession(sessionId);
1167
1213
  const actions = buildBidiKeyActions(key);
1214
+ const token = crypto.randomUUID();
1168
1215
  const focused = await this.runPageAction(
1169
1216
  session,
1170
1217
  {
1171
1218
  action: "focus",
1172
1219
  selector,
1220
+ inputProbe: token,
1173
1221
  },
1174
1222
  { userActivation: true },
1175
1223
  );
@@ -1177,12 +1225,17 @@ export class FirefoxBidiSessionManager {
1177
1225
  return focused;
1178
1226
  }
1179
1227
 
1180
- await this.performKeyActions(session, actions);
1228
+ const delivery = await sendCheckedInput({
1229
+ send: () => this.performKeyActions(session, actions),
1230
+ readProbe: (disarm) => this.readInputProbe(session, token, disarm),
1231
+ describe: `The key press "${key}"`,
1232
+ });
1181
1233
 
1182
1234
  return {
1183
1235
  browserFamily: "firefox",
1184
1236
  key,
1185
1237
  dispatched: true,
1238
+ ...(delivery.resent ? { resent: true } : {}),
1186
1239
  target: focused.target,
1187
1240
  };
1188
1241
  }
@@ -1388,6 +1441,26 @@ export class FirefoxBidiSessionManager {
1388
1441
  });
1389
1442
  }
1390
1443
 
1444
+ // Counts trusted input from the start of every later document, and from
1445
+ // now on in the current one, so input actions can check that their input
1446
+ // arrived. Without it they are reported as sent, unchecked.
1447
+ async installInputRecorder(session) {
1448
+ try {
1449
+ const preload = await this.send("script.addPreloadScript", {
1450
+ functionDeclaration: `() => ${buildInputRecorderExpression(true)}`,
1451
+ contexts: [session.target.targetId],
1452
+ });
1453
+ session.inputRecorderScript = preload?.script ?? null;
1454
+ await this.evaluateInContext(
1455
+ session,
1456
+ buildInputRecorderExpression(false),
1457
+ { awaitPromise: false },
1458
+ );
1459
+ } catch {
1460
+ // Ignore recorder failures so attach still succeeds.
1461
+ }
1462
+ }
1463
+
1391
1464
  async seedBufferedState(session) {
1392
1465
  try {
1393
1466
  const snapshot = await this.runPageAction(session, {
@@ -0,0 +1,82 @@
1
+ import { setTimeout as sleep } from "node:timers/promises";
2
+
3
+ export const INPUT_NOT_DELIVERED = "INPUT_NOT_DELIVERED";
4
+
5
+ // Input normally reaches the page before the browser acknowledges it, so
6
+ // these re-checks only cover a late delivery.
7
+ const RECHECK_DELAYS_MS = [50, 150];
8
+
9
+ // A browser can acknowledge input it never delivers: Chrome has been seen
10
+ // dropping every CDP input event to a tab after a navigation while still
11
+ // reporting success. So send the input and check with the probe the page
12
+ // script armed that it arrived. If it did not, and the probe can be sure of
13
+ // that, recover and send it once more. Input that still does not arrive is
14
+ // reported as an error rather than a success that did nothing. When the
15
+ // probe cannot be sure, because page listeners might have hidden the input,
16
+ // it is not sent again, so an action is never repeated.
17
+ //
18
+ // readProbe(disarm) returns the probe reading ({ delivered, conclusive,
19
+ // node }), or null when delivery cannot be checked, for example because the
20
+ // page navigated away. The page removes the probe once input arrives;
21
+ // disarm removes it when giving up.
22
+ export async function sendCheckedInput({ send, readProbe, recover, describe }) {
23
+ let settled = false;
24
+ const settle = (reading, resent) => {
25
+ settled = true;
26
+ return { node: reading?.node ?? null, resent };
27
+ };
28
+
29
+ let resent = false;
30
+ try {
31
+ await send();
32
+ let reading = await awaitDelivery(readProbe);
33
+ if (reading.delivered) {
34
+ return settle(reading, false);
35
+ }
36
+
37
+ if (reading.conclusive) {
38
+ await recover?.();
39
+ // The first input may have arrived, or the page navigated, while
40
+ // recovering; sending again then would repeat it or reach another page.
41
+ reading = (await readProbe(false)) ?? { delivered: true };
42
+ if (reading.delivered) {
43
+ return settle(reading, false);
44
+ }
45
+
46
+ await send();
47
+ resent = true;
48
+ reading = await awaitDelivery(readProbe);
49
+ if (reading.delivered) {
50
+ return settle(reading, true);
51
+ }
52
+ }
53
+ } finally {
54
+ if (!settled) {
55
+ await readProbe(true);
56
+ }
57
+ }
58
+
59
+ const error = new Error(
60
+ resent
61
+ ? `${describe} was sent twice, but the browser delivered no input events to the page, so it had no effect. The tab may not be accepting input yet, for example just after a navigation. Wait and try again, or act from the page with evaluate_js (for example element.click()).`
62
+ : `${describe} was sent, but no input events reached the page, so it most likely had no effect. It was not sent again, because a page listener may have hidden it. Check the page; if nothing changed, wait and try again, or act from the page with evaluate_js (for example element.click()).`,
63
+ );
64
+ error.code = INPUT_NOT_DELIVERED;
65
+ throw error;
66
+ }
67
+
68
+ // The reading once the input has arrived or the re-checks are used up. A
69
+ // probe that cannot be read counts as delivered.
70
+ async function awaitDelivery(readProbe) {
71
+ let reading;
72
+ for (const delay of [0, ...RECHECK_DELAYS_MS]) {
73
+ if (delay) {
74
+ await sleep(delay);
75
+ }
76
+ reading = (await readProbe(false)) ?? { delivered: true };
77
+ if (reading.delivered) {
78
+ break;
79
+ }
80
+ }
81
+ return reading;
82
+ }
@@ -332,7 +332,7 @@ export class McpBrowserDevToolsServer {
332
332
  version: SERVER_VERSION,
333
333
  },
334
334
  instructions:
335
- 'Use the browser tools to inspect tabs, console output, network activity, DOM structure, element state, screenshots, and page interactions across Chromium CDP or Firefox BiDi. To act on a page and check the result, prefer run_steps: send the actions you already know (such as every field of a form), a wait_for, and the check (take_screenshot with output image, or inspect_element) in one call instead of several round trips, for example {"sessionId":"<id>","steps":[{"tool":"type","arguments":{"selector":"#search","text":"headphones"}},{"tool":"press_key","arguments":{"key":"Enter"}},{"tool":"wait_for","arguments":{"selector":"#results"}},{"tool":"take_screenshot","arguments":{"output":"image"}}]}. Add an if step when the page can be in more than one state.',
335
+ 'Use the browser tools to inspect tabs, console output, network activity, DOM structure, element state, screenshots, and page interactions across Chromium CDP or Firefox BiDi. To act on a page and check the result, prefer run_steps: send the actions you already know (such as every field of a form), a wait_for, and the check (take_screenshot with output image, or inspect_element) in one call instead of several round trips, for example {"sessionId":"<id>","steps":[{"tool":"type","arguments":{"selector":"#search","text":"headphones"}},{"tool":"press_key","arguments":{"key":"Enter"}},{"tool":"wait_for","arguments":{"selector":"#results"}},{"tool":"take_screenshot","arguments":{"output":"image"}}]}. Add an if step when the page can be in more than one state. To read several pages, open them together with run_tabs and read each with read_text. Locators: plain CSS (or css=) takes the first match; text=Foo takes the first visible element whose text equals Foo, else contains it, in document order, so it can match a wrapper; role=button[name="Save"] matches ARIA role and accessible name (equal or containing) without a visibility check; name=Foo takes the first visible element whose accessible name equals or contains Foo, and a matched <label> resolves to its control when that control is visible. Comparisons are case-sensitive; iframes and shadow roots are not searched.',
336
336
  });
337
337
  case "notifications/initialized":
338
338
  return null;
@@ -1,7 +1,15 @@
1
- import { pageScript } from "./page-script.mjs";
1
+ import { inputRecorder, pageScript } from "./page-script.mjs";
2
2
 
3
3
  const PAGE_SCRIPT_SOURCE = pageScript.toString();
4
4
 
5
+ // The input recorder as a function declaration, to run with early = true
6
+ // when each new document starts or false on the current document.
7
+ export const INPUT_RECORDER_FUNCTION = inputRecorder.toString();
8
+
9
+ export function buildInputRecorderExpression(early) {
10
+ return `(${INPUT_RECORDER_FUNCTION})(${early})`;
11
+ }
12
+
5
13
  // Builds an expression that runs pageScript in the page with this payload.
6
14
  // With serialize, the expression evaluates to the result as a JSON string.
7
15
  export function buildPageContextExpression(
@@ -892,6 +892,86 @@ export function pageScript(payload) {
892
892
  return Boolean(label && label.control === element);
893
893
  }
894
894
 
895
+ // Tells input the browser silently dropped apart from input the page
896
+ // received, from the trusted events inputRecorder counted between arming
897
+ // the probe and reading it. A recorder installed when the document started
898
+ // runs before every page listener, so no count means nothing arrived. One
899
+ // installed later can miss events that earlier page listeners stopped, so
900
+ // there a click also counts as delivered when the element under the pointer
901
+ // becomes hovered, and typing when the field's content changes: the
902
+ // browser does both before any page listener runs.
903
+ const INPUT_PROBE_KEY = Symbol.for("mcp-browser-dev-tools.inputProbe");
904
+ const INPUT_RECORDER_KEY = Symbol.for("mcp-browser-dev-tools.inputRecorder");
905
+
906
+ // Input aimed at a frame goes to the frame's own document, whose events
907
+ // this window does not see.
908
+ function hostsDocument(element) {
909
+ return ["IFRAME", "FRAME", "OBJECT", "EMBED"].includes(element?.tagName);
910
+ }
911
+
912
+ function isHovered(element) {
913
+ try {
914
+ return element.matches(":hover");
915
+ } catch {
916
+ return false;
917
+ }
918
+ }
919
+
920
+ function editedContent(element) {
921
+ if (!element) {
922
+ return null;
923
+ }
924
+ return typeof element.value === "string"
925
+ ? element.value
926
+ : element.textContent;
927
+ }
928
+
929
+ function armInputProbe(token, kind, options = {}) {
930
+ const recorder = window[INPUT_RECORDER_KEY];
931
+ if (!recorder) {
932
+ delete window[INPUT_PROBE_KEY];
933
+ return;
934
+ }
935
+ const hovered = options.pointerAt ?? null;
936
+ window[INPUT_PROBE_KEY] = {
937
+ token,
938
+ kind,
939
+ count: recorder[kind],
940
+ early: recorder.early,
941
+ element: options.element ?? null,
942
+ locator: options.locator ?? null,
943
+ hovered: hovered && !isHovered(hovered) ? hovered : null,
944
+ edited: options.edited ?? null,
945
+ content: editedContent(options.edited),
946
+ };
947
+ }
948
+
949
+ // Unarmed means delivery cannot be checked, for example after the page
950
+ // navigated. conclusive says whether "not delivered" can be trusted.
951
+ function readInputProbe(token, disarm) {
952
+ const probe = window[INPUT_PROBE_KEY];
953
+ const recorder = window[INPUT_RECORDER_KEY];
954
+ if (!probe || probe.token !== token || !recorder) {
955
+ return { armed: false, delivered: false, conclusive: false };
956
+ }
957
+ const delivered =
958
+ recorder[probe.kind] > probe.count ||
959
+ Boolean(probe.hovered && isHovered(probe.hovered)) ||
960
+ (probe.edited !== null && editedContent(probe.edited) !== probe.content);
961
+ if (disarm || delivered) {
962
+ delete window[INPUT_PROBE_KEY];
963
+ }
964
+ return {
965
+ armed: true,
966
+ delivered,
967
+ conclusive: probe.early,
968
+ node:
969
+ delivered && probe.element?.isConnected
970
+ ? describeElement(probe.element, probe.locator)
971
+ : null,
972
+ };
973
+ }
974
+
895
975
  // Whether the page renders the element at all. innerText falls back to the
896
976
  // raw text content for an element inside display: none, which the page
897
977
  // does not show; unlike isVisible, size and pointer events do not matter.
@@ -1046,6 +1126,18 @@ export function pageScript(payload) {
1046
1126
  const receivesEvents = Boolean(
1047
1127
  hit && receivesPointerAt(resolved.element, hit),
1048
1128
  );
1129
+ if (
1130
+ receivesEvents &&
1131
+ typeof payload.inputProbe === "string" &&
1132
+ !hostsDocument(hit) &&
1133
+ !isDisabled(resolved.element)
1134
+ ) {
1135
+ armInputProbe(payload.inputProbe, "pointer", {
1136
+ element: resolved.element,
1137
+ locator: resolved,
1138
+ pointerAt: hit,
1139
+ });
1140
+ }
1049
1141
 
1050
1142
  return {
1051
1143
  browserFamily: payload.browserFamily,
@@ -1057,6 +1149,8 @@ export function pageScript(payload) {
1057
1149
  node: describeElement(resolved.element, resolved),
1058
1150
  };
1059
1151
  }
1152
+ case "input_probe":
1153
+ return readInputProbe(payload.token, payload.disarm === true);
1060
1154
  case "prepare_type": {
1061
1155
  const resolved = ensureResolved(payload.selector);
1062
1156
  if (!resolved.element) {
@@ -1122,6 +1216,14 @@ export function pageScript(payload) {
1122
1216
  selection.addRange(range);
1123
1217
  }
1124
1218
 
1219
+ if (typeof payload.inputProbe === "string") {
1220
+ armInputProbe(payload.inputProbe, "keyboard", {
1221
+ element,
1222
+ locator: resolved,
1223
+ edited: element,
1224
+ });
1225
+ }
1226
+
1125
1227
  return {
1126
1228
  browserFamily: payload.browserFamily,
1127
1229
  selector: payload.selector,
@@ -1181,11 +1283,18 @@ export function pageScript(payload) {
1181
1283
  }
1182
1284
  }
1183
1285
 
1286
+ const focused = getDeepActiveElement() ?? document.body;
1287
+ if (typeof payload.inputProbe === "string" && !hostsDocument(focused)) {
1288
+ armInputProbe(payload.inputProbe, "keyboard", {
1289
+ edited: isEditable(focused) ? focused : null,
1290
+ });
1291
+ }
1292
+
1184
1293
  return {
1185
1294
  browserFamily: payload.browserFamily,
1186
1295
  selector: payload.selector ?? null,
1187
1296
  found: true,
1188
- target: summarizeTarget(getDeepActiveElement() ?? document.body),
1297
+ target: summarizeTarget(focused),
1189
1298
  };
1190
1299
  }
1191
1300
  case "scroll": {
@@ -1370,3 +1479,35 @@ export function pageScript(payload) {
1370
1479
 
1371
1480
  return runAction();
1372
1481
  }
1482
+
1483
+ // Counts trusted pointer and keyboard events in the page from the moment it
1484
+ // runs, for the input probe in pageScript. Registered to run when each new
1485
+ // document starts (early), it sees every event before page listeners can
1486
+ // stop it; run on a document that is already loaded, it misses what
1487
+ // listeners added before it stop. Like pageScript, it is serialized with
1488
+ // toString() and must not reference anything outside itself.
1489
+ export function inputRecorder(early) {
1490
+ const key = Symbol.for("mcp-browser-dev-tools.inputRecorder");
1491
+ if (window[key]) {
1492
+ return;
1493
+ }
1494
+ const counts = { pointer: 0, keyboard: 0, early };
1495
+ const kinds = {
1496
+ pointer: ["pointerdown", "mousedown", "pointerup", "mouseup", "click"],
1497
+ keyboard: ["keydown", "keyup", "beforeinput", "input"],
1498
+ };
1499
+ for (const [kind, types] of Object.entries(kinds)) {
1500
+ for (const type of types) {
1501
+ window.addEventListener(
1502
+ type,
1503
+ (event) => {
1504
+ if (event.isTrusted) {
1505
+ counts[kind] += 1;
1506
+ }
1507
+ },
1508
+ true,
1509
+ );
1510
+ }
1511
+ }
1512
+ Object.defineProperty(window, key, { value: counts });
1513
+ }
package/src/run-steps.mjs CHANGED
@@ -106,7 +106,7 @@ export function stepSchema(stepTools) {
106
106
  arguments: {
107
107
  type: "object",
108
108
  description:
109
- "That tool's arguments without sessionId (default {}). sleep takes { ms }. if takes { condition, then, elseIf, else }: each condition has the wait_for condition fields, checked once without waiting, all of which must hold; then and else are step lists; elseIf is a list of { condition, then } checked in order after condition, and the first condition that holds runs its then. repeat takes { steps, until, max }: runs steps, then checks the until condition once, and runs them again until it holds, at most max passes.",
109
+ "The tool's arguments without sessionId (default {}). sleep takes { ms }; if takes { condition, then, elseIf, else }; repeat takes { steps, until, max }.",
110
110
  },
111
111
  },
112
112
  required: ["tool"],
@@ -500,7 +500,7 @@ export function runStepsTool(runner, stepTools) {
500
500
  definition: {
501
501
  name: "run_steps",
502
502
  description:
503
- 'Run several tools on one attached session in order, in a single call. Use it to act and check the result together, for example [{"tool":"click","arguments":{"selector":"text=Save"}},{"tool":"sleep","arguments":{"ms":300}},{"tool":"take_screenshot"}]. Each step names a tool that takes sessionId (or sleep) and gives that tool\'s arguments without sessionId. To branch on the page state, use an if step, for example {"tool":"if","arguments":{"condition":{"selector":"#status","textIncludes":"failed"},"then":[{"tool":"click","arguments":{"selector":"text=Retry"}}],"elseIf":[{"condition":{"urlIncludes":"/login"},"then":[{"tool":"take_screenshot","arguments":{"output":"image"}}]}],"else":[]}}; conditions are checked once, in order, without waiting, so put wait_for or sleep before the if when the page may still be changing. The if result reports the branch taken (then, elseIf[i], or else), each checked condition with what was observed, and the branch\'s step results. Conditions and wait_for also take anyOf, a list of conditions of which any one must hold, to end on the first of several outcomes. To retry or poll, use a repeat step, for example {"tool":"repeat","arguments":{"max":5,"steps":[{"tool":"click","arguments":{"selector":"text=Load more"}},{"tool":"wait_for","arguments":{"selector":"#list","textExcludes":"Loading"}}],"until":{"selector":"text=Order #1042","state":"present"}}}; it runs its steps, checks until once without waiting, and runs them again until it holds, at most max passes (default 5, at most 10); it fails if until never holds or one of its steps fails, which ends the loop even with continueOnError, and its result lists each pass. Every step, including branches and repeat bodies, is validated before any runs. A step fails when its tool throws or reports found: false (except inspect_element). Stops at the first failing step unless continueOnError is true, and returns each step\'s result or error. When a step fails, the result also has page: the URL, title, and visible controls with a locator for each, to fix the batch without looking again. Screenshots come back as image content; the step result keeps the metadata plus image, the 1-based position of its image. Prefer wait_for over sleep when there is a condition to wait for.',
503
+ 'Run tools on one attached session in order, in a single call, to act and check the result together: [{"tool":"click","arguments":{"selector":"text=Save"}},{"tool":"wait_for","arguments":{"selector":"#status","textIncludes":"Saved"}},{"tool":"take_screenshot"}]. Each step names a tool that takes sessionId (or sleep) with that tool\'s arguments minus sessionId. if branches once, without waiting, on conditions with the wait_for fields: {"tool":"if","arguments":{"condition":{"selector":"text=Accept cookies"},"then":[...],"elseIf":[{"condition":{...},"then":[...]}],"else":[...]}}; the result reports the branch taken and what each condition observed. repeat retries or polls: {"tool":"repeat","arguments":{"steps":[...],"until":{"selector":"#list","textIncludes":"Order #1042"},"max":5}} runs its steps, then checks until once, at most max passes (default 5, at most 10); it fails if until never holds, and a failing step ends the loop. All steps are validated before any runs. A step fails when its tool throws or reports found: false (except inspect_element); the batch stops there unless continueOnError, and the result then includes page, the visible controls with a locator for each. Screenshots come back as image content; each step result keeps image, its 1-based position. Prefer wait_for over sleep.',
504
504
  inputSchema: runStepsInputSchema(stepTools),
505
505
  },
506
506
  handler: async (args) => runner.runSteps(args),
package/src/run-tabs.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { MAX_RUN_STEPS, stepSchema } from "./run-steps.mjs";
2
2
  import { asImageToolResult } from "./tool-results.mjs";
3
- import { waitUntilProperty } from "./tool-schemas.mjs";
3
+ import { waitUntilProperty, withoutDescriptions } from "./tool-schemas.mjs";
4
4
 
5
5
  export const MAX_TABS = 8;
6
6
  export const DEFAULT_TAB_TIMEOUT_MS = 60_000;
@@ -14,7 +14,7 @@ export function runTabsInputSchema(stepTools, browserFamily) {
14
14
  type: "array",
15
15
  minItems: 1,
16
16
  maxItems: MAX_TABS,
17
- description: `Tabs to run at the same time (at most ${MAX_TABS}). Each gives either url, to open a new tab there, or sessionId, to use an attached tab, plus the steps to run in it.`,
17
+ description: `At most ${MAX_TABS}, each with url (opens a new tab there) or sessionId (an attached tab), plus its steps.`,
18
18
  items: {
19
19
  type: "object",
20
20
  properties: {
@@ -33,7 +33,7 @@ export function runTabsInputSchema(stepTools, browserFamily) {
33
33
  type: "array",
34
34
  maxItems: MAX_RUN_STEPS,
35
35
  description: `Steps to run in this tab, as in run_steps (at most ${MAX_RUN_STEPS}, default none).`,
36
- items: stepSchema(stepTools),
36
+ items: withoutDescriptions(stepSchema(stepTools)),
37
37
  },
38
38
  },
39
39
  additionalProperties: false,
@@ -281,7 +281,7 @@ export function runTabsTool(runner, stepTools, configuredFamily) {
281
281
  {
282
282
  definition: {
283
283
  name: "run_tabs",
284
- description: `Run step lists in several tabs at the same time, in one call, and return every tab's results together. Use it to read or check several pages at once, for example to open search results side by side: {"tabs":[{"url":"https://example.com/a","steps":[{"tool":"read_text","arguments":{"maxChars":4000}}]},{"url":"https://example.com/b","steps":[{"tool":"read_text","arguments":{"maxChars":4000}}]}]}. A tab with url opens a new tab, loads the URL (waitUntil, default complete), and runs its steps; a tab with sessionId runs its steps in that attached tab. Steps are the same as in run_steps (including if and repeat) and are all validated before any tab opens. All tabs run at once by default (at most ${MAX_TABS}; concurrency lowers that); each has timeoutMs (default ${DEFAULT_TAB_TIMEOUT_MS}) and fails on its own without stopping the others, with page controls reported as in run_steps. Tabs opened for a url are closed afterwards unless keepTabs is true.`,
284
+ description: `Run step lists in several tabs at the same time and return every tab's results in one reply, for example to read search results side by side: {"tabs":[{"url":"https://example.com/a","steps":[{"tool":"read_text"}]},{"url":"https://example.com/b","steps":[{"tool":"read_text"}]}]}. A url tab opens a new tab, loads it, runs its steps, and closes unless keepTabs; a sessionId tab uses that attached tab. Steps are as in run_steps and are all validated first. Tabs run at once (at most ${MAX_TABS}; concurrency lowers that); each has timeoutMs (default ${DEFAULT_TAB_TIMEOUT_MS}) and fails without stopping the others.`,
285
285
  inputSchema: runTabsInputSchema(stepTools, configuredFamily),
286
286
  },
287
287
  handler: async (args) => runner.runTabs(args, configuredFamily),
@@ -32,7 +32,25 @@ export function sessionWithLimitSchema(description) {
32
32
  }
33
33
 
34
34
  export const LOCATOR_DESCRIPTION =
35
- 'Element locator. Plain CSS (or css=...) resolves to the first document.querySelector match. text=Foo resolves to the first visible element whose whitespace-normalized text equals Foo, falling back to the first whose text contains Foo; elements are scanned in document order, so this can resolve to a wrapper around the element you want. role=button or role=button[name="Save"] matches by explicit or implicit ARIA role and, optionally, accessible name (equal or containing), without a visibility check. name=Foo resolves to the first visible element whose accessible name (aria-label, aria-labelledby, associated label, alt, and so on) equals or contains Foo. Text comparisons are case-sensitive. Only the top-level document is searched: elements inside iframes or shadow roots are not found.';
35
+ 'Locator: CSS, text=Visible text, role=button[name="Save"], or name=Accessible name.';
36
+
37
+ // A copy of schema without descriptions, for a schema repeated inside another
38
+ // whose fields are already described once; validation is unchanged.
39
+ export function withoutDescriptions(schema) {
40
+ if (Array.isArray(schema)) {
41
+ return schema.map(withoutDescriptions);
42
+ }
43
+ if (!schema || typeof schema !== "object") {
44
+ return schema;
45
+ }
46
+ return Object.fromEntries(
47
+ Object.entries(schema)
48
+ .filter(
49
+ ([key, value]) => key !== "description" || typeof value !== "string",
50
+ )
51
+ .map(([key, value]) => [key, withoutDescriptions(value)]),
52
+ );
53
+ }
36
54
 
37
55
  export function selectorProperty() {
38
56
  return {
@@ -93,24 +111,24 @@ export function pageConditionProperties({ expression = false } = {}) {
93
111
  textEquals: {
94
112
  type: "string",
95
113
  description:
96
- "The selector's full visible text equals this string, comparing with whitespace collapsed. Requires selector; not with state hidden.",
114
+ "The selector's full visible text equals this, with whitespace collapsed. Requires selector; not with state hidden.",
97
115
  },
98
116
  textIncludes: {
99
117
  type: "string",
100
118
  description:
101
- "The selector's full visible text contains this string, comparing with whitespace collapsed. Requires selector; not with state hidden.",
119
+ "The selector's full visible text contains this, with whitespace collapsed. Requires selector; not with state hidden.",
102
120
  },
103
121
  textExcludes: {
104
122
  type: "string",
105
123
  description:
106
- "The selector's visible text does not contain this string, for example to wait until a status no longer says Processing. Never holds for a missing element. Requires selector; not with state hidden.",
124
+ "The selector's visible text no longer contains this, for example Processing; never holds for a missing element. Requires selector; not with state hidden.",
107
125
  },
108
126
  ...(expression
109
127
  ? {
110
128
  expression: {
111
129
  type: "string",
112
130
  description:
113
- "JavaScript expression evaluated in the page's main world; holds when its result, awaited if it is a promise, is truthy, for example document.querySelectorAll('.row').length >= 5. An expression that throws fails the check. Each evaluation must settle within the wait's remaining time, or 5000ms in if and repeat.",
131
+ "JavaScript in the page's main world; holds when its result (awaited if a promise) is truthy, for example document.querySelectorAll('.row').length >= 5. Throwing fails the check; each evaluation must settle within the remaining wait (5000ms in if and repeat).",
114
132
  },
115
133
  }
116
134
  : {}),
@@ -134,11 +152,11 @@ export function anyOfProperty(options) {
134
152
  minItems: 1,
135
153
  items: {
136
154
  type: "object",
137
- properties: pageConditionProperties(options),
155
+ properties: withoutDescriptions(pageConditionProperties(options)),
138
156
  additionalProperties: false,
139
157
  },
140
158
  description:
141
- "Alternative conditions, each with the fields above; holds when any one holds, checked in order. Use instead of the fields above, for example to wait until a status says either Paid or Declined. The result reports matchedIndex.",
159
+ "Alternative conditions with the fields above, instead of them; holds when any one holds, checked in order, for example a status of either Paid or Declined. The result reports matchedIndex.",
142
160
  };
143
161
  }
144
162
 
@@ -338,7 +356,7 @@ export function launchBrowserInputSchema(
338
356
  userDataDir: {
339
357
  type: "string",
340
358
  description:
341
- "Browser profile directory for a new launch (default: MCP_BROWSER_USER_DATA_DIR when set). Without either, Chromium and Edge get a fresh temporary profile if that browser is already running, and the default profile otherwise.",
359
+ "Profile directory for a new launch (default: MCP_BROWSER_USER_DATA_DIR). Without either, Chromium and Edge use a temporary profile if already running, else the default one.",
342
360
  },
343
361
  waitMs: {
344
362
  type: "integer",
@@ -404,7 +422,7 @@ export function ensureBrowserInputSchema(
404
422
  userDataDir: {
405
423
  type: "string",
406
424
  description:
407
- "Browser profile directory for a new launch (default: MCP_BROWSER_USER_DATA_DIR when set). Without either, Chromium and Edge get a fresh temporary profile if that browser is already running, and the default profile otherwise.",
425
+ "Profile directory for a new launch (default: MCP_BROWSER_USER_DATA_DIR). Without either, Chromium and Edge use a temporary profile if already running, else the default one.",
408
426
  },
409
427
  waitMs: {
410
428
  type: "integer",
@@ -65,7 +65,7 @@ export function actionTools(server) {
65
65
  definition: {
66
66
  name: "click",
67
67
  description:
68
- "Click a single element located by CSS, text=..., role=..., or name=... syntax. Sends real mouse input at the element center and fails if another element covers that point. A JavaScript alert or confirm dialog that this opens is accepted automatically and a prompt is dismissed; get_events reports it as a dialog event. To check the result in the same call, run it as a run_steps step followed by wait_for, inspect_element, or take_screenshot.",
68
+ "Click an element with real mouse input at its center; fails if another element covers that point. Accepts an alert or confirm dialog it opens and dismisses a prompt (get_events reports it). Check the result in the same call with run_steps.",
69
69
  inputSchema: sessionSchema(
70
70
  {
71
71
  selector: selectorProperty(),
@@ -113,19 +113,19 @@ export function actionTools(server) {
113
113
  definition: {
114
114
  name: "type",
115
115
  description:
116
- "Type text into an input, textarea, or contenteditable element using real text input, replacing existing content unless clear is false. To check the result in the same call, run it as a run_steps step followed by wait_for, inspect_element, or take_screenshot.",
116
+ "Type into an input, textarea, or contenteditable with real text input, replacing its content unless clear is false. Check the result in the same call with run_steps.",
117
117
  inputSchema: sessionSchema(
118
118
  {
119
119
  selector: selectorProperty(),
120
120
  text: {
121
121
  type: "string",
122
122
  description:
123
- "Text to enter. Each newline is sent as an Enter key press: a line break in a textarea, implicit form submission in a single-line input. Date, time, datetime-local, month, week, color, and range inputs get the value set directly, so pass it in that input's value format (for example 2026-09-27). An empty string with clear empties the field.",
123
+ "Text to enter; each newline is an Enter press (a line break in a textarea, form submission in a single-line input). Date, time, datetime-local, month, week, color, and range inputs get the value set directly, in their value format (for example 2026-09-27). An empty string with clear empties the field.",
124
124
  },
125
125
  clear: {
126
126
  type: "boolean",
127
127
  description:
128
- "Replace the existing content (default true). When false, the text is inserted at the end of the current content. Ignored for date, time, datetime-local, month, week, color, and range inputs, whose value is always replaced.",
128
+ "Replace the existing content (default true); false inserts at the end. The picker inputs listed under text are always replaced.",
129
129
  },
130
130
  timeoutMs: actionTimeoutProperty(""),
131
131
  },
@@ -151,7 +151,7 @@ export function actionTools(server) {
151
151
  definition: {
152
152
  name: "select",
153
153
  description:
154
- "Select an option in a native <select> element and fire input and change events. Provide value, label, or both; the first option matching either is selected, and the call fails if none matches. Custom dropdowns built from other elements need click instead. To check the result in the same call, run it as a run_steps step followed by wait_for, inspect_element, or take_screenshot.",
154
+ "Select an option in a native <select> by value or label (the first option matching either) and fire input and change events; fails if none matches. Use click for custom dropdowns. Check the result in the same call with run_steps.",
155
155
  inputSchema: sessionSchema(
156
156
  {
157
157
  selector: selectorProperty(),
@@ -192,7 +192,7 @@ export function actionTools(server) {
192
192
  definition: {
193
193
  name: "press_key",
194
194
  description:
195
- "Press a key or key combination (for example Enter, Tab, Escape, ArrowDown, Shift+Tab, Meta+a) with real keyboard input on the focused element, or on selector after focusing it. Fails if selector cannot take focus. A JavaScript alert or confirm dialog that this opens is accepted automatically and a prompt is dismissed; get_events reports it as a dialog event. To check the result in the same call, run it as a run_steps step followed by wait_for, inspect_element, or take_screenshot.",
195
+ "Press a key or combination with real keyboard input on the focused element, or on selector after focusing it (fails if it cannot take focus). Accepts an alert or confirm dialog it opens and dismisses a prompt (get_events reports it). Check the result in the same call with run_steps.",
196
196
  inputSchema: sessionSchema(
197
197
  {
198
198
  key: {
@@ -51,7 +51,7 @@ export function browserTools(server) {
51
51
  definition: {
52
52
  name: "launch_browser",
53
53
  description:
54
- "Launch a local debug-enabled browser process that matches the current broker configuration and return launch details plus an optional doctor report. When port, address, userDataDir, and unsafeArgs are all omitted and a browser of this family is already reachable, returns it with reused: true instead of launching, opening url in a new tab if given. On macOS and Linux it never starts a second browser on a profile that is already open. Prefer ensure_browser.",
54
+ "Launch a local debug-enabled browser for this server's configuration and return launch details and an optional doctor report. When port, address, userDataDir, and unsafeArgs are omitted and a browser of this family is reachable, returns it with reused: true, opening url in a new tab if given. On macOS and Linux it never opens a second browser on a profile already in use. Prefer ensure_browser.",
55
55
  inputSchema: launchBrowserInputSchema(
56
56
  server.config.browserFamily,
57
57
  server.config.enableUnsafeLaunchArgs,
@@ -110,7 +110,7 @@ export function browserTools(server) {
110
110
  definition: {
111
111
  name: "ensure_browser",
112
112
  description:
113
- "Ensure a compatible browser is reachable through the current broker, reusing a running one when possible. If none answers after three status checks, launch one locally, using the MCP_BROWSER_USER_DATA_DIR profile when set, and optionally open a tab for the requested URL. Will not launch again for 30 seconds while a browser it launched is still starting, and on macOS and Linux never starts a second browser on a profile that is already open.",
113
+ "Reuse a reachable browser or launch one (with the MCP_BROWSER_USER_DATA_DIR profile when set), optionally opening url in a new tab. Checks three times before launching, does not launch again for 30 seconds while a browser it launched is starting, and on macOS and Linux never opens a second browser on a profile already in use.",
114
114
  inputSchema: ensureBrowserInputSchema(
115
115
  server.config.browserFamily,
116
116
  server.config.enableUnsafeLaunchArgs,
@@ -88,7 +88,7 @@ export function inspectionTools(server) {
88
88
  definition: {
89
89
  name: "inspect_element",
90
90
  description:
91
- "Inspect a single DOM element located by CSS, text=..., role=..., or name=... syntax and return normalized element details. Scrolls the element into view first, so the returned box reflects the scrolled position.",
91
+ "Describe one element: its box, visibility, role, accessible name, state, and styles. Scrolls it into view first, so the box reflects the scrolled position.",
92
92
  inputSchema: {
93
93
  type: "object",
94
94
  properties: {
@@ -111,7 +111,7 @@ export function inspectionTools(server) {
111
111
  {
112
112
  definition: {
113
113
  name: "read_text",
114
- description: `Read the visible text of the page's main content (main or role=main, else a single article, else the body), or of one element with selector, as plain lines up to maxChars. With links, also list the links in it with their text and absolute URL, for example to collect search results. Use it to read articles and results pages; inspect_element clips text to 400 characters.`,
114
+ description: `Read the visible text of the main content (main or role=main, else a single article, else the body), or of selector, as plain lines up to maxChars. With links, also list its links with text and absolute URL, for example search results. inspect_element clips text to 400 characters.`,
115
115
  inputSchema: {
116
116
  type: "object",
117
117
  properties: {
@@ -156,7 +156,7 @@ export function inspectionTools(server) {
156
156
  definition: {
157
157
  name: "take_screenshot",
158
158
  description:
159
- "Capture a screenshot from an attached page or a single element when selector is provided. By default the image comes back as base64 data in the JSON result; output image returns it as image content instead, and output file (or path) writes it to a file and returns the path.",
159
+ "Screenshot the page, or one element with selector. Returns base64 data in the JSON by default; output image returns image content instead, and output file (or path) writes a file and returns its path.",
160
160
  inputSchema: {
161
161
  type: "object",
162
162
  properties: {
@@ -175,11 +175,11 @@ export function inspectionTools(server) {
175
175
  type: "string",
176
176
  enum: ["data", "image", "file"],
177
177
  description:
178
- "How to return the image: data puts base64 data in the JSON result, image returns an image content block with only metadata in the JSON, file writes the decoded image to a file and returns its path (default data, or file when path is given).",
178
+ "data (default) puts base64 in the JSON, image returns image content with metadata in the JSON, file writes a file and returns its path (the default when path is given).",
179
179
  },
180
180
  path: {
181
181
  type: "string",
182
- description: `Absolute file path for output file, ending in ${screenshotFileExtensions(server.config.browserFamily).join(", ")}; the extension sets the format. Missing parent directories are created. Default: a new file in a private directory under the system temp directory.`,
182
+ description: `Absolute path for output file, ending in ${screenshotFileExtensions(server.config.browserFamily).join(", ")} (the extension sets the format); parent directories are created. Default: a new file in a private temp directory.`,
183
183
  },
184
184
  overwrite: {
185
185
  type: "boolean",
@@ -267,7 +267,7 @@ export function inspectionTools(server) {
267
267
  returnByValue: {
268
268
  type: "boolean",
269
269
  description:
270
- "Return the result as a JSON value (default true). When false, only a short description of the resulting object is returned. Chromium and Edge only; Firefox always returns a serialized value.",
270
+ "Return a JSON value (default true); false returns a short description of the object. Chromium and Edge only; Firefox always returns a serialized value.",
271
271
  },
272
272
  },
273
273
  required: ["sessionId", "expression"],
@@ -190,8 +190,8 @@ export function stateTools(server) {
190
190
  definition: {
191
191
  name: "wait_for",
192
192
  description: server.config.enableEvaluate
193
- ? "Wait until every given condition holds on an attached session: selector state, selector text (textEquals, textIncludes, textExcludes), exact url, urlIncludes substring, readyState, and a JavaScript expression. Give at least one of selector, url, urlIncludes, readyState, or expression, or give anyOf to wait until any one of several conditions holds. Polls until the conditions match or timeoutMs passes, then fails with the last observed state. A selector check scrolls the matched element into view on each poll."
194
- : "Wait until every given condition holds on an attached session: selector state, selector text (textEquals, textIncludes, textExcludes), exact url, urlIncludes substring, and readyState. Give at least one of selector, url, urlIncludes, or readyState, or give anyOf to wait until any one of several conditions holds. Polls until the conditions match or timeoutMs passes, then fails with the last observed state. A selector check scrolls the matched element into view on each poll.",
193
+ ? "Wait until every given condition holds: selector state, its text (textEquals, textIncludes, textExcludes), url, urlIncludes, readyState, or expression; or give anyOf to end on the first of several. Polls until they hold or timeoutMs passes, then fails with the last observed state. Selector checks scroll the element into view."
194
+ : "Wait until every given condition holds: selector state, its text (textEquals, textIncludes, textExcludes), url, urlIncludes, or readyState; or give anyOf to end on the first of several. Polls until they hold or timeoutMs passes, then fails with the last observed state. Selector checks scroll the element into view.",
195
195
  inputSchema: waitForInputSchema({
196
196
  expression: server.config.enableEvaluate,
197
197
  }),