chrome-devtools-mcp 0.2.6 → 0.2.7
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 +1 -1
- package/build/src/index.js +6 -198
- package/build/src/main.js +204 -0
- package/package.json +4 -1
package/README.md
CHANGED
package/build/src/index.js
CHANGED
|
@@ -4,202 +4,10 @@
|
|
|
4
4
|
* Copyright 2025 Google LLC
|
|
5
5
|
* SPDX-License-Identifier: Apache-2.0
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import { hideBin } from 'yargs/helpers';
|
|
12
|
-
import { McpResponse } from './McpResponse.js';
|
|
13
|
-
import { McpContext } from './McpContext.js';
|
|
14
|
-
import { logger, saveLogsToFile } from './logger.js';
|
|
15
|
-
import { resolveBrowser } from './browser.js';
|
|
16
|
-
import * as emulationTools from './tools/emulation.js';
|
|
17
|
-
import * as consoleTools from './tools/console.js';
|
|
18
|
-
import * as inputTools from './tools/input.js';
|
|
19
|
-
import * as networkTools from './tools/network.js';
|
|
20
|
-
import * as pagesTools from './tools/pages.js';
|
|
21
|
-
import * as performanceTools from './tools/performance.js';
|
|
22
|
-
import * as screenshotTools from './tools/screenshot.js';
|
|
23
|
-
import * as scriptTools from './tools/script.js';
|
|
24
|
-
import * as snapshotTools from './tools/snapshot.js';
|
|
25
|
-
import path from 'node:path';
|
|
26
|
-
import fs from 'node:fs';
|
|
27
|
-
import assert from 'node:assert';
|
|
28
|
-
import { Mutex } from './Mutex.js';
|
|
29
|
-
export const cliOptions = {
|
|
30
|
-
browserUrl: {
|
|
31
|
-
type: 'string',
|
|
32
|
-
description: 'Connect to a running Chrome instance using port forwarding. For more details see: https://developer.chrome.com/docs/devtools/remote-debugging/local-server.',
|
|
33
|
-
alias: 'u',
|
|
34
|
-
coerce: (url) => {
|
|
35
|
-
new URL(url);
|
|
36
|
-
return url;
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
headless: {
|
|
40
|
-
type: 'boolean',
|
|
41
|
-
description: 'Whether to run in headless (no UI) mode.',
|
|
42
|
-
default: false,
|
|
43
|
-
},
|
|
44
|
-
executablePath: {
|
|
45
|
-
type: 'string',
|
|
46
|
-
description: 'Path to custom Chrome executable.',
|
|
47
|
-
conflicts: 'browserUrl',
|
|
48
|
-
alias: 'e',
|
|
49
|
-
},
|
|
50
|
-
isolated: {
|
|
51
|
-
type: 'boolean',
|
|
52
|
-
description: 'If specified, creates a temporary user-data-dir that is automatically cleaned up after the browser is closed.',
|
|
53
|
-
default: false,
|
|
54
|
-
},
|
|
55
|
-
customDevtools: {
|
|
56
|
-
type: 'string',
|
|
57
|
-
description: 'Path to custom DevTools.',
|
|
58
|
-
hidden: true,
|
|
59
|
-
conflicts: 'browserUrl',
|
|
60
|
-
alias: 'd',
|
|
61
|
-
},
|
|
62
|
-
channel: {
|
|
63
|
-
type: 'string',
|
|
64
|
-
description: 'Specify a different Chrome channel that should be used. The default is the stable channel version.',
|
|
65
|
-
choices: ['stable', 'canary', 'beta', 'dev'],
|
|
66
|
-
conflicts: ['browserUrl', 'executablePath'],
|
|
67
|
-
},
|
|
68
|
-
logFile: {
|
|
69
|
-
type: 'string',
|
|
70
|
-
describe: 'Save the logs to file.',
|
|
71
|
-
hidden: true,
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
function readPackageJson() {
|
|
75
|
-
const currentDir = import.meta.dirname;
|
|
76
|
-
const packageJsonPath = path.join(currentDir, '..', '..', 'package.json');
|
|
77
|
-
if (!fs.existsSync(packageJsonPath)) {
|
|
78
|
-
return {};
|
|
79
|
-
}
|
|
80
|
-
try {
|
|
81
|
-
const json = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
82
|
-
assert.strict(json['name'], 'chrome-devtools-mcp');
|
|
83
|
-
return json;
|
|
84
|
-
}
|
|
85
|
-
catch {
|
|
86
|
-
return {};
|
|
87
|
-
}
|
|
7
|
+
const [major, minor] = process.version.substring(1).split('.').map(Number);
|
|
8
|
+
if (major < 22 || (major === 22 && minor < 12)) {
|
|
9
|
+
console.error(`ERROR: \`chrome-devtools-mcp\` does not support Node ${process.version}. Please upgrade to Node 22+.`);
|
|
10
|
+
process.exit(1);
|
|
88
11
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
.scriptName('npx chrome-devtools-mcp@latest')
|
|
92
|
-
.options(cliOptions)
|
|
93
|
-
.check(args => {
|
|
94
|
-
// We can't set default in the options else
|
|
95
|
-
// Yargs will complain
|
|
96
|
-
if (!args.channel && !args.browserUrl) {
|
|
97
|
-
args.channel = 'stable';
|
|
98
|
-
}
|
|
99
|
-
return true;
|
|
100
|
-
})
|
|
101
|
-
.example([
|
|
102
|
-
[
|
|
103
|
-
'$0 --browserUrl http://127.0.0.1:9222',
|
|
104
|
-
'Connect to an existing browser instance',
|
|
105
|
-
],
|
|
106
|
-
['$0 --channel beta', 'Use Chrome Beta installed on this system'],
|
|
107
|
-
['$0 --channel canary', 'Use Chrome Canary installed on this system'],
|
|
108
|
-
['$0 --channel dev', 'Use Chrome Dev installed on this system'],
|
|
109
|
-
['$0 --channel stable', 'Use stable Chrome installed on this system'],
|
|
110
|
-
['$0 --logFile /tmp/log.txt', 'Save logs to a file'],
|
|
111
|
-
['$0 --help', 'Print CLI options'],
|
|
112
|
-
]);
|
|
113
|
-
export const args = yargsInstance
|
|
114
|
-
.wrap(Math.min(120, yargsInstance.terminalWidth()))
|
|
115
|
-
.help()
|
|
116
|
-
.version(version)
|
|
117
|
-
.parseSync();
|
|
118
|
-
const logFile = args.logFile ? saveLogsToFile(args.logFile) : undefined;
|
|
119
|
-
logger(`Starting Chrome DevTools MCP Server v${version}`);
|
|
120
|
-
const server = new McpServer({
|
|
121
|
-
name: 'chrome_devtools',
|
|
122
|
-
title: 'Chrome DevTools MCP server',
|
|
123
|
-
version,
|
|
124
|
-
}, { capabilities: { logging: {} } });
|
|
125
|
-
server.server.setRequestHandler(SetLevelRequestSchema, () => {
|
|
126
|
-
return {};
|
|
127
|
-
});
|
|
128
|
-
let context;
|
|
129
|
-
async function getContext() {
|
|
130
|
-
const browser = await resolveBrowser({
|
|
131
|
-
browserUrl: args.browserUrl,
|
|
132
|
-
headless: args.headless,
|
|
133
|
-
executablePath: args.executablePath,
|
|
134
|
-
customDevTools: args.customDevtools,
|
|
135
|
-
channel: args.channel,
|
|
136
|
-
isolated: args.isolated,
|
|
137
|
-
logFile,
|
|
138
|
-
});
|
|
139
|
-
if (context?.browser !== browser) {
|
|
140
|
-
context = await McpContext.from(browser, logger);
|
|
141
|
-
}
|
|
142
|
-
return context;
|
|
143
|
-
}
|
|
144
|
-
const logDisclaimers = () => {
|
|
145
|
-
console.error(`chrome-devtools-mcp exposes content of the browser instance to the MCP clients allowing them to inspect,
|
|
146
|
-
debug, and modify any data in the browser or DevTools.
|
|
147
|
-
Avoid sharing sensitive or personal information that you do want to share with MCP clients.`);
|
|
148
|
-
};
|
|
149
|
-
const toolMutex = new Mutex();
|
|
150
|
-
function registerTool(tool) {
|
|
151
|
-
server.registerTool(tool.name, {
|
|
152
|
-
description: tool.description,
|
|
153
|
-
inputSchema: tool.schema,
|
|
154
|
-
annotations: tool.annotations,
|
|
155
|
-
}, async (params) => {
|
|
156
|
-
const guard = await toolMutex.acquire();
|
|
157
|
-
try {
|
|
158
|
-
logger(`${tool.name} request: ${JSON.stringify(params, null, ' ')}`);
|
|
159
|
-
const context = await getContext();
|
|
160
|
-
const response = new McpResponse();
|
|
161
|
-
await tool.handler({
|
|
162
|
-
params,
|
|
163
|
-
}, response, context);
|
|
164
|
-
try {
|
|
165
|
-
const content = await response.handle(tool.name, context);
|
|
166
|
-
return {
|
|
167
|
-
content,
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
catch (error) {
|
|
171
|
-
const errorText = error instanceof Error ? error.message : String(error);
|
|
172
|
-
return {
|
|
173
|
-
content: [
|
|
174
|
-
{
|
|
175
|
-
type: 'text',
|
|
176
|
-
text: errorText,
|
|
177
|
-
},
|
|
178
|
-
],
|
|
179
|
-
isError: true,
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
finally {
|
|
184
|
-
guard.dispose();
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
const tools = [
|
|
189
|
-
...Object.values(consoleTools),
|
|
190
|
-
...Object.values(emulationTools),
|
|
191
|
-
...Object.values(inputTools),
|
|
192
|
-
...Object.values(networkTools),
|
|
193
|
-
...Object.values(pagesTools),
|
|
194
|
-
...Object.values(performanceTools),
|
|
195
|
-
...Object.values(screenshotTools),
|
|
196
|
-
...Object.values(scriptTools),
|
|
197
|
-
...Object.values(snapshotTools),
|
|
198
|
-
];
|
|
199
|
-
for (const tool of tools) {
|
|
200
|
-
registerTool(tool);
|
|
201
|
-
}
|
|
202
|
-
const transport = new StdioServerTransport();
|
|
203
|
-
await server.connect(transport);
|
|
204
|
-
logger('Chrome DevTools MCP Server connected');
|
|
205
|
-
logDisclaimers();
|
|
12
|
+
await import('./main.js');
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
7
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
8
|
+
import { SetLevelRequestSchema, } from '@modelcontextprotocol/sdk/types.js';
|
|
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';
|
|
14
|
+
import { resolveBrowser } from './browser.js';
|
|
15
|
+
import * as emulationTools from './tools/emulation.js';
|
|
16
|
+
import * as consoleTools from './tools/console.js';
|
|
17
|
+
import * as inputTools from './tools/input.js';
|
|
18
|
+
import * as networkTools from './tools/network.js';
|
|
19
|
+
import * as pagesTools from './tools/pages.js';
|
|
20
|
+
import * as performanceTools from './tools/performance.js';
|
|
21
|
+
import * as screenshotTools from './tools/screenshot.js';
|
|
22
|
+
import * as scriptTools from './tools/script.js';
|
|
23
|
+
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
|
+
function readPackageJson() {
|
|
74
|
+
const currentDir = import.meta.dirname;
|
|
75
|
+
const packageJsonPath = path.join(currentDir, '..', '..', 'package.json');
|
|
76
|
+
if (!fs.existsSync(packageJsonPath)) {
|
|
77
|
+
return {};
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
const json = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8'));
|
|
81
|
+
assert.strict(json['name'], 'chrome-devtools-mcp');
|
|
82
|
+
return json;
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return {};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const version = readPackageJson().version ?? 'unknown';
|
|
89
|
+
const yargsInstance = yargs(hideBin(process.argv))
|
|
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();
|
|
117
|
+
const logFile = args.logFile ? saveLogsToFile(args.logFile) : undefined;
|
|
118
|
+
logger(`Starting Chrome DevTools MCP Server v${version}`);
|
|
119
|
+
const server = new McpServer({
|
|
120
|
+
name: 'chrome_devtools',
|
|
121
|
+
title: 'Chrome DevTools MCP server',
|
|
122
|
+
version,
|
|
123
|
+
}, { capabilities: { logging: {} } });
|
|
124
|
+
server.server.setRequestHandler(SetLevelRequestSchema, () => {
|
|
125
|
+
return {};
|
|
126
|
+
});
|
|
127
|
+
let context;
|
|
128
|
+
async function getContext() {
|
|
129
|
+
const browser = await resolveBrowser({
|
|
130
|
+
browserUrl: args.browserUrl,
|
|
131
|
+
headless: args.headless,
|
|
132
|
+
executablePath: args.executablePath,
|
|
133
|
+
customDevTools: args.customDevtools,
|
|
134
|
+
channel: args.channel,
|
|
135
|
+
isolated: args.isolated,
|
|
136
|
+
logFile,
|
|
137
|
+
});
|
|
138
|
+
if (context?.browser !== browser) {
|
|
139
|
+
context = await McpContext.from(browser, logger);
|
|
140
|
+
}
|
|
141
|
+
return context;
|
|
142
|
+
}
|
|
143
|
+
const logDisclaimers = () => {
|
|
144
|
+
console.error(`chrome-devtools-mcp exposes content of the browser instance to the MCP clients allowing them to inspect,
|
|
145
|
+
debug, and modify any data in the browser or DevTools.
|
|
146
|
+
Avoid sharing sensitive or personal information that you do want to share with MCP clients.`);
|
|
147
|
+
};
|
|
148
|
+
const toolMutex = new Mutex();
|
|
149
|
+
function registerTool(tool) {
|
|
150
|
+
server.registerTool(tool.name, {
|
|
151
|
+
description: tool.description,
|
|
152
|
+
inputSchema: tool.schema,
|
|
153
|
+
annotations: tool.annotations,
|
|
154
|
+
}, async (params) => {
|
|
155
|
+
const guard = await toolMutex.acquire();
|
|
156
|
+
try {
|
|
157
|
+
logger(`${tool.name} request: ${JSON.stringify(params, null, ' ')}`);
|
|
158
|
+
const context = await getContext();
|
|
159
|
+
const response = new McpResponse();
|
|
160
|
+
await tool.handler({
|
|
161
|
+
params,
|
|
162
|
+
}, response, context);
|
|
163
|
+
try {
|
|
164
|
+
const content = await response.handle(tool.name, context);
|
|
165
|
+
return {
|
|
166
|
+
content,
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
const errorText = error instanceof Error ? error.message : String(error);
|
|
171
|
+
return {
|
|
172
|
+
content: [
|
|
173
|
+
{
|
|
174
|
+
type: 'text',
|
|
175
|
+
text: errorText,
|
|
176
|
+
},
|
|
177
|
+
],
|
|
178
|
+
isError: true,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
finally {
|
|
183
|
+
guard.dispose();
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
const tools = [
|
|
188
|
+
...Object.values(consoleTools),
|
|
189
|
+
...Object.values(emulationTools),
|
|
190
|
+
...Object.values(inputTools),
|
|
191
|
+
...Object.values(networkTools),
|
|
192
|
+
...Object.values(pagesTools),
|
|
193
|
+
...Object.values(performanceTools),
|
|
194
|
+
...Object.values(screenshotTools),
|
|
195
|
+
...Object.values(scriptTools),
|
|
196
|
+
...Object.values(snapshotTools),
|
|
197
|
+
];
|
|
198
|
+
for (const tool of tools) {
|
|
199
|
+
registerTool(tool);
|
|
200
|
+
}
|
|
201
|
+
const transport = new StdioServerTransport();
|
|
202
|
+
await server.connect(transport);
|
|
203
|
+
logger('Chrome DevTools MCP Server connected');
|
|
204
|
+
logDisclaimers();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chrome-devtools-mcp",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.7",
|
|
4
4
|
"description": "MCP server for Chrome DevTools",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": "./build/src/index.js",
|
|
@@ -58,5 +58,8 @@
|
|
|
58
58
|
"sinon": "^21.0.0",
|
|
59
59
|
"typescript": "^5.9.2",
|
|
60
60
|
"typescript-eslint": "^8.43.0"
|
|
61
|
+
},
|
|
62
|
+
"engines": {
|
|
63
|
+
"node": ">=22.12.0"
|
|
61
64
|
}
|
|
62
65
|
}
|