safari-devtools-mcp 1.2.0 → 1.3.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 +15 -0
- package/build/src/bin/safari-devtools-mcp.d.ts +7 -0
- package/build/src/bin/safari-devtools-mcp.d.ts.map +1 -1
- package/build/src/bin/safari-devtools-mcp.js +17 -1
- package/build/src/bin/safari-devtools-mcp.js.map +1 -1
- package/build/src/index.d.ts +5 -1
- package/build/src/index.d.ts.map +1 -1
- package/build/src/index.js +33 -80
- package/build/src/index.js.map +1 -1
- package/build/src/tools/console.d.ts +1 -13
- package/build/src/tools/console.d.ts.map +1 -1
- package/build/src/tools/console.js +85 -67
- package/build/src/tools/console.js.map +1 -1
- package/build/src/tools/cookies.d.ts +1 -20
- package/build/src/tools/cookies.d.ts.map +1 -1
- package/build/src/tools/cookies.js +129 -111
- package/build/src/tools/cookies.js.map +1 -1
- package/build/src/tools/css.d.ts +1 -6
- package/build/src/tools/css.d.ts.map +1 -1
- package/build/src/tools/css.js +52 -45
- package/build/src/tools/css.js.map +1 -1
- package/build/src/tools/input.d.ts +1 -63
- package/build/src/tools/input.d.ts.map +1 -1
- package/build/src/tools/input.js +311 -253
- package/build/src/tools/input.js.map +1 -1
- package/build/src/tools/network.d.ts +1 -13
- package/build/src/tools/network.d.ts.map +1 -1
- package/build/src/tools/network.js +85 -67
- package/build/src/tools/network.js.map +1 -1
- package/build/src/tools/page-content.d.ts +1 -11
- package/build/src/tools/page-content.d.ts.map +1 -1
- package/build/src/tools/page-content.js +104 -83
- package/build/src/tools/page-content.js.map +1 -1
- package/build/src/tools/pages.d.ts +1 -30
- package/build/src/tools/pages.d.ts.map +1 -1
- package/build/src/tools/pages.js +244 -202
- package/build/src/tools/pages.js.map +1 -1
- package/build/src/tools/screenshot.d.ts +1 -6
- package/build/src/tools/screenshot.d.ts.map +1 -1
- package/build/src/tools/screenshot.js +73 -65
- package/build/src/tools/screenshot.js.map +1 -1
- package/build/src/tools/script.d.ts +1 -6
- package/build/src/tools/script.d.ts.map +1 -1
- package/build/src/tools/script.js +41 -33
- package/build/src/tools/script.js.map +1 -1
- package/build/src/tools/scroll.d.ts +1 -10
- package/build/src/tools/scroll.d.ts.map +1 -1
- package/build/src/tools/scroll.js +50 -40
- package/build/src/tools/scroll.js.map +1 -1
- package/build/src/tools/snapshot.d.ts +1 -11
- package/build/src/tools/snapshot.d.ts.map +1 -1
- package/build/src/tools/snapshot.js +79 -68
- package/build/src/tools/snapshot.js.map +1 -1
- package/build/src/tools/storage.d.ts +1 -17
- package/build/src/tools/storage.d.ts.map +1 -1
- package/build/src/tools/storage.js +116 -98
- package/build/src/tools/storage.js.map +1 -1
- package/build/src/tools/types.d.ts +11 -1
- package/build/src/tools/types.d.ts.map +1 -1
- package/build/src/tools/types.js +3 -1
- package/build/src/tools/types.js.map +1 -1
- package/package.json +7 -8
|
@@ -7,69 +7,77 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { z } from 'zod';
|
|
9
9
|
import { writeFile } from 'fs/promises';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
{
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
10
|
+
import { defineTool } from './types.js';
|
|
11
|
+
export const tools = [
|
|
12
|
+
defineTool({
|
|
13
|
+
name: 'take_screenshot',
|
|
14
|
+
description: 'Take a screenshot of the page or element.',
|
|
15
|
+
slimDescription: 'Screenshot page or element.',
|
|
16
|
+
schema: {
|
|
17
|
+
uid: z
|
|
18
|
+
.string()
|
|
19
|
+
.optional()
|
|
20
|
+
.describe('The uid of an element on the page from the page content snapshot. If omitted takes a page screenshot.'),
|
|
21
|
+
filePath: z
|
|
22
|
+
.string()
|
|
23
|
+
.optional()
|
|
24
|
+
.describe('The absolute path, or a path relative to the current working directory, to save the screenshot to instead of attaching it to the response.'),
|
|
25
|
+
},
|
|
26
|
+
handler: async (params, driver) => {
|
|
27
|
+
let base64Data;
|
|
28
|
+
let description;
|
|
29
|
+
if (params.uid) {
|
|
30
|
+
base64Data = await driver.takeElementScreenshot(params.uid);
|
|
31
|
+
description = `Took a screenshot of element with uid "${params.uid}".`;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
base64Data = await driver.takeScreenshot();
|
|
35
|
+
description = "Took a screenshot of the current page's viewport.";
|
|
36
|
+
}
|
|
37
|
+
if (params.filePath) {
|
|
38
|
+
const buffer = Buffer.from(base64Data, 'base64');
|
|
39
|
+
await writeFile(params.filePath, buffer);
|
|
40
|
+
return {
|
|
41
|
+
content: [
|
|
42
|
+
{
|
|
43
|
+
type: 'text',
|
|
44
|
+
text: `${description}\nSaved screenshot to ${params.filePath}.`,
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
// Check size — if too large for inline base64, save to temp file
|
|
50
|
+
if (base64Data.length >= 2_000_000) {
|
|
51
|
+
const { tmpdir } = await import('os');
|
|
52
|
+
const { join } = await import('path');
|
|
53
|
+
const tempPath = join(tmpdir(), `safari-screenshot-${Date.now()}.png`);
|
|
54
|
+
const buffer = Buffer.from(base64Data, 'base64');
|
|
55
|
+
await writeFile(tempPath, buffer);
|
|
56
|
+
const sizeMB = (buffer.length / 1_048_576).toFixed(1);
|
|
57
|
+
return {
|
|
58
|
+
content: [
|
|
59
|
+
{
|
|
60
|
+
type: 'text',
|
|
61
|
+
text: [
|
|
62
|
+
description,
|
|
63
|
+
`\nScreenshot (${sizeMB} MB) exceeded the 1.5 MB inline limit and was saved to: ${tempPath}`,
|
|
64
|
+
'Tip: Use the filePath parameter to save directly to a preferred location, or use resize_page to reduce viewport size before capturing.',
|
|
65
|
+
].join('\n'),
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
return {
|
|
71
|
+
content: [
|
|
72
|
+
{ type: 'text', text: description },
|
|
73
|
+
{
|
|
74
|
+
type: 'image',
|
|
75
|
+
data: base64Data,
|
|
76
|
+
mimeType: 'image/png',
|
|
77
|
+
},
|
|
78
|
+
],
|
|
79
|
+
};
|
|
80
|
+
},
|
|
81
|
+
}),
|
|
82
|
+
];
|
|
75
83
|
//# sourceMappingURL=screenshot.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"screenshot.js","sourceRoot":"","sources":["../../../src/tools/screenshot.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AACtB,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"screenshot.js","sourceRoot":"","sources":["../../../src/tools/screenshot.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AACtB,OAAO,EAAC,S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,MAAM,IAAI,SAAS,EAAE,CAAC;gBACnC,MAAM,EAAC,MAAM,EAAC,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,CAAC;gBACpC,MAAM,EAAC,IAAI,EAAC,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC;gBACpC,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,EAAE,EAAE,qBAAqB,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;gBACvE,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;gBACjD,MAAM,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;gBAClC,MAAM,MAAM,GAAG,CAAC,MAAM,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;gBACtD,OAAO;oBACL,OAAO,EAAE;wBACP;4BACE,IAAI,EAAE,MAAe;4BACrB,IAAI,EAAE;gCACJ,WAAW;gCACX,iBAAiB,MAAM,2DAA2D,QAAQ,EAAE;gCAC5F,wIAAwI;6BACzI,CAAC,IAAI,CAAC,IAAI,CAAC;yBACb;qBACF;iBACF,CAAC;YACJ,CAAC;YAED,OAAO;gBACL,OAAO,EAAE;oBACP,EAAC,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,WAAW,EAAC;oBAC1C;wBACE,IAAI,EAAE,OAAgB;wBACtB,IAAI,EAAE,UAAU;wBAChB,QAAQ,EAAE,WAAW;qBACtB;iBACF;aACF,CAAC;QACJ,CAAC;KACF,CAAC;CACH,CAAC"}
|
|
@@ -3,10 +3,5 @@
|
|
|
3
3
|
* Mirrors chrome-devtools-mcp tool name: evaluate_script
|
|
4
4
|
*/
|
|
5
5
|
import { z } from 'zod';
|
|
6
|
-
|
|
7
|
-
export declare const evaluateScriptSchema: {
|
|
8
|
-
function: z.ZodString;
|
|
9
|
-
args: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
10
|
-
};
|
|
11
|
-
export declare const evaluateScript: ToolHandler;
|
|
6
|
+
export declare const tools: import("./types.js").ToolDef<z.ZodRawShape>[];
|
|
12
7
|
//# sourceMappingURL=script.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"script.d.ts","sourceRoot":"","sources":["../../../src/tools/script.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"script.d.ts","sourceRoot":"","sources":["../../../src/tools/script.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAGtB,eAAO,MAAM,KAAK,+CA0DjB,CAAC"}
|
|
@@ -3,8 +3,14 @@
|
|
|
3
3
|
* Mirrors chrome-devtools-mcp tool name: evaluate_script
|
|
4
4
|
*/
|
|
5
5
|
import { z } from 'zod';
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
import { defineTool } from './types.js';
|
|
7
|
+
export const tools = [
|
|
8
|
+
defineTool({
|
|
9
|
+
name: 'evaluate_script',
|
|
10
|
+
description: 'Evaluate a JavaScript function inside the currently selected page. Returns the response as JSON, so returned values have to be JSON-serializable.',
|
|
11
|
+
slimDescription: 'Evaluate JavaScript in page. Returns JSON.',
|
|
12
|
+
schema: {
|
|
13
|
+
function: z.string().describe(`A JavaScript function declaration to be executed in the currently selected page.
|
|
8
14
|
Example without arguments: \`() => {
|
|
9
15
|
return document.title
|
|
10
16
|
}\` or \`async () => {
|
|
@@ -14,35 +20,37 @@ Example with arguments: \`(el) => {
|
|
|
14
20
|
return el.innerText;
|
|
15
21
|
}\`
|
|
16
22
|
`),
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
23
|
+
args: z
|
|
24
|
+
.array(z
|
|
25
|
+
.string()
|
|
26
|
+
.describe('The uid of an element on the page from the page content snapshot'))
|
|
27
|
+
.optional()
|
|
28
|
+
.describe('An optional list of element UIDs to pass as arguments.'),
|
|
29
|
+
},
|
|
30
|
+
handler: async (params, driver) => {
|
|
31
|
+
try {
|
|
32
|
+
const result = await driver.evaluateScript(params.function, params.args);
|
|
33
|
+
return {
|
|
34
|
+
content: [
|
|
35
|
+
{
|
|
36
|
+
type: 'text',
|
|
37
|
+
text: `Script ran on page and returned:\n\`\`\`json\n${result}\n\`\`\``,
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
return {
|
|
44
|
+
content: [
|
|
45
|
+
{
|
|
46
|
+
type: 'text',
|
|
47
|
+
text: `Script evaluation failed: ${error instanceof Error ? error.message : String(error)}`,
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
isError: true,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
}),
|
|
55
|
+
];
|
|
48
56
|
//# sourceMappingURL=script.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"script.js","sourceRoot":"","sources":["../../../src/tools/script.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"script.js","sourceRoot":"","sources":["../../../src/tools/script.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AACtB,OAAO,EAAC,UAAU,EAAC,MAAM,YAAY,CAAC;AAEtC,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,UAAU,CAAC;QACT,IAAI,EAAE,iBAAiB;QACvB,WAAW,EACT,mJAAmJ;QACrJ,eAAe,EAAE,4CAA4C;QAC7D,MAAM,EAAE;YACN,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAC3B;;;;;;;;;CASP,CACM;YACD,IAAI,EAAE,CAAC;iBACJ,KAAK,CACJ,CAAC;iBACE,MAAM,EAAE;iBACR,QAAQ,CACP,kEAAkE,CACnE,CACJ;iBACA,QAAQ,EAAE;iBACV,QAAQ,CAAC,wDAAwD,CAAC;SACtE;QACD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;YAChC,IAAI,CAAC;gBACH,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,cAAc,CACxC,MAAM,CAAC,QAAQ,EACf,MAAM,CAAC,IAAI,CACZ,CAAC;gBAEF,OAAO;oBACL,OAAO,EAAE;wBACP;4BACE,IAAI,EAAE,MAAe;4BACrB,IAAI,EAAE,iDAAiD,MAAM,UAAU;yBACxE;qBACF;iBACF,CAAC;YACJ,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO;oBACL,OAAO,EAAE;wBACP;4BACE,IAAI,EAAE,MAAe;4BACrB,IAAI,EAAE,6BAA6B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;yBAC5F;qBACF;oBACD,OAAO,EAAE,IAAI;iBACd,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC;CACH,CAAC"}
|
|
@@ -3,14 +3,5 @@
|
|
|
3
3
|
* Provides scroll by direction and scroll-to-element capabilities.
|
|
4
4
|
*/
|
|
5
5
|
import { z } from 'zod';
|
|
6
|
-
|
|
7
|
-
export declare const scrollSchema: {
|
|
8
|
-
direction: z.ZodEnum<["up", "down", "left", "right"]>;
|
|
9
|
-
amount: z.ZodOptional<z.ZodNumber>;
|
|
10
|
-
};
|
|
11
|
-
export declare const scroll: ToolHandler;
|
|
12
|
-
export declare const scrollToElementSchema: {
|
|
13
|
-
uid: z.ZodString;
|
|
14
|
-
};
|
|
15
|
-
export declare const scrollToElement: ToolHandler;
|
|
6
|
+
export declare const tools: import("./types.js").ToolDef<z.ZodRawShape>[];
|
|
16
7
|
//# sourceMappingURL=scroll.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scroll.d.ts","sourceRoot":"","sources":["../../../src/tools/scroll.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"scroll.d.ts","sourceRoot":"","sources":["../../../src/tools/scroll.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAGtB,eAAO,MAAM,KAAK,+CAmDjB,CAAC"}
|
|
@@ -3,44 +3,54 @@
|
|
|
3
3
|
* Provides scroll by direction and scroll-to-element capabilities.
|
|
4
4
|
*/
|
|
5
5
|
import { z } from 'zod';
|
|
6
|
-
|
|
7
|
-
export const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
6
|
+
import { defineTool } from './types.js';
|
|
7
|
+
export const tools = [
|
|
8
|
+
defineTool({
|
|
9
|
+
name: 'scroll',
|
|
10
|
+
description: 'Scroll the page in a direction by a given amount of pixels.',
|
|
11
|
+
slimDescription: 'Scroll the page.',
|
|
12
|
+
schema: {
|
|
13
|
+
direction: z
|
|
14
|
+
.enum(['up', 'down', 'left', 'right'])
|
|
15
|
+
.describe('The direction to scroll.'),
|
|
16
|
+
amount: z
|
|
17
|
+
.number()
|
|
18
|
+
.optional()
|
|
19
|
+
.describe('The number of pixels to scroll. Default is 500.'),
|
|
20
|
+
},
|
|
21
|
+
handler: async (params, driver) => {
|
|
22
|
+
const amount = params.amount ?? 500;
|
|
23
|
+
await driver.scroll(params.direction, amount);
|
|
24
|
+
return {
|
|
25
|
+
content: [
|
|
26
|
+
{
|
|
27
|
+
type: 'text',
|
|
28
|
+
text: `Scrolled ${params.direction} by ${amount}px.`,
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
}),
|
|
34
|
+
defineTool({
|
|
35
|
+
name: 'scroll_to_element',
|
|
36
|
+
description: 'Scroll an element into view by its UID from a snapshot.',
|
|
37
|
+
slimDescription: 'Scroll element into view.',
|
|
38
|
+
schema: {
|
|
39
|
+
uid: z
|
|
40
|
+
.string()
|
|
41
|
+
.describe('The uid of an element on the page from the page content snapshot.'),
|
|
42
|
+
},
|
|
43
|
+
handler: async (params, driver) => {
|
|
44
|
+
await driver.scrollToElement(params.uid);
|
|
45
|
+
return {
|
|
46
|
+
content: [
|
|
47
|
+
{
|
|
48
|
+
type: 'text',
|
|
49
|
+
text: `Scrolled element ${params.uid} into view.`,
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
}),
|
|
55
|
+
];
|
|
46
56
|
//# sourceMappingURL=scroll.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scroll.js","sourceRoot":"","sources":["../../../src/tools/scroll.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"scroll.js","sourceRoot":"","sources":["../../../src/tools/scroll.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AACtB,OAAO,EAAC,UAAU,EAAC,MAAM,YAAY,CAAC;AAEtC,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,UAAU,CAAC;QACT,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,6DAA6D;QAC1E,eAAe,EAAE,kBAAkB;QACnC,MAAM,EAAE;YACN,SAAS,EAAE,CAAC;iBACT,IAAI,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;iBACrC,QAAQ,CAAC,0BAA0B,CAAC;YACvC,MAAM,EAAE,CAAC;iBACN,MAAM,EAAE;iBACR,QAAQ,EAAE;iBACV,QAAQ,CAAC,iDAAiD,CAAC;SAC/D;QACD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;YAChC,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,GAAG,CAAC;YACpC,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;YAC9C,OAAO;gBACL,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,MAAe;wBACrB,IAAI,EAAE,YAAY,MAAM,CAAC,SAAS,OAAO,MAAM,KAAK;qBACrD;iBACF;aACF,CAAC;QACJ,CAAC;KACF,CAAC;IAEF,UAAU,CAAC;QACT,IAAI,EAAE,mBAAmB;QACzB,WAAW,EAAE,yDAAyD;QACtE,eAAe,EAAE,2BAA2B;QAC5C,MAAM,EAAE;YACN,GAAG,EAAE,CAAC;iBACH,MAAM,EAAE;iBACR,QAAQ,CACP,mEAAmE,CACpE;SACJ;QACD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;YAChC,MAAM,MAAM,CAAC,eAAe,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACzC,OAAO;gBACL,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,MAAe;wBACrB,IAAI,EAAE,oBAAoB,MAAM,CAAC,GAAG,aAAa;qBAClD;iBACF;aACF,CAAC;QACJ,CAAC;KACF,CAAC;CACH,CAAC"}
|
|
@@ -3,15 +3,5 @@
|
|
|
3
3
|
* Mirrors chrome-devtools-mcp tool names: take_snapshot, wait_for
|
|
4
4
|
*/
|
|
5
5
|
import { z } from 'zod';
|
|
6
|
-
|
|
7
|
-
export declare const takeSnapshotSchema: {
|
|
8
|
-
verbose: z.ZodOptional<z.ZodBoolean>;
|
|
9
|
-
filePath: z.ZodOptional<z.ZodString>;
|
|
10
|
-
};
|
|
11
|
-
export declare const takeSnapshot: ToolHandler;
|
|
12
|
-
export declare const waitForSchema: {
|
|
13
|
-
text: z.ZodArray<z.ZodString, "many">;
|
|
14
|
-
timeout: z.ZodOptional<z.ZodNumber>;
|
|
15
|
-
};
|
|
16
|
-
export declare const waitFor: ToolHandler;
|
|
6
|
+
export declare const tools: import("./types.js").ToolDef<z.ZodRawShape>[];
|
|
17
7
|
//# sourceMappingURL=snapshot.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../../../src/tools/snapshot.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"snapshot.d.ts","sourceRoot":"","sources":["../../../src/tools/snapshot.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAKtB,eAAO,MAAM,KAAK,+CAuFjB,CAAC"}
|
|
@@ -5,72 +5,83 @@
|
|
|
5
5
|
import { z } from 'zod';
|
|
6
6
|
import { writeFile } from 'fs/promises';
|
|
7
7
|
import { formatSnapshot } from '../formatters/SnapshotFormatter.js';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
8
|
+
import { defineTool } from './types.js';
|
|
9
|
+
export const tools = [
|
|
10
|
+
defineTool({
|
|
11
|
+
name: 'take_snapshot',
|
|
12
|
+
description: 'Take a text snapshot of the currently selected page based on the DOM/a11y tree. The snapshot lists page elements along with a unique identifier (uid). Always use the latest snapshot. Prefer taking a snapshot over taking a screenshot.',
|
|
13
|
+
slimDescription: 'Snapshot the page DOM/a11y tree with element UIDs.',
|
|
14
|
+
schema: {
|
|
15
|
+
verbose: z
|
|
16
|
+
.boolean()
|
|
17
|
+
.optional()
|
|
18
|
+
.describe('Whether to include all possible information (tag names, attributes). Default is true.'),
|
|
19
|
+
filePath: z
|
|
20
|
+
.string()
|
|
21
|
+
.optional()
|
|
22
|
+
.describe('The absolute path, or a path relative to the current working directory, to save the snapshot to instead of attaching it to the response.'),
|
|
23
|
+
},
|
|
24
|
+
handler: async (params, driver) => {
|
|
25
|
+
const verbose = params.verbose !== false; // default true
|
|
26
|
+
const tree = await driver.takeSnapshot(verbose);
|
|
27
|
+
const text = formatSnapshot(tree, verbose);
|
|
28
|
+
if (params.filePath) {
|
|
29
|
+
await writeFile(params.filePath, text, 'utf-8');
|
|
30
|
+
return {
|
|
31
|
+
content: [
|
|
32
|
+
{
|
|
33
|
+
type: 'text',
|
|
34
|
+
text: `Snapshot saved to ${params.filePath}.`,
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
content: [{ type: 'text', text }],
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
}),
|
|
44
|
+
defineTool({
|
|
45
|
+
name: 'wait_for',
|
|
46
|
+
description: 'Wait for the specified text to appear on the selected page.',
|
|
47
|
+
slimDescription: 'Wait for text on page.',
|
|
48
|
+
schema: {
|
|
49
|
+
text: z
|
|
50
|
+
.array(z.string())
|
|
51
|
+
.min(1)
|
|
52
|
+
.describe('Non-empty list of texts. Resolves when any value appears on the page.'),
|
|
53
|
+
timeout: z
|
|
54
|
+
.number()
|
|
55
|
+
.optional()
|
|
56
|
+
.describe('Timeout in milliseconds. Default is 30000.'),
|
|
57
|
+
},
|
|
58
|
+
handler: async (params, driver) => {
|
|
59
|
+
try {
|
|
60
|
+
const found = await driver.waitForText(params.text, params.timeout);
|
|
61
|
+
// Take a snapshot after waiting
|
|
62
|
+
const tree = await driver.takeSnapshot();
|
|
63
|
+
const snapshotText = formatSnapshot(tree);
|
|
64
|
+
return {
|
|
65
|
+
content: [
|
|
66
|
+
{
|
|
67
|
+
type: 'text',
|
|
68
|
+
text: `Element matching "${found}" found.\n\n${snapshotText}`,
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
return {
|
|
75
|
+
content: [
|
|
76
|
+
{
|
|
77
|
+
type: 'text',
|
|
78
|
+
text: error instanceof Error ? error.message : String(error),
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
isError: true,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
}),
|
|
86
|
+
];
|
|
76
87
|
//# sourceMappingURL=snapshot.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"snapshot.js","sourceRoot":"","sources":["../../../src/tools/snapshot.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AACtB,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AACtC,OAAO,EAAC,cAAc,EAAC,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"snapshot.js","sourceRoot":"","sources":["../../../src/tools/snapshot.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AACtB,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AACtC,OAAO,EAAC,cAAc,EAAC,MAAM,oCAAoC,CAAC;AAClE,OAAO,EAAC,UAAU,EAAC,MAAM,YAAY,CAAC;AAEtC,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,UAAU,CAAC;QACT,IAAI,EAAE,eAAe;QACrB,WAAW,EACT,2OAA2O;QAC7O,eAAe,EAAE,oDAAoD;QACrE,MAAM,EAAE;YACN,OAAO,EAAE,CAAC;iBACP,OAAO,EAAE;iBACT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I,CAAC;gBACH,MAAM,KAAK,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;gBACpE,gCAAgC;gBAChC,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,YAAY,EAAE,CAAC;gBACzC,MAAM,YAAY,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC;gBAE1C,OAAO;oBACL,OAAO,EAAE;wBACP;4BACE,IAAI,EAAE,MAAe;4BACrB,IAAI,EAAE,qBAAqB,KAAK,eAAe,YAAY,EAAE;yBAC9D;qBACF;iBACF,CAAC;YACJ,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO;oBACL,OAAO,EAAE;wBACP;4BACE,IAAI,EAAE,MAAe;4BACrB,IAAI,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;yBAC7D;qBACF;oBACD,OAAO,EAAE,IAAI;iBACd,CAAC;YACJ,CAAC;QACH,CAAC;KACF,CAAC;CACH,CAAC"}
|
|
@@ -2,21 +2,5 @@
|
|
|
2
2
|
* Browser storage tools (localStorage and sessionStorage).
|
|
3
3
|
*/
|
|
4
4
|
import { z } from 'zod';
|
|
5
|
-
|
|
6
|
-
export declare const getStorageSchema: {
|
|
7
|
-
storageType: z.ZodOptional<z.ZodEnum<["localStorage", "sessionStorage"]>>;
|
|
8
|
-
key: z.ZodOptional<z.ZodString>;
|
|
9
|
-
};
|
|
10
|
-
export declare const getStorage: ToolHandler;
|
|
11
|
-
export declare const setStorageSchema: {
|
|
12
|
-
storageType: z.ZodOptional<z.ZodEnum<["localStorage", "sessionStorage"]>>;
|
|
13
|
-
key: z.ZodString;
|
|
14
|
-
value: z.ZodString;
|
|
15
|
-
};
|
|
16
|
-
export declare const setStorage: ToolHandler;
|
|
17
|
-
export declare const deleteStorageSchema: {
|
|
18
|
-
storageType: z.ZodOptional<z.ZodEnum<["localStorage", "sessionStorage"]>>;
|
|
19
|
-
key: z.ZodOptional<z.ZodString>;
|
|
20
|
-
};
|
|
21
|
-
export declare const deleteStorage: ToolHandler;
|
|
5
|
+
export declare const tools: import("./types.js").ToolDef<z.ZodRawShape>[];
|
|
22
6
|
//# sourceMappingURL=storage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../../src/tools/storage.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../../src/tools/storage.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAKtB,eAAO,MAAM,KAAK,+CAsIjB,CAAC"}
|