chrome-devtools-mcp 0.2.7 → 0.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 +10 -2
- package/build/node_modules/chrome-devtools-frontend/front_end/core/host/GdpClient.js +18 -3
- package/build/node_modules/chrome-devtools-frontend/front_end/core/host/UserMetrics.js +3 -2
- package/build/node_modules/chrome-devtools-frontend/front_end/core/i18n/i18n.js +24 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/CSSMatchedStyles.js +5 -1
- package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/EnhancedTracesParser.js +4 -5
- package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/NetworkManager.js +1 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/NetworkRequest.js +8 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/core/sdk/TargetManager.js +4 -0
- package/build/node_modules/chrome-devtools-frontend/front_end/generated/InspectorBackendCommands.js +10 -7
- package/build/node_modules/chrome-devtools-frontend/front_end/generated/SupportedCSSProperties.js +40 -11
- package/build/node_modules/chrome-devtools-frontend/front_end/models/ai_assistance/data_formatters/PerformanceInsightFormatter.js +95 -283
- package/build/node_modules/chrome-devtools-frontend/front_end/models/ai_assistance/data_formatters/PerformanceTraceFormatter.js +256 -22
- package/build/node_modules/chrome-devtools-frontend/front_end/models/ai_assistance/performance/AICallTree.js +12 -6
- package/build/node_modules/chrome-devtools-frontend/front_end/models/ai_assistance/performance/AIContext.js +64 -7
- package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/EventsSerializer.js +3 -3
- package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/UserInteractionsHandler.js +91 -63
- package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/handlers/UserTimingsHandler.js +1 -1
- package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/helpers/Timing.js +1 -1
- package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/helpers/Trace.js +98 -36
- package/build/node_modules/chrome-devtools-frontend/front_end/models/trace/types/TraceEvents.js +9 -0
- package/build/src/McpContext.js +8 -2
- package/build/src/McpResponse.js +30 -3
- package/build/src/browser.js +2 -2
- package/build/src/cli.js +82 -0
- package/build/src/formatters/consoleFormatter.js +3 -1
- package/build/src/index.js +1 -1
- package/build/src/main.js +11 -84
- package/build/src/tools/ToolDefinition.js +1 -0
- package/build/src/tools/emulation.js +2 -2
- package/build/src/tools/input.js +8 -8
- package/build/src/tools/network.js +20 -4
- package/build/src/tools/pages.js +12 -2
- package/build/src/tools/performance.js +2 -2
- package/build/src/tools/screenshot.js +1 -1
- package/build/src/tools/script.js +4 -7
- package/build/src/tools/snapshot.js +2 -2
- package/build/src/trace-processing/parse.js +5 -6
- package/build/src/utils/pagination.js +49 -0
- package/package.json +9 -6
package/build/src/main.js
CHANGED
|
@@ -3,17 +3,20 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
+
import assert from 'node:assert';
|
|
7
|
+
import fs from 'node:fs';
|
|
8
|
+
import path from 'node:path';
|
|
6
9
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
7
10
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
8
|
-
import { SetLevelRequestSchema
|
|
9
|
-
import yargs from 'yargs';
|
|
10
|
-
import { hideBin } from 'yargs/helpers';
|
|
11
|
-
import { McpResponse } from './McpResponse.js';
|
|
12
|
-
import { McpContext } from './McpContext.js';
|
|
13
|
-
import { logger, saveLogsToFile } from './logger.js';
|
|
11
|
+
import { SetLevelRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
14
12
|
import { resolveBrowser } from './browser.js';
|
|
15
|
-
import
|
|
13
|
+
import { parseArguments } from './cli.js';
|
|
14
|
+
import { logger, saveLogsToFile } from './logger.js';
|
|
15
|
+
import { McpContext } from './McpContext.js';
|
|
16
|
+
import { McpResponse } from './McpResponse.js';
|
|
17
|
+
import { Mutex } from './Mutex.js';
|
|
16
18
|
import * as consoleTools from './tools/console.js';
|
|
19
|
+
import * as emulationTools from './tools/emulation.js';
|
|
17
20
|
import * as inputTools from './tools/input.js';
|
|
18
21
|
import * as networkTools from './tools/network.js';
|
|
19
22
|
import * as pagesTools from './tools/pages.js';
|
|
@@ -21,55 +24,6 @@ import * as performanceTools from './tools/performance.js';
|
|
|
21
24
|
import * as screenshotTools from './tools/screenshot.js';
|
|
22
25
|
import * as scriptTools from './tools/script.js';
|
|
23
26
|
import * as snapshotTools from './tools/snapshot.js';
|
|
24
|
-
import path from 'node:path';
|
|
25
|
-
import fs from 'node:fs';
|
|
26
|
-
import assert from 'node:assert';
|
|
27
|
-
import { Mutex } from './Mutex.js';
|
|
28
|
-
export const cliOptions = {
|
|
29
|
-
browserUrl: {
|
|
30
|
-
type: 'string',
|
|
31
|
-
description: 'Connect to a running Chrome instance using port forwarding. For more details see: https://developer.chrome.com/docs/devtools/remote-debugging/local-server.',
|
|
32
|
-
alias: 'u',
|
|
33
|
-
coerce: (url) => {
|
|
34
|
-
new URL(url);
|
|
35
|
-
return url;
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
headless: {
|
|
39
|
-
type: 'boolean',
|
|
40
|
-
description: 'Whether to run in headless (no UI) mode.',
|
|
41
|
-
default: false,
|
|
42
|
-
},
|
|
43
|
-
executablePath: {
|
|
44
|
-
type: 'string',
|
|
45
|
-
description: 'Path to custom Chrome executable.',
|
|
46
|
-
conflicts: 'browserUrl',
|
|
47
|
-
alias: 'e',
|
|
48
|
-
},
|
|
49
|
-
isolated: {
|
|
50
|
-
type: 'boolean',
|
|
51
|
-
description: 'If specified, creates a temporary user-data-dir that is automatically cleaned up after the browser is closed.',
|
|
52
|
-
default: false,
|
|
53
|
-
},
|
|
54
|
-
customDevtools: {
|
|
55
|
-
type: 'string',
|
|
56
|
-
description: 'Path to custom DevTools.',
|
|
57
|
-
hidden: true,
|
|
58
|
-
conflicts: 'browserUrl',
|
|
59
|
-
alias: 'd',
|
|
60
|
-
},
|
|
61
|
-
channel: {
|
|
62
|
-
type: 'string',
|
|
63
|
-
description: 'Specify a different Chrome channel that should be used. The default is the stable channel version.',
|
|
64
|
-
choices: ['stable', 'canary', 'beta', 'dev'],
|
|
65
|
-
conflicts: ['browserUrl', 'executablePath'],
|
|
66
|
-
},
|
|
67
|
-
logFile: {
|
|
68
|
-
type: 'string',
|
|
69
|
-
describe: 'Save the logs to file.',
|
|
70
|
-
hidden: true,
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
27
|
function readPackageJson() {
|
|
74
28
|
const currentDir = import.meta.dirname;
|
|
75
29
|
const packageJsonPath = path.join(currentDir, '..', '..', 'package.json');
|
|
@@ -86,34 +40,7 @@ function readPackageJson() {
|
|
|
86
40
|
}
|
|
87
41
|
}
|
|
88
42
|
const version = readPackageJson().version ?? 'unknown';
|
|
89
|
-
const
|
|
90
|
-
.scriptName('npx chrome-devtools-mcp@latest')
|
|
91
|
-
.options(cliOptions)
|
|
92
|
-
.check(args => {
|
|
93
|
-
// We can't set default in the options else
|
|
94
|
-
// Yargs will complain
|
|
95
|
-
if (!args.channel && !args.browserUrl) {
|
|
96
|
-
args.channel = 'stable';
|
|
97
|
-
}
|
|
98
|
-
return true;
|
|
99
|
-
})
|
|
100
|
-
.example([
|
|
101
|
-
[
|
|
102
|
-
'$0 --browserUrl http://127.0.0.1:9222',
|
|
103
|
-
'Connect to an existing browser instance',
|
|
104
|
-
],
|
|
105
|
-
['$0 --channel beta', 'Use Chrome Beta installed on this system'],
|
|
106
|
-
['$0 --channel canary', 'Use Chrome Canary installed on this system'],
|
|
107
|
-
['$0 --channel dev', 'Use Chrome Dev installed on this system'],
|
|
108
|
-
['$0 --channel stable', 'Use stable Chrome installed on this system'],
|
|
109
|
-
['$0 --logFile /tmp/log.txt', 'Save logs to a file'],
|
|
110
|
-
['$0 --help', 'Print CLI options'],
|
|
111
|
-
]);
|
|
112
|
-
export const args = yargsInstance
|
|
113
|
-
.wrap(Math.min(120, yargsInstance.terminalWidth()))
|
|
114
|
-
.help()
|
|
115
|
-
.version(version)
|
|
116
|
-
.parseSync();
|
|
43
|
+
export const args = parseArguments(version);
|
|
117
44
|
const logFile = args.logFile ? saveLogsToFile(args.logFile) : undefined;
|
|
118
45
|
logger(`Starting Chrome DevTools MCP Server v${version}`);
|
|
119
46
|
const server = new McpServer({
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import z from 'zod';
|
|
7
|
-
import { defineTool } from './ToolDefinition.js';
|
|
8
6
|
import { PredefinedNetworkConditions } from 'puppeteer-core';
|
|
7
|
+
import z from 'zod';
|
|
9
8
|
import { ToolCategories } from './categories.js';
|
|
9
|
+
import { defineTool } from './ToolDefinition.js';
|
|
10
10
|
const throttlingOptions = [
|
|
11
11
|
'No emulation',
|
|
12
12
|
...Object.keys(PredefinedNetworkConditions),
|
package/build/src/tools/input.js
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import z from 'zod';
|
|
7
|
-
import { defineTool } from './ToolDefinition.js';
|
|
8
7
|
import { ToolCategories } from './categories.js';
|
|
8
|
+
import { defineTool } from './ToolDefinition.js';
|
|
9
9
|
export const click = defineTool({
|
|
10
10
|
name: 'click',
|
|
11
11
|
description: `Clicks on the provided element`,
|
|
@@ -37,7 +37,7 @@ export const click = defineTool({
|
|
|
37
37
|
response.setIncludeSnapshot(true);
|
|
38
38
|
}
|
|
39
39
|
finally {
|
|
40
|
-
handle.dispose();
|
|
40
|
+
void handle.dispose();
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
43
|
});
|
|
@@ -64,7 +64,7 @@ export const hover = defineTool({
|
|
|
64
64
|
response.setIncludeSnapshot(true);
|
|
65
65
|
}
|
|
66
66
|
finally {
|
|
67
|
-
handle.dispose();
|
|
67
|
+
void handle.dispose();
|
|
68
68
|
}
|
|
69
69
|
},
|
|
70
70
|
});
|
|
@@ -91,7 +91,7 @@ export const fill = defineTool({
|
|
|
91
91
|
response.setIncludeSnapshot(true);
|
|
92
92
|
}
|
|
93
93
|
finally {
|
|
94
|
-
handle.dispose();
|
|
94
|
+
void handle.dispose();
|
|
95
95
|
}
|
|
96
96
|
},
|
|
97
97
|
});
|
|
@@ -119,8 +119,8 @@ export const drag = defineTool({
|
|
|
119
119
|
response.setIncludeSnapshot(true);
|
|
120
120
|
}
|
|
121
121
|
finally {
|
|
122
|
-
fromHandle.dispose();
|
|
123
|
-
toHandle.dispose();
|
|
122
|
+
void fromHandle.dispose();
|
|
123
|
+
void toHandle.dispose();
|
|
124
124
|
}
|
|
125
125
|
},
|
|
126
126
|
});
|
|
@@ -148,7 +148,7 @@ export const fillForm = defineTool({
|
|
|
148
148
|
});
|
|
149
149
|
}
|
|
150
150
|
finally {
|
|
151
|
-
handle.dispose();
|
|
151
|
+
void handle.dispose();
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
154
|
response.appendResponseLine(`Successfully filled out the form`);
|
|
@@ -195,7 +195,7 @@ export const uploadFile = defineTool({
|
|
|
195
195
|
response.appendResponseLine(`File uploaded from ${filePath}.`);
|
|
196
196
|
}
|
|
197
197
|
finally {
|
|
198
|
-
handle.dispose();
|
|
198
|
+
void handle.dispose();
|
|
199
199
|
}
|
|
200
200
|
},
|
|
201
201
|
});
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import z from 'zod';
|
|
7
|
-
import { defineTool } from './ToolDefinition.js';
|
|
8
7
|
import { ToolCategories } from './categories.js';
|
|
8
|
+
import { defineTool } from './ToolDefinition.js';
|
|
9
9
|
export const listNetworkRequests = defineTool({
|
|
10
10
|
name: 'list_network_requests',
|
|
11
11
|
description: `List all requests for the currently selected page`,
|
|
@@ -13,9 +13,25 @@ export const listNetworkRequests = defineTool({
|
|
|
13
13
|
category: ToolCategories.NETWORK,
|
|
14
14
|
readOnlyHint: true,
|
|
15
15
|
},
|
|
16
|
-
schema: {
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
schema: {
|
|
17
|
+
pageSize: z
|
|
18
|
+
.number()
|
|
19
|
+
.int()
|
|
20
|
+
.positive()
|
|
21
|
+
.optional()
|
|
22
|
+
.describe('Maximum number of requests to return. When omitted, returns all requests.'),
|
|
23
|
+
pageIdx: z
|
|
24
|
+
.number()
|
|
25
|
+
.int()
|
|
26
|
+
.min(0)
|
|
27
|
+
.optional()
|
|
28
|
+
.describe('Page number to return (0-based). When omitted, returns the first page.'),
|
|
29
|
+
},
|
|
30
|
+
handler: async (request, response) => {
|
|
31
|
+
response.setIncludeNetworkRequests(true, {
|
|
32
|
+
pageSize: request.params.pageSize,
|
|
33
|
+
pageIdx: request.params.pageIdx,
|
|
34
|
+
});
|
|
19
35
|
},
|
|
20
36
|
});
|
|
21
37
|
export const getNetworkRequest = defineTool({
|
package/build/src/tools/pages.js
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import z from 'zod';
|
|
7
|
-
import { defineTool } from './ToolDefinition.js';
|
|
8
7
|
import { ToolCategories } from './categories.js';
|
|
8
|
+
import { CLOSE_PAGE_ERROR, defineTool } from './ToolDefinition.js';
|
|
9
9
|
export const listPages = defineTool({
|
|
10
10
|
name: 'list_pages',
|
|
11
11
|
description: `Get a list of pages open in the browser.`,
|
|
@@ -50,7 +50,17 @@ export const closePage = defineTool({
|
|
|
50
50
|
.describe('The index of the page to close. Call list_pages to list pages.'),
|
|
51
51
|
},
|
|
52
52
|
handler: async (request, response, context) => {
|
|
53
|
-
|
|
53
|
+
try {
|
|
54
|
+
await context.closePage(request.params.pageIdx);
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
if (err.message === CLOSE_PAGE_ERROR) {
|
|
58
|
+
response.appendResponseLine(err.message);
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
throw err;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
54
64
|
response.setIncludePages(true);
|
|
55
65
|
},
|
|
56
66
|
});
|
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import z from 'zod';
|
|
7
|
-
import { defineTool } from './ToolDefinition.js';
|
|
8
|
-
import { getInsightOutput, getTraceSummary, parseRawTraceBuffer, traceResultIsSuccess, } from '../trace-processing/parse.js';
|
|
9
7
|
import { logger } from '../logger.js';
|
|
8
|
+
import { getInsightOutput, getTraceSummary, parseRawTraceBuffer, traceResultIsSuccess, } from '../trace-processing/parse.js';
|
|
10
9
|
import { ToolCategories } from './categories.js';
|
|
10
|
+
import { defineTool } from './ToolDefinition.js';
|
|
11
11
|
export const startTrace = defineTool({
|
|
12
12
|
name: 'performance_start_trace',
|
|
13
13
|
description: 'Starts a performance trace recording on the selected page.',
|
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
6
|
import z from 'zod';
|
|
7
|
-
import { defineTool } from './ToolDefinition.js';
|
|
8
7
|
import { ToolCategories } from './categories.js';
|
|
8
|
+
import { defineTool } from './ToolDefinition.js';
|
|
9
9
|
export const screenshot = defineTool({
|
|
10
10
|
name: 'take_screenshot',
|
|
11
11
|
description: `Take a screenshot of the page or element.`,
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2025 Google LLC
|
|
4
|
-
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
-
*/
|
|
6
1
|
import z from 'zod';
|
|
7
|
-
import { defineTool } from './ToolDefinition.js';
|
|
8
2
|
import { ToolCategories } from './categories.js';
|
|
3
|
+
import { defineTool } from './ToolDefinition.js';
|
|
9
4
|
export const evaluateScript = defineTool({
|
|
10
5
|
name: 'evaluate_script',
|
|
11
6
|
description: `Evaluate a JavaScript function inside the currently selected page. Returns the response as JSON
|
|
@@ -54,7 +49,9 @@ Example with arguments: \`(el) => {
|
|
|
54
49
|
});
|
|
55
50
|
}
|
|
56
51
|
finally {
|
|
57
|
-
Promise.allSettled(args.map(arg => arg.dispose())).catch(() => {
|
|
52
|
+
Promise.allSettled(args.map(arg => arg.dispose())).catch(() => {
|
|
53
|
+
// Ignore errors
|
|
54
|
+
});
|
|
58
55
|
}
|
|
59
56
|
},
|
|
60
57
|
});
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import z from 'zod';
|
|
7
|
-
import { defineTool } from './ToolDefinition.js';
|
|
8
6
|
import { Locator } from 'puppeteer-core';
|
|
7
|
+
import z from 'zod';
|
|
9
8
|
import { ToolCategories } from './categories.js';
|
|
9
|
+
import { defineTool } from './ToolDefinition.js';
|
|
10
10
|
export const takeSnapshot = defineTool({
|
|
11
11
|
name: 'take_snapshot',
|
|
12
12
|
description: `Take a text snapshot of the currently selected page. The snapshot lists page elements along with a unique
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
* Copyright 2025 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import { PerformanceTraceFormatter } from '../../node_modules/chrome-devtools-frontend/front_end/models/ai_assistance/data_formatters/PerformanceTraceFormatter.js';
|
|
7
6
|
import { PerformanceInsightFormatter } from '../../node_modules/chrome-devtools-frontend/front_end/models/ai_assistance/data_formatters/PerformanceInsightFormatter.js';
|
|
7
|
+
import { PerformanceTraceFormatter } from '../../node_modules/chrome-devtools-frontend/front_end/models/ai_assistance/data_formatters/PerformanceTraceFormatter.js';
|
|
8
|
+
import { AgentFocus } from '../../node_modules/chrome-devtools-frontend/front_end/models/ai_assistance/performance/AIContext.js';
|
|
8
9
|
import * as TraceEngine from '../../node_modules/chrome-devtools-frontend/front_end/models/trace/trace.js';
|
|
9
10
|
import { logger } from '../logger.js';
|
|
10
|
-
import { AgentFocus } from '../../node_modules/chrome-devtools-frontend/front_end/models/ai_assistance/performance/AIContext.js';
|
|
11
11
|
const engine = TraceEngine.TraceModel.Model.createWithAllHandlers();
|
|
12
12
|
export function traceResultIsSuccess(x) {
|
|
13
13
|
return 'parsedTrace' in x;
|
|
@@ -50,9 +50,8 @@ export async function parseRawTraceBuffer(buffer) {
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
export function getTraceSummary(result) {
|
|
53
|
-
const focus = AgentFocus.
|
|
54
|
-
const
|
|
55
|
-
const formatter = new PerformanceTraceFormatter(focus, serializer);
|
|
53
|
+
const focus = AgentFocus.fromParsedTrace(result.parsedTrace);
|
|
54
|
+
const formatter = new PerformanceTraceFormatter(focus, PerformanceInsightFormatter.create);
|
|
56
55
|
const output = formatter.formatTraceSummary();
|
|
57
56
|
return output;
|
|
58
57
|
}
|
|
@@ -81,6 +80,6 @@ export function getInsightOutput(result, insightName) {
|
|
|
81
80
|
error: `No Insight with the name ${insightName} found. Double check the name you provided is accurate and try again.`,
|
|
82
81
|
};
|
|
83
82
|
}
|
|
84
|
-
const formatter = new PerformanceInsightFormatter(result.parsedTrace, matchingInsight);
|
|
83
|
+
const formatter = new PerformanceInsightFormatter(AgentFocus.fromParsedTrace(result.parsedTrace), matchingInsight);
|
|
85
84
|
return { output: formatter.formatInsight() };
|
|
86
85
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
const DEFAULT_PAGE_SIZE = 20;
|
|
7
|
+
export function paginate(items, options) {
|
|
8
|
+
const total = items.length;
|
|
9
|
+
if (!options || noPaginationOptions(options)) {
|
|
10
|
+
return {
|
|
11
|
+
items,
|
|
12
|
+
currentPage: 0,
|
|
13
|
+
totalPages: 1,
|
|
14
|
+
hasNextPage: false,
|
|
15
|
+
hasPreviousPage: false,
|
|
16
|
+
startIndex: 0,
|
|
17
|
+
endIndex: total,
|
|
18
|
+
invalidPage: false,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const pageSize = options.pageSize ?? DEFAULT_PAGE_SIZE;
|
|
22
|
+
const totalPages = Math.max(1, Math.ceil(total / pageSize));
|
|
23
|
+
const { currentPage, invalidPage } = resolvePageIndex(options.pageIdx, totalPages);
|
|
24
|
+
const startIndex = currentPage * pageSize;
|
|
25
|
+
const pageItems = items.slice(startIndex, startIndex + pageSize);
|
|
26
|
+
const endIndex = startIndex + pageItems.length;
|
|
27
|
+
return {
|
|
28
|
+
items: pageItems,
|
|
29
|
+
currentPage,
|
|
30
|
+
totalPages,
|
|
31
|
+
hasNextPage: currentPage < totalPages - 1,
|
|
32
|
+
hasPreviousPage: currentPage > 0,
|
|
33
|
+
startIndex,
|
|
34
|
+
endIndex,
|
|
35
|
+
invalidPage,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function noPaginationOptions(options) {
|
|
39
|
+
return options.pageSize === undefined && options.pageIdx === undefined;
|
|
40
|
+
}
|
|
41
|
+
function resolvePageIndex(pageIdx, totalPages) {
|
|
42
|
+
if (pageIdx === undefined) {
|
|
43
|
+
return { currentPage: 0, invalidPage: false };
|
|
44
|
+
}
|
|
45
|
+
if (pageIdx < 0 || pageIdx >= totalPages) {
|
|
46
|
+
return { currentPage: 0, invalidPage: true };
|
|
47
|
+
}
|
|
48
|
+
return { currentPage: pageIdx, invalidPage: false };
|
|
49
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chrome-devtools-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "MCP server for Chrome DevTools",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": "./build/src/index.js",
|
|
@@ -38,11 +38,12 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@modelcontextprotocol/sdk": "1.18.1",
|
|
40
40
|
"debug": "4.4.3",
|
|
41
|
-
"puppeteer-core": "24.22.
|
|
41
|
+
"puppeteer-core": "24.22.3",
|
|
42
42
|
"yargs": "18.0.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@eslint/js": "^9.35.0",
|
|
46
|
+
"@stylistic/eslint-plugin": "^5.4.0",
|
|
46
47
|
"@types/debug": "^4.1.12",
|
|
47
48
|
"@types/filesystem": "^0.0.36",
|
|
48
49
|
"@types/node": "^24.3.3",
|
|
@@ -50,14 +51,16 @@
|
|
|
50
51
|
"@types/yargs": "^17.0.33",
|
|
51
52
|
"@typescript-eslint/eslint-plugin": "^8.43.0",
|
|
52
53
|
"@typescript-eslint/parser": "^8.43.0",
|
|
53
|
-
"chrome-devtools-frontend": "1.0.
|
|
54
|
+
"chrome-devtools-frontend": "1.0.1520139",
|
|
54
55
|
"eslint": "^9.35.0",
|
|
56
|
+
"eslint-plugin-import": "^2.32.0",
|
|
57
|
+
"eslint-import-resolver-typescript": "^4.4.4",
|
|
55
58
|
"globals": "^16.4.0",
|
|
56
59
|
"prettier": "^3.6.2",
|
|
57
|
-
"puppeteer": "24.22.
|
|
60
|
+
"puppeteer": "24.22.3",
|
|
58
61
|
"sinon": "^21.0.0",
|
|
59
|
-
"typescript": "^
|
|
60
|
-
"typescript
|
|
62
|
+
"typescript-eslint": "^8.43.0",
|
|
63
|
+
"typescript": "^5.9.2"
|
|
61
64
|
},
|
|
62
65
|
"engines": {
|
|
63
66
|
"node": ">=22.12.0"
|