mcp-browser-dev-tools 0.4.1 → 0.5.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 +4 -4
- package/package.json +2 -1
- package/src/action-changes.mjs +47 -9
- package/src/app.mjs +35 -3
- package/src/browser-adapter.mjs +8 -0
- package/src/browser-launch-service.mjs +55 -7
- package/src/cdp-client.mjs +76 -16
- package/src/dialog-answers.mjs +91 -0
- package/src/firefox-bidi-client.mjs +128 -27
- package/src/json-rpc-stdio.mjs +19 -2
- package/src/mcp-server.mjs +20 -3
- package/src/page-context.mjs +57 -2
- package/src/page-script.mjs +359 -73
- package/src/run-steps.mjs +299 -20
- package/src/run-tabs.mjs +31 -18
- package/src/tool-results.mjs +96 -0
- package/src/tool-schemas.mjs +1 -1
- package/src/tool-sets.mjs +3 -2
- package/src/tools/action-tools.mjs +36 -0
- package/src/tools/browser-tools.mjs +8 -3
- package/src/tools/inspection-tools.mjs +74 -0
|
@@ -49,8 +49,13 @@ export function browserTools(server) {
|
|
|
49
49
|
{
|
|
50
50
|
definition: {
|
|
51
51
|
name: "launch_browser",
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
// unsafeArgs is only in the schema when enabled, so only name it
|
|
53
|
+
// then.
|
|
54
|
+
description: `Launch a debug-enabled browser, or reuse a reachable one unless ${
|
|
55
|
+
server.config.enableUnsafeLaunchArgs
|
|
56
|
+
? "port, address, userDataDir, or unsafeArgs"
|
|
57
|
+
: "port, address, or userDataDir"
|
|
58
|
+
} is given; never a second browser on a profile in use (except from WSL). Prefer ensure_browser.`,
|
|
54
59
|
inputSchema: launchBrowserInputSchema(
|
|
55
60
|
server.config.browserFamily,
|
|
56
61
|
server.config.enableUnsafeLaunchArgs,
|
|
@@ -109,7 +114,7 @@ export function browserTools(server) {
|
|
|
109
114
|
definition: {
|
|
110
115
|
name: "ensure_browser",
|
|
111
116
|
description:
|
|
112
|
-
"Reuse a reachable browser or launch one (with the MCP_BROWSER_USER_DATA_DIR profile when set), optionally opening url in a new tab.
|
|
117
|
+
"Reuse a reachable browser or launch one (with the MCP_BROWSER_USER_DATA_DIR profile when set), optionally opening url in a new tab. It never launches twice on one profile (except from WSL).",
|
|
113
118
|
inputSchema: ensureBrowserInputSchema(
|
|
114
119
|
server.config.browserFamily,
|
|
115
120
|
server.config.enableUnsafeLaunchArgs,
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
import {
|
|
10
10
|
asImageToolResult,
|
|
11
11
|
asToolResult,
|
|
12
|
+
elementLine,
|
|
12
13
|
moveScreenshotImage,
|
|
13
14
|
} from "../tool-results.mjs";
|
|
14
15
|
import { selectorProperty, sessionWithLimitSchema } from "../tool-schemas.mjs";
|
|
@@ -36,6 +37,28 @@ export function formatSnapshotResult(result) {
|
|
|
36
37
|
structuredContent: result,
|
|
37
38
|
};
|
|
38
39
|
}
|
|
40
|
+
const DEFAULT_QUERY_ELEMENTS = 20;
|
|
41
|
+
const MAX_QUERY_ELEMENTS = 100;
|
|
42
|
+
const MAX_QUERY_NAMES = 20;
|
|
43
|
+
|
|
44
|
+
// Each matched element as its ref and line, then what was asked for; more
|
|
45
|
+
// counts the matches past the limit.
|
|
46
|
+
export function formatQueryResult(result) {
|
|
47
|
+
if (!Array.isArray(result?.elements)) {
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
const { elements, count, ...rest } = result;
|
|
51
|
+
return {
|
|
52
|
+
...rest,
|
|
53
|
+
count,
|
|
54
|
+
elements: elements.map(({ ref, node, ...asked }) => ({
|
|
55
|
+
ref,
|
|
56
|
+
element: elementLine(node),
|
|
57
|
+
...asked,
|
|
58
|
+
})),
|
|
59
|
+
...(count > elements.length ? { more: count - elements.length } : {}),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
39
62
|
const MAX_READ_CHARS = 100_000;
|
|
40
63
|
const DEFAULT_READ_LINKS = 50;
|
|
41
64
|
const MAX_READ_LINKS = 200;
|
|
@@ -199,6 +222,57 @@ export function inspectionTools(server) {
|
|
|
199
222
|
}),
|
|
200
223
|
},
|
|
201
224
|
],
|
|
225
|
+
[
|
|
226
|
+
"query_elements",
|
|
227
|
+
{
|
|
228
|
+
definition: {
|
|
229
|
+
name: "query_elements",
|
|
230
|
+
description:
|
|
231
|
+
"List every element a locator matches, each with a ref and a line as in get_snapshot, and when asked its box, attributes, or computed styles. Reads lists, layout, and styles without evaluate_js.",
|
|
232
|
+
inputSchema: {
|
|
233
|
+
type: "object",
|
|
234
|
+
properties: {
|
|
235
|
+
sessionId: { type: "string" },
|
|
236
|
+
selector: selectorProperty(),
|
|
237
|
+
box: {
|
|
238
|
+
type: "boolean",
|
|
239
|
+
description: "Add x, y, width, height in viewport CSS px.",
|
|
240
|
+
},
|
|
241
|
+
attributes: {
|
|
242
|
+
type: "array",
|
|
243
|
+
maxItems: MAX_QUERY_NAMES,
|
|
244
|
+
items: { type: "string" },
|
|
245
|
+
description: "Attribute names to read.",
|
|
246
|
+
},
|
|
247
|
+
styles: {
|
|
248
|
+
type: "array",
|
|
249
|
+
maxItems: MAX_QUERY_NAMES,
|
|
250
|
+
items: { type: "string" },
|
|
251
|
+
description: "Computed CSS properties, e.g. font-size.",
|
|
252
|
+
},
|
|
253
|
+
limit: {
|
|
254
|
+
type: "integer",
|
|
255
|
+
minimum: 1,
|
|
256
|
+
maximum: MAX_QUERY_ELEMENTS,
|
|
257
|
+
description: `Default ${DEFAULT_QUERY_ELEMENTS}.`,
|
|
258
|
+
},
|
|
259
|
+
},
|
|
260
|
+
required: ["sessionId", "selector"],
|
|
261
|
+
additionalProperties: false,
|
|
262
|
+
},
|
|
263
|
+
},
|
|
264
|
+
handler: async (args) =>
|
|
265
|
+
formatQueryResult(
|
|
266
|
+
await server.browserAdapter.queryElements(args.sessionId, {
|
|
267
|
+
selector: args.selector,
|
|
268
|
+
box: args.box === true,
|
|
269
|
+
attributes: args.attributes ?? [],
|
|
270
|
+
styles: args.styles ?? [],
|
|
271
|
+
limit: args.limit ?? DEFAULT_QUERY_ELEMENTS,
|
|
272
|
+
}),
|
|
273
|
+
),
|
|
274
|
+
},
|
|
275
|
+
],
|
|
202
276
|
[
|
|
203
277
|
"take_screenshot",
|
|
204
278
|
{
|