-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathsnapshot.ts
More file actions
53 lines (47 loc) · 1.55 KB
/
snapshot.ts
File metadata and controls
53 lines (47 loc) · 1.55 KB
1
2
3
4
5
6
7
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
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import {zod} from '../third_party/modelcontextprotocol-sdk/index.js';
import {ToolCategories} from './categories.js';
import {defineTool, timeoutSchema} from './ToolDefinition.js';
export const takeSnapshot = defineTool({
name: 'take_snapshot',
description: `Take a text snapshot of the currently selected page based on the 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.`,
annotations: {
category: ToolCategories.DEBUGGING,
readOnlyHint: true,
},
schema: {
verbose: zod
.boolean()
.optional()
.describe(
'Whether to include all possible information available in the full a11y tree. Default is false.',
),
},
handler: async (request, response) => {
response.setIncludeSnapshot(true, request.params.verbose ?? false);
},
});
export const waitFor = defineTool({
name: 'wait_for',
description: `Wait for the specified text to appear on the selected page.`,
annotations: {
category: ToolCategories.NAVIGATION_AUTOMATION,
readOnlyHint: true,
},
schema: {
text: zod.string().describe('Text to appear on the page'),
...timeoutSchema,
},
handler: async (request, response, context) => {
await context.waitForTextOnPage(request.params);
response.appendResponseLine(
`Element with text "${request.params.text}" found.`,
);
response.setIncludeSnapshot(true);
},
});