-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathconsole.ts
More file actions
78 lines (73 loc) · 1.73 KB
/
console.ts
File metadata and controls
78 lines (73 loc) · 1.73 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import type {ConsoleMessageType} from 'puppeteer-core';
import {zod} from '../third_party/modelcontextprotocol-sdk/index.js';
import {ToolCategories} from './categories.js';
import {defineTool} from './ToolDefinition.js';
const FILTERABLE_MESSAGE_TYPES: readonly [
ConsoleMessageType,
...ConsoleMessageType[],
] = [
'log',
'debug',
'info',
'error',
'warn',
'dir',
'dirxml',
'table',
'trace',
'clear',
'startGroup',
'startGroupCollapsed',
'endGroup',
'assert',
'profile',
'profileEnd',
'count',
'timeEnd',
'verbose',
];
export const consoleTool = defineTool({
name: 'list_console_messages',
description:
'List all console messages for the currently selected page since the last navigation.',
annotations: {
category: ToolCategories.DEBUGGING,
readOnlyHint: true,
},
schema: {
pageSize: zod
.number()
.int()
.positive()
.optional()
.describe(
'Maximum number of messages to return. When omitted, returns all requests.',
),
pageIdx: zod
.number()
.int()
.min(0)
.optional()
.describe(
'Page number to return (0-based). When omitted, returns the first page.',
),
types: zod
.array(zod.enum(FILTERABLE_MESSAGE_TYPES))
.optional()
.describe(
'Filter messages to only return messages of the specified resource types. When omitted or empty, returns all messages.',
),
},
handler: async (request, response) => {
response.setIncludeConsoleData(true, {
pageSize: request.params.pageSize,
pageIdx: request.params.pageIdx,
types: request.params.types,
});
},
});