Skip to content

Commit 4bb0c18

Browse files
Merge branch 'main' into stabilize-test
2 parents e4b16e9 + 800e7e8 commit 4bb0c18

File tree

12 files changed

+72
-65
lines changed

12 files changed

+72
-65
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@
4040
"core-js": "3.46.0",
4141
"debug": "4.4.3",
4242
"puppeteer-core": "^24.24.1",
43-
"yargs": "18.0.0",
44-
"zod": "^3.25.76"
43+
"yargs": "18.0.0"
4544
},
4645
"devDependencies": {
4746
"@eslint/js": "^9.35.0",

src/third_party/modelcontextprotocol-sdk/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ export {
1212
type ImageContent,
1313
type TextContent,
1414
} from '@modelcontextprotocol/sdk/types.js';
15+
export {z as zod} from 'zod';

src/tools/ToolDefinition.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@
55
*/
66

77
import type {Dialog, ElementHandle, Page} from 'puppeteer-core';
8-
import z from 'zod';
98

109
import type {TextSnapshotNode} from '../McpContext.js';
10+
import {zod} from '../third_party/modelcontextprotocol-sdk/index.js';
1111
import type {TraceResult} from '../trace-processing/parse.js';
1212
import type {PaginationOptions} from '../utils/types.js';
1313

1414
import type {ToolCategories} from './categories.js';
1515

16-
export interface ToolDefinition<Schema extends z.ZodRawShape = z.ZodRawShape> {
16+
export interface ToolDefinition<
17+
Schema extends zod.ZodRawShape = zod.ZodRawShape,
18+
> {
1719
name: string;
1820
description: string;
1921
annotations: {
@@ -32,8 +34,8 @@ export interface ToolDefinition<Schema extends z.ZodRawShape = z.ZodRawShape> {
3234
) => Promise<void>;
3335
}
3436

35-
export interface Request<Schema extends z.ZodRawShape> {
36-
params: z.objectOutputType<Schema, z.ZodTypeAny>;
37+
export interface Request<Schema extends zod.ZodRawShape> {
38+
params: zod.objectOutputType<Schema, zod.ZodTypeAny>;
3739
}
3840

3941
export interface ImageContentData {
@@ -92,7 +94,7 @@ export type Context = Readonly<{
9294
waitForEventsAfterAction(action: () => Promise<unknown>): Promise<void>;
9395
}>;
9496

95-
export function defineTool<Schema extends z.ZodRawShape>(
97+
export function defineTool<Schema extends zod.ZodRawShape>(
9698
definition: ToolDefinition<Schema>,
9799
) {
98100
return definition;
@@ -102,7 +104,7 @@ export const CLOSE_PAGE_ERROR =
102104
'The last open page cannot be closed. It is fine to keep it open.';
103105

104106
export const timeoutSchema = {
105-
timeout: z
107+
timeout: zod
106108
.number()
107109
.int()
108110
.optional()

src/tools/console.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
*/
66

77
import type {ConsoleMessageType} from 'puppeteer-core';
8-
import z from 'zod';
8+
9+
import {zod} from '../third_party/modelcontextprotocol-sdk/index.js';
910

1011
import {ToolCategories} from './categories.js';
1112
import {defineTool} from './ToolDefinition.js';
@@ -44,24 +45,24 @@ export const consoleTool = defineTool({
4445
readOnlyHint: true,
4546
},
4647
schema: {
47-
pageSize: z
48+
pageSize: zod
4849
.number()
4950
.int()
5051
.positive()
5152
.optional()
5253
.describe(
5354
'Maximum number of messages to return. When omitted, returns all requests.',
5455
),
55-
pageIdx: z
56+
pageIdx: zod
5657
.number()
5758
.int()
5859
.min(0)
5960
.optional()
6061
.describe(
6162
'Page number to return (0-based). When omitted, returns the first page.',
6263
),
63-
types: z
64-
.array(z.enum(FILTERABLE_MESSAGE_TYPES))
64+
types: zod
65+
.array(zod.enum(FILTERABLE_MESSAGE_TYPES))
6566
.optional()
6667
.describe(
6768
'Filter messages to only return messages of the specified resource types. When omitted or empty, returns all messages.',

src/tools/emulation.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
*/
66

77
import {PredefinedNetworkConditions} from 'puppeteer-core';
8-
import z from 'zod';
8+
9+
import {zod} from '../third_party/modelcontextprotocol-sdk/index.js';
910

1011
import {ToolCategories} from './categories.js';
1112
import {defineTool} from './ToolDefinition.js';
@@ -24,7 +25,7 @@ export const emulateNetwork = defineTool({
2425
readOnlyHint: false,
2526
},
2627
schema: {
27-
throttlingOption: z
28+
throttlingOption: zod
2829
.enum(throttlingOptions)
2930
.describe(
3031
`The network throttling option to emulate. Available throttling options are: ${throttlingOptions.join(', ')}. Set to "No emulation" to disable. Set to "Offline" to simulate offline network conditions.`,
@@ -70,7 +71,7 @@ export const emulateCpu = defineTool({
7071
readOnlyHint: false,
7172
},
7273
schema: {
73-
throttlingRate: z
74+
throttlingRate: zod
7475
.number()
7576
.min(1)
7677
.max(20)

src/tools/input.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
*/
66

77
import type {ElementHandle} from 'puppeteer-core';
8-
import z from 'zod';
98

109
import type {McpContext, TextSnapshotNode} from '../McpContext.js';
10+
import {zod} from '../third_party/modelcontextprotocol-sdk/index.js';
1111

1212
import {ToolCategories} from './categories.js';
1313
import {defineTool} from './ToolDefinition.js';
@@ -20,12 +20,12 @@ export const click = defineTool({
2020
readOnlyHint: false,
2121
},
2222
schema: {
23-
uid: z
23+
uid: zod
2424
.string()
2525
.describe(
2626
'The uid of an element on the page from the page content snapshot',
2727
),
28-
dblClick: z
28+
dblClick: zod
2929
.boolean()
3030
.optional()
3131
.describe('Set to true for double clicks. Default is false.'),
@@ -59,7 +59,7 @@ export const hover = defineTool({
5959
readOnlyHint: false,
6060
},
6161
schema: {
62-
uid: z
62+
uid: zod
6363
.string()
6464
.describe(
6565
'The uid of an element on the page from the page content snapshot',
@@ -143,12 +143,12 @@ export const fill = defineTool({
143143
readOnlyHint: false,
144144
},
145145
schema: {
146-
uid: z
146+
uid: zod
147147
.string()
148148
.describe(
149149
'The uid of an element on the page from the page content snapshot',
150150
),
151-
value: z.string().describe('The value to fill in'),
151+
value: zod.string().describe('The value to fill in'),
152152
},
153153
handler: async (request, response, context) => {
154154
await context.waitForEventsAfterAction(async () => {
@@ -171,8 +171,8 @@ export const drag = defineTool({
171171
readOnlyHint: false,
172172
},
173173
schema: {
174-
from_uid: z.string().describe('The uid of the element to drag'),
175-
to_uid: z.string().describe('The uid of the element to drop into'),
174+
from_uid: zod.string().describe('The uid of the element to drag'),
175+
to_uid: zod.string().describe('The uid of the element to drop into'),
176176
},
177177
handler: async (request, response, context) => {
178178
const fromHandle = await context.getElementByUid(request.params.from_uid);
@@ -200,11 +200,11 @@ export const fillForm = defineTool({
200200
readOnlyHint: false,
201201
},
202202
schema: {
203-
elements: z
203+
elements: zod
204204
.array(
205-
z.object({
206-
uid: z.string().describe('The uid of the element to fill out'),
207-
value: z.string().describe('Value for the element'),
205+
zod.object({
206+
uid: zod.string().describe('The uid of the element to fill out'),
207+
value: zod.string().describe('Value for the element'),
208208
}),
209209
)
210210
.describe('Elements from snapshot to fill out.'),
@@ -232,12 +232,12 @@ export const uploadFile = defineTool({
232232
readOnlyHint: false,
233233
},
234234
schema: {
235-
uid: z
235+
uid: zod
236236
.string()
237237
.describe(
238238
'The uid of the file input element or an element that will open file chooser on the page from the page content snapshot',
239239
),
240-
filePath: z.string().describe('The local path of the file to upload'),
240+
filePath: zod.string().describe('The local path of the file to upload'),
241241
},
242242
handler: async (request, response, context) => {
243243
const {uid, filePath} = request.params;

src/tools/network.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
*/
66

77
import type {ResourceType} from 'puppeteer-core';
8-
import z from 'zod';
8+
9+
import {zod} from '../third_party/modelcontextprotocol-sdk/index.js';
910

1011
import {ToolCategories} from './categories.js';
1112
import {defineTool} from './ToolDefinition.js';
@@ -40,24 +41,24 @@ export const listNetworkRequests = defineTool({
4041
readOnlyHint: true,
4142
},
4243
schema: {
43-
pageSize: z
44+
pageSize: zod
4445
.number()
4546
.int()
4647
.positive()
4748
.optional()
4849
.describe(
4950
'Maximum number of requests to return. When omitted, returns all requests.',
5051
),
51-
pageIdx: z
52+
pageIdx: zod
5253
.number()
5354
.int()
5455
.min(0)
5556
.optional()
5657
.describe(
5758
'Page number to return (0-based). When omitted, returns the first page.',
5859
),
59-
resourceTypes: z
60-
.array(z.enum(FILTERABLE_RESOURCE_TYPES))
60+
resourceTypes: zod
61+
.array(zod.enum(FILTERABLE_RESOURCE_TYPES))
6162
.optional()
6263
.describe(
6364
'Filter requests to only return requests of the specified resource types. When omitted or empty, returns all requests.',
@@ -80,7 +81,7 @@ export const getNetworkRequest = defineTool({
8081
readOnlyHint: true,
8182
},
8283
schema: {
83-
reqid: z
84+
reqid: zod
8485
.number()
8586
.describe(
8687
'The reqid of a request on the page from the listed network requests',

src/tools/pages.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
import z from 'zod';
8-
97
import {logger} from '../logger.js';
8+
import {zod} from '../third_party/modelcontextprotocol-sdk/index.js';
109

1110
import {ToolCategories} from './categories.js';
1211
import {CLOSE_PAGE_ERROR, defineTool, timeoutSchema} from './ToolDefinition.js';
@@ -32,7 +31,7 @@ export const selectPage = defineTool({
3231
readOnlyHint: true,
3332
},
3433
schema: {
35-
pageIdx: z
34+
pageIdx: zod
3635
.number()
3736
.describe(
3837
'The index of the page to select. Call list_pages to list pages.',
@@ -54,7 +53,7 @@ export const closePage = defineTool({
5453
readOnlyHint: false,
5554
},
5655
schema: {
57-
pageIdx: z
56+
pageIdx: zod
5857
.number()
5958
.describe(
6059
'The index of the page to close. Call list_pages to list pages.',
@@ -82,7 +81,7 @@ export const newPage = defineTool({
8281
readOnlyHint: false,
8382
},
8483
schema: {
85-
url: z.string().describe('URL to load in a new page.'),
84+
url: zod.string().describe('URL to load in a new page.'),
8685
...timeoutSchema,
8786
},
8887
handler: async (request, response, context) => {
@@ -106,7 +105,7 @@ export const navigatePage = defineTool({
106105
readOnlyHint: false,
107106
},
108107
schema: {
109-
url: z.string().describe('URL to navigate the page to'),
108+
url: zod.string().describe('URL to navigate the page to'),
110109
...timeoutSchema,
111110
},
112111
handler: async (request, response, context) => {
@@ -130,7 +129,7 @@ export const navigatePageHistory = defineTool({
130129
readOnlyHint: false,
131130
},
132131
schema: {
133-
navigate: z
132+
navigate: zod
134133
.enum(['back', 'forward'])
135134
.describe(
136135
'Whether to navigate back or navigate forward in the selected pages history',
@@ -167,8 +166,8 @@ export const resizePage = defineTool({
167166
readOnlyHint: false,
168167
},
169168
schema: {
170-
width: z.number().describe('Page width'),
171-
height: z.number().describe('Page height'),
169+
width: zod.number().describe('Page width'),
170+
height: zod.number().describe('Page height'),
172171
},
173172
handler: async (request, response, context) => {
174173
const page = context.getSelectedPage();
@@ -191,10 +190,10 @@ export const handleDialog = defineTool({
191190
readOnlyHint: false,
192191
},
193192
schema: {
194-
action: z
193+
action: zod
195194
.enum(['accept', 'dismiss'])
196195
.describe('Whether to dismiss or accept the dialog'),
197-
promptText: z
196+
promptText: zod
198197
.string()
199198
.optional()
200199
.describe('Optional prompt text to enter into the dialog.'),

src/tools/performance.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
*/
66

77
import type {Page} from 'puppeteer-core';
8-
import z from 'zod';
98

109
import {logger} from '../logger.js';
10+
import {zod} from '../third_party/modelcontextprotocol-sdk/index.js';
1111
import type {InsightName} from '../trace-processing/parse.js';
1212
import {
1313
getInsightOutput,
@@ -29,12 +29,12 @@ export const startTrace = defineTool({
2929
readOnlyHint: true,
3030
},
3131
schema: {
32-
reload: z
32+
reload: zod
3333
.boolean()
3434
.describe(
3535
'Determines if, once tracing has started, the page should be automatically reloaded.',
3636
),
37-
autoStop: z
37+
autoStop: zod
3838
.boolean()
3939
.describe(
4040
'Determines if the trace recording should be automatically stopped.',
@@ -128,7 +128,7 @@ export const analyzeInsight = defineTool({
128128
readOnlyHint: true,
129129
},
130130
schema: {
131-
insightName: z
131+
insightName: zod
132132
.string()
133133
.describe(
134134
'The name of the Insight you want more information on. For example: "DocumentLatency" or "LCPBreakdown"',

0 commit comments

Comments
 (0)