chrome-devtools-mcp 1.8.0 → 1.10.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 +20 -908
- package/build/src/BrowserManager.js +401 -0
- package/build/src/McpContext.js +43 -26
- package/build/src/McpPage.js +112 -4
- package/build/src/McpResponse.js +68 -3
- package/build/src/ToolHandler.js +184 -160
- package/build/src/bin/chrome-devtools-mcp-main.js +12 -7
- package/build/src/bin/chrome-devtools.js +6 -12
- package/build/src/collectors/PageCollector.js +66 -3
- package/build/src/config/browser-options.js +125 -0
- package/build/src/config/category-options.js +89 -0
- package/build/src/config/cli-commands.js +26 -0
- package/build/src/config/cli-options.js +34 -2
- package/build/src/config/mcp-options.js +86 -147
- package/build/src/daemon/utils.js +6 -0
- package/build/src/devtools/DevToolsCommentBridge.js +91 -0
- package/build/src/devtools/DevtoolsUtils.js +27 -21
- package/build/src/formatters/CommentFormatter.js +82 -0
- package/build/src/formatters/CssFormatter.js +812 -0
- package/build/src/formatters/NetworkFormatter.js +5 -2
- package/build/src/index.js +175 -128
- package/build/src/processors/ChunkedTraceParser.js +361 -0
- package/build/src/processors/PerformanceTrace.js +60 -13
- package/build/src/telemetry/ClearcutLogger.js +95 -37
- package/build/src/telemetry/metricsRegistry.js +3 -0
- package/build/src/telemetry/persistence.js +17 -7
- package/build/src/telemetry/transformation.js +53 -4
- package/build/src/telemetry/types.js +1 -0
- package/build/src/third_party/THIRD_PARTY_NOTICES +687 -133
- package/build/src/third_party/bundled-packages.json +6 -3
- package/build/src/third_party/devtools-formatter-worker.js +158 -5
- package/build/src/third_party/devtools-heap-snapshot-worker.js +589 -6
- package/build/src/third_party/index.js +59173 -38013
- package/build/src/third_party/issue-descriptions/webInstallManifestMissingId.md +3 -0
- package/build/src/third_party/issue-descriptions/webInstallManifestMissingNameOrShortName.md +3 -0
- package/build/src/third_party/issue-descriptions/webInstallManifestParsingOrNetworkError.md +3 -0
- package/build/src/third_party/issue-descriptions/webInstallNoManifest.md +3 -0
- package/build/src/third_party/issue-descriptions/webInstallStartUrlInvalid.md +3 -0
- package/build/src/tools/ToolDefinition.js +28 -21
- package/build/src/tools/categories.js +0 -6
- package/build/src/tools/comments.js +169 -0
- package/build/src/tools/console.js +3 -3
- package/build/src/tools/css.js +45 -0
- package/build/src/tools/emulation.js +5 -5
- package/build/src/tools/extensions.js +10 -10
- package/build/src/tools/input.js +159 -87
- package/build/src/tools/lighthouse.js +18 -7
- package/build/src/tools/memory.js +26 -26
- package/build/src/tools/network.js +5 -5
- package/build/src/tools/pages.js +34 -19
- package/build/src/tools/performance.js +7 -6
- package/build/src/tools/pwa.js +8 -8
- package/build/src/tools/screencast.js +5 -4
- package/build/src/tools/screenshot.js +2 -2
- package/build/src/tools/script.js +8 -7
- package/build/src/tools/slim/tools.js +45 -37
- package/build/src/tools/snapshot.js +4 -4
- package/build/src/tools/thirdPartyDeveloper.js +4 -4
- package/build/src/tools/tools.js +6 -9
- package/build/src/tools/webmcp.js +4 -4
- package/build/src/types.js +4 -1
- package/build/src/utils/WaitForHelper.js +26 -9
- package/build/src/utils/logger.js +7 -6
- package/build/src/utils/url.js +73 -0
- package/build/src/version.js +1 -1
- package/package.json +9 -6
- package/skills/chrome-devtools/SKILL.md +2 -1
- package/skills/chrome-devtools-cli/SKILL.md +3 -7
- package/skills/cookie-debugging/SKILL.md +149 -0
- package/skills/memory-leak-debugging/SKILL.md +4 -0
- package/build/src/browser.js +0 -244
- package/build/src/third_party/issue-descriptions/cookieExcludeBlockedWithinRelatedWebsiteSet.md +0 -4
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
import { isUtf8 } from 'node:buffer';
|
|
7
7
|
import { DevTools, } from '../third_party/index.js';
|
|
8
8
|
const BODY_CONTEXT_SIZE_LIMIT = 10000;
|
|
9
|
+
const URL_CONTEXT_SIZE_LIMIT = 255;
|
|
9
10
|
export class NetworkFormatter {
|
|
10
11
|
#request;
|
|
11
12
|
#options;
|
|
@@ -178,8 +179,10 @@ function getSizeLimitedString(text, sizeLimit) {
|
|
|
178
179
|
return text;
|
|
179
180
|
}
|
|
180
181
|
function convertNetworkRequestConciseToString(data) {
|
|
181
|
-
//
|
|
182
|
-
|
|
182
|
+
// Long URLs (e.g., data: URLs) bloat the concise list output. The full URL
|
|
183
|
+
// remains available via the detailed view and the structured content.
|
|
184
|
+
const url = getSizeLimitedString(data.url, URL_CONTEXT_SIZE_LIMIT);
|
|
185
|
+
return `reqid=${data.requestId} ${data.method} ${url} [${data.status}]${data.selectedInDevToolsUI ? ` [selected in the DevTools Network panel]` : ''}`;
|
|
183
186
|
}
|
|
184
187
|
function formatHeaders(headers) {
|
|
185
188
|
const response = [];
|
package/build/src/index.js
CHANGED
|
@@ -3,18 +3,18 @@
|
|
|
3
3
|
* Copyright 2026 Google LLC
|
|
4
4
|
* SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
*/
|
|
6
|
-
import
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { pathToFileURL } from 'node:url';
|
|
8
|
+
import { BrowserManager } from './BrowserManager.js';
|
|
7
9
|
import { loadIssueDescriptions } from './devtools/issueDescriptions.js';
|
|
8
10
|
import { McpContext } from './McpContext.js';
|
|
9
11
|
import { ClearcutLogger } from './telemetry/ClearcutLogger.js';
|
|
10
12
|
import { FilePersistence } from './telemetry/persistence.js';
|
|
11
|
-
import { McpServer
|
|
13
|
+
import { McpServer as SdkMcpServer, Mutex, puppeteer, } from './third_party/index.js';
|
|
12
14
|
import { ToolHandler } from './ToolHandler.js';
|
|
13
15
|
import { createTools } from './tools/tools.js';
|
|
14
16
|
import { logger } from './utils/logger.js';
|
|
15
|
-
import { Mutex, puppeteer } from './third_party/index.js';
|
|
16
17
|
import { VERSION } from './version.js';
|
|
17
|
-
export { buildFlag } from './ToolHandler.js';
|
|
18
18
|
puppeteer.setFollowSymlinks(false);
|
|
19
19
|
/**
|
|
20
20
|
* Timeout for a `roots/list` that a tool call is waiting on, matching the 5s
|
|
@@ -25,154 +25,201 @@ puppeteer.setFollowSymlinks(false);
|
|
|
25
25
|
* slow client sends late still land.
|
|
26
26
|
*/
|
|
27
27
|
const ROOTS_REQUEST_TIMEOUT = 5_000;
|
|
28
|
-
export
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
28
|
+
export class McpServer {
|
|
29
|
+
server;
|
|
30
|
+
#serverArgs;
|
|
31
|
+
#browserManager;
|
|
32
|
+
#context;
|
|
33
|
+
/**
|
|
34
|
+
* Client roots stay valid across browser reconnects and only the client can
|
|
35
|
+
* invalidate them through a `roots/list_changed` notification. CLI-configured
|
|
36
|
+
* roots are read from `#serverArgs` when combining roots.
|
|
37
|
+
*/
|
|
38
|
+
#lastClientRoots;
|
|
39
|
+
#toolMutex = new Mutex();
|
|
40
|
+
constructor(serverArgs, options) {
|
|
41
|
+
this.#serverArgs = serverArgs;
|
|
42
|
+
this.#browserManager = options.browserManager;
|
|
43
|
+
if (this.#serverArgs.usageStatistics) {
|
|
44
|
+
ClearcutLogger.initialize({
|
|
45
|
+
persistence: new FilePersistence(),
|
|
46
|
+
logFile: this.#serverArgs.logFile,
|
|
47
|
+
appVersion: VERSION,
|
|
48
|
+
clearcutEndpoint: this.#serverArgs.clearcutEndpoint,
|
|
49
|
+
clearcutForceFlushIntervalMs: this.#serverArgs.clearcutForceFlushIntervalMs,
|
|
50
|
+
clearcutIncludePidHeader: this.#serverArgs.clearcutIncludePidHeader,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
this.server = new SdkMcpServer({
|
|
54
|
+
name: 'chrome_devtools',
|
|
55
|
+
title: 'Chrome DevTools MCP server',
|
|
56
|
+
version: VERSION,
|
|
57
|
+
}, { capabilities: { logging: {} } });
|
|
58
|
+
this.server.server.setRequestHandler('logging/setLevel', () => {
|
|
59
|
+
return {};
|
|
37
60
|
});
|
|
61
|
+
this.server.server.oninitialized = () => {
|
|
62
|
+
const clientName = this.server.server.getClientVersion()?.name;
|
|
63
|
+
if (clientName) {
|
|
64
|
+
ClearcutLogger.get()?.setClientName(clientName);
|
|
65
|
+
}
|
|
66
|
+
if (this.server.server.getClientCapabilities()?.roots) {
|
|
67
|
+
void this.#updateRoots();
|
|
68
|
+
this.server.server.setNotificationHandler('notifications/roots/list_changed', () => {
|
|
69
|
+
void this.#updateRoots();
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
else if (!this.#serverArgs.allowUnrestrictedPaths &&
|
|
73
|
+
(this.#serverArgs.filesystemRoot ?? []).length === 0) {
|
|
74
|
+
console.warn('[chrome-devtools-mcp] The connecting client did not negotiate the MCP roots ' +
|
|
75
|
+
'capability. File-writing tools will be restricted to the OS temp directory. ' +
|
|
76
|
+
'To restore the previous unrestricted behavior, start the server with ' +
|
|
77
|
+
'--allow-unrestricted-paths.');
|
|
78
|
+
}
|
|
79
|
+
};
|
|
38
80
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
});
|
|
47
|
-
// Roots are client state rather than browser state, so the last listing stays
|
|
48
|
-
// valid across browser reconnects and only the client can invalidate it, via
|
|
49
|
-
// the `roots/list_changed` notification handled below
|
|
50
|
-
let lastRoots;
|
|
51
|
-
// `timeout` is only passed where a tool call is waiting on the result – the
|
|
52
|
-
// background refreshes below block nobody, so bounding them would just discard
|
|
53
|
-
// roots a slow client was about to send
|
|
54
|
-
const updateRoots = async (timeout) => {
|
|
55
|
-
if (!server.server.getClientCapabilities()?.roots) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
81
|
+
async connect(transport) {
|
|
82
|
+
return await this.server.connect(transport);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Closes the MCP connection and disposes internal context/listeners.
|
|
86
|
+
*/
|
|
87
|
+
async close() {
|
|
58
88
|
try {
|
|
59
|
-
|
|
60
|
-
lastRoots = roots.roots;
|
|
61
|
-
context?.setRoots(lastRoots);
|
|
89
|
+
this.#context?.dispose();
|
|
62
90
|
}
|
|
63
|
-
catch (
|
|
64
|
-
logger?.('Failed to
|
|
91
|
+
catch (err) {
|
|
92
|
+
logger?.('Failed to dispose context', err);
|
|
65
93
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const clientName = server.server.getClientVersion()?.name;
|
|
69
|
-
if (clientName) {
|
|
70
|
-
ClearcutLogger.get()?.setClientName(clientName);
|
|
94
|
+
finally {
|
|
95
|
+
this.#context = undefined;
|
|
71
96
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
97
|
+
await Promise.allSettled([
|
|
98
|
+
this.#browserManager.close(),
|
|
99
|
+
this.server.close(),
|
|
100
|
+
]);
|
|
101
|
+
}
|
|
102
|
+
[Symbol.dispose]() {
|
|
103
|
+
this.close().catch(err => {
|
|
104
|
+
logger?.('Failed to dispose McpServer', err);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
async [Symbol.asyncDispose]() {
|
|
108
|
+
await this.close();
|
|
109
|
+
}
|
|
110
|
+
static async from(serverArgs, options) {
|
|
111
|
+
const server = new McpServer(serverArgs, options);
|
|
112
|
+
await server.#init();
|
|
113
|
+
return server;
|
|
114
|
+
}
|
|
115
|
+
async #init() {
|
|
116
|
+
const tools = createTools(this.#serverArgs);
|
|
117
|
+
for (const tool of tools) {
|
|
118
|
+
this.#registerTool(tool);
|
|
119
|
+
}
|
|
120
|
+
await loadIssueDescriptions();
|
|
121
|
+
}
|
|
122
|
+
#combinedRoots() {
|
|
123
|
+
const configuredRoots = (this.#serverArgs.allowUnrestrictedPaths
|
|
124
|
+
? []
|
|
125
|
+
: (this.#serverArgs.filesystemRoot ?? [])).map(root => {
|
|
126
|
+
const rootPath = path.resolve(root);
|
|
127
|
+
return {
|
|
128
|
+
uri: pathToFileURL(rootPath).href,
|
|
129
|
+
name: path.basename(rootPath) || rootPath,
|
|
130
|
+
};
|
|
131
|
+
});
|
|
132
|
+
if (configuredRoots.length === 0 && this.#lastClientRoots === undefined) {
|
|
133
|
+
return undefined;
|
|
77
134
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
135
|
+
return [...configuredRoots, ...(this.#lastClientRoots ?? [])];
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* `timeout` is only passed where a tool call is waiting on the result – the
|
|
139
|
+
* background refreshes below block nobody, so bounding them would just discard
|
|
140
|
+
* roots a slow client was about to send
|
|
141
|
+
*/
|
|
142
|
+
async #updateRoots(timeout) {
|
|
143
|
+
if (!this.server.server.getClientCapabilities()?.roots) {
|
|
144
|
+
return;
|
|
83
145
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const ignoreDefaultChromeArgs = (serverArgs.ignoreDefaultChromeArg ?? []).map(String);
|
|
89
|
-
if (serverArgs.proxyServer) {
|
|
90
|
-
chromeArgs.push(`--proxy-server=${serverArgs.proxyServer}`);
|
|
146
|
+
try {
|
|
147
|
+
const result = await this.server.server.request({ method: 'roots/list' }, timeout === undefined ? undefined : { timeout });
|
|
148
|
+
this.#lastClientRoots = result.roots;
|
|
149
|
+
this.#context?.setRoots(this.#combinedRoots());
|
|
91
150
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
userDataDir: serverArgs.userDataDir,
|
|
109
|
-
devtools,
|
|
110
|
-
blocklist,
|
|
111
|
-
allowlist,
|
|
112
|
-
})
|
|
113
|
-
: await ensureBrowserLaunched({
|
|
114
|
-
headless: serverArgs.headless,
|
|
115
|
-
executablePath: serverArgs.executablePath,
|
|
116
|
-
channel: serverArgs.channel,
|
|
117
|
-
isolated: serverArgs.isolated ?? false,
|
|
118
|
-
userDataDir: serverArgs.userDataDir,
|
|
119
|
-
logFile: options.logFile,
|
|
120
|
-
viewport: serverArgs.viewport,
|
|
121
|
-
chromeArgs,
|
|
122
|
-
ignoreDefaultChromeArgs,
|
|
123
|
-
acceptInsecureCerts: serverArgs.acceptInsecureCerts,
|
|
124
|
-
devtools,
|
|
125
|
-
enableExtensions: serverArgs.categoryExtensions,
|
|
126
|
-
viaCli: serverArgs.viaCli,
|
|
127
|
-
blocklist,
|
|
128
|
-
allowlist,
|
|
129
|
-
});
|
|
130
|
-
if (context?.browser !== browser) {
|
|
131
|
-
context?.dispose();
|
|
132
|
-
context = await McpContext.from(browser, logger, {
|
|
133
|
-
experimentalDevToolsDebugging: devtools,
|
|
134
|
-
experimentalIncludeAllPages: serverArgs.experimentalIncludeAllPages,
|
|
135
|
-
performanceCrux: serverArgs.performanceCrux,
|
|
136
|
-
allowList: allowlist,
|
|
137
|
-
blocklist: blocklist,
|
|
138
|
-
allowUnrestrictedPaths: serverArgs.allowUnrestrictedPaths,
|
|
151
|
+
catch (e) {
|
|
152
|
+
logger?.('Failed to list roots', e);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
async #getContext() {
|
|
156
|
+
const browser = await this.#browserManager.ensureBrowser();
|
|
157
|
+
if (this.#context?.browser !== browser) {
|
|
158
|
+
this.#context?.dispose();
|
|
159
|
+
this.#context = await McpContext.from(browser, logger, {
|
|
160
|
+
experimentalDevToolsDebugging: this.#serverArgs.experimentalDevtools ?? false,
|
|
161
|
+
experimentalIncludeAllPages: this.#serverArgs.experimentalIncludeAllPages,
|
|
162
|
+
performanceCrux: this.#serverArgs.performanceCrux,
|
|
163
|
+
sourceMaps: this.#serverArgs.sourceMaps,
|
|
164
|
+
allowlist: this.#serverArgs.allowedUrlPattern,
|
|
165
|
+
blocklist: this.#serverArgs.blockedUrlPattern,
|
|
166
|
+
allowUnrestrictedPaths: this.#serverArgs.allowUnrestrictedPaths,
|
|
139
167
|
// Surfaces a one-time note in the next response after a reconnect.
|
|
140
|
-
reconnected: context !== undefined,
|
|
168
|
+
reconnected: this.#context !== undefined,
|
|
169
|
+
categoryExtensions: this.#serverArgs.categoryExtensions,
|
|
170
|
+
onNotification: (message) => {
|
|
171
|
+
void this.server
|
|
172
|
+
.sendLoggingMessage({
|
|
173
|
+
level: 'info',
|
|
174
|
+
data: message,
|
|
175
|
+
})
|
|
176
|
+
.catch(e => {
|
|
177
|
+
logger?.('Failed to send MCP notification', e);
|
|
178
|
+
});
|
|
179
|
+
},
|
|
141
180
|
});
|
|
142
|
-
|
|
181
|
+
this.#context.setRoots(this.#combinedRoots());
|
|
182
|
+
if (this.#lastClientRoots === undefined) {
|
|
143
183
|
// Nothing listed yet, so this call has to wait – bounded, since it is
|
|
144
184
|
// holding the tool mutex, and a later background refresh still lands
|
|
145
|
-
await updateRoots(ROOTS_REQUEST_TIMEOUT);
|
|
185
|
+
await this.#updateRoots(ROOTS_REQUEST_TIMEOUT);
|
|
146
186
|
}
|
|
147
187
|
else {
|
|
148
188
|
// Carry the known roots over and refresh out of band, so a reconnect
|
|
149
189
|
// never pays for a client round-trip
|
|
150
|
-
|
|
151
|
-
void updateRoots();
|
|
190
|
+
void this.#updateRoots();
|
|
152
191
|
}
|
|
153
192
|
}
|
|
154
|
-
return context;
|
|
193
|
+
return this.#context;
|
|
155
194
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
const
|
|
159
|
-
if (!toolHandler.shouldRegister) {
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
server.registerTool(tool.name, {
|
|
195
|
+
#registerTool(tool) {
|
|
196
|
+
const toolHandler = new ToolHandler(tool, this.#serverArgs, () => this.#getContext(), this.#toolMutex);
|
|
197
|
+
const registeredTool = this.server.registerTool(tool.name, {
|
|
163
198
|
description: tool.description,
|
|
164
199
|
inputSchema: toolHandler.registeredInputSchema,
|
|
165
200
|
annotations: tool.annotations,
|
|
166
|
-
},
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
const tools = createTools(serverArgs);
|
|
171
|
-
for (const tool of tools) {
|
|
172
|
-
registerTool(tool);
|
|
201
|
+
}, toolHandler.handle);
|
|
202
|
+
if (toolHandler.disabled) {
|
|
203
|
+
registeredTool.disable();
|
|
204
|
+
}
|
|
173
205
|
}
|
|
174
|
-
|
|
175
|
-
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Creates and initializes a Chrome DevTools MCP server instance.
|
|
209
|
+
*
|
|
210
|
+
* Maintained as a public API for backwards compatibility because external
|
|
211
|
+
* consumers and integrations rely on `createMcpServer()`. For new code,
|
|
212
|
+
* prefer using `McpServer.from(serverArgs, options)`.
|
|
213
|
+
*/
|
|
214
|
+
export async function createMcpServer(serverArgs, options) {
|
|
215
|
+
const browserManager = new BrowserManager(serverArgs, {
|
|
216
|
+
logFile: options.logFile,
|
|
217
|
+
});
|
|
218
|
+
const server = await McpServer.from(serverArgs, {
|
|
219
|
+
browserManager,
|
|
220
|
+
...options,
|
|
221
|
+
});
|
|
222
|
+
return { server: server.server };
|
|
176
223
|
}
|
|
177
224
|
export const logDisclaimers = (args) => {
|
|
178
225
|
console.error(`chrome-devtools-mcp exposes content of the browser instance to the MCP clients allowing them to inspect,
|