Skip to content

Commit f005c69

Browse files
Merge branch 'main' of github.com:ChromeDevTools/chrome-devtools-mcp into webmcp
2 parents 98011ce + 764b9cf commit f005c69

14 files changed

Lines changed: 228 additions & 123 deletions

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,11 @@ The Chrome DevTools MCP server supports the following configuration option:
620620
Exposes a "slim" set of 3 tools covering navigation, script execution and screenshots only. Useful for basic browser tasks.
621621
- **Type:** boolean
622622

623+
- **`--redactNetworkHeaders`/ `--redact-network-headers`**
624+
If true, redacts some of the network headers considered senstive before returning to the client.
625+
- **Type:** boolean
626+
- **Default:** `false`
627+
623628
<!-- END AUTO GENERATED OPTIONS -->
624629

625630
Pass them via the `args` property in the JSON configuration. For example:

package-lock.json

Lines changed: 100 additions & 101 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/post-build.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ function main(): void {
2626

2727
// Create i18n mock
2828
const i18nDir = path.join(BUILD_DIR, devtoolsFrontEndCorePath, 'i18n');
29+
fs.mkdirSync(i18nDir, {recursive: true});
2930
const localesFile = path.join(i18nDir, 'locales.js');
3031
const localesContent = `
3132
export const LOCALES = [

scripts/test.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ async function runTests(attempt) {
101101
...process.env,
102102
CHROME_DEVTOOLS_MCP_NO_USAGE_STATISTICS: true,
103103
CHROME_DEVTOOLS_MCP_CRASH_ON_UNCAUGHT: true,
104+
CHROME_DEVTOOLS_MCP_NO_UPDATE_CHECKS: true,
104105
},
105106
});
106107

src/McpResponse.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ export class McpResponse implements Response {
188188
#tabId?: string;
189189
#args: ParsedArguments;
190190
#page?: McpPage;
191+
#redactNetworkHeaders = true;
191192

192193
constructor(args: ParsedArguments) {
193194
this.#args = args;
@@ -197,6 +198,10 @@ export class McpResponse implements Response {
197198
this.#page = page;
198199
}
199200

201+
setRedactNetworkHeaders(value: boolean): void {
202+
this.#redactNetworkHeaders = value;
203+
}
204+
200205
attachDevToolsData(data: DevToolsData): void {
201206
this.#devToolsData = data;
202207
}
@@ -434,6 +439,7 @@ export class McpResponse implements Response {
434439
requestFilePath: this.#attachedNetworkRequestOptions?.requestFilePath,
435440
responseFilePath: this.#attachedNetworkRequestOptions?.responseFilePath,
436441
saveFile: (data, filename) => context.saveFile(data, filename),
442+
redactNetworkHeaders: this.#redactNetworkHeaders,
437443
});
438444
detailedNetworkRequest = formatter;
439445
}
@@ -583,6 +589,7 @@ export class McpResponse implements Response {
583589
this.#networkRequestsOptions?.networkRequestIdInDevToolsUI,
584590
fetchData: false,
585591
saveFile: (data, filename) => context.saveFile(data, filename),
592+
redactNetworkHeaders: this.#redactNetworkHeaders,
586593
}),
587594
),
588595
);

src/bin/chrome-devtools-mcp-cli-options.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,12 @@ export const cliOptions = {
266266
'Set by Chrome DevTools CLI if the MCP server is started via the CLI client (this arg exists for usage stats)',
267267
hidden: true,
268268
},
269+
redactNetworkHeaders: {
270+
type: 'boolean',
271+
describe:
272+
'If true, redacts some of the network headers considered senstive before returning to the client.',
273+
default: false,
274+
},
269275
} satisfies Record<string, YargsOptions>;
270276

271277
export type ParsedArguments = ReturnType<typeof parseArguments>;

src/formatters/NetworkFormatter.ts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66

77
import {isUtf8} from 'node:buffer';
88

9-
import type {HTTPRequest, HTTPResponse} from '../third_party/index.js';
9+
import {
10+
DevTools,
11+
type HTTPRequest,
12+
type HTTPResponse,
13+
} from '../third_party/index.js';
1014

1115
const BODY_CONTEXT_SIZE_LIMIT = 10000;
1216

@@ -21,6 +25,7 @@ export interface NetworkFormatterOptions {
2125
data: Uint8Array<ArrayBufferLike>,
2226
filename: string,
2327
) => Promise<{filename: string}>;
28+
redactNetworkHeaders: boolean;
2429
}
2530

2631
interface NetworkRequestConcise {
@@ -150,6 +155,20 @@ export class NetworkFormatter {
150155
};
151156
}
152157

158+
#redactNetworkHeaders(
159+
headers: Record<string, string>,
160+
): Record<string, string> {
161+
const headersList = Object.entries(headers).map(item => {
162+
return {name: item[0], value: item[1]};
163+
});
164+
const redacted =
165+
DevTools.NetworkRequestFormatter.sanitizeHeaders(headersList);
166+
return redacted.reduce<Record<string, string>>((acc, item) => {
167+
acc[item.name] = item.value;
168+
return acc;
169+
}, {});
170+
}
171+
153172
toJSONDetailed(): NetworkRequestDetailed {
154173
const redirectChain = this.#request.redirectChain();
155174
const formattedRedirectChain = redirectChain.reverse().map(request => {
@@ -159,16 +178,24 @@ export class NetworkFormatter {
159178
const formatter = new NetworkFormatter(request, {
160179
requestId: id,
161180
saveFile: this.#options.saveFile,
181+
redactNetworkHeaders: this.#options.redactNetworkHeaders,
162182
});
163183
return formatter.toJSON();
164184
});
165185

186+
const responseHeaders = this.#request.response()?.headers();
187+
166188
return {
167189
...this.toJSON(),
168-
requestHeaders: this.#request.headers(),
190+
requestHeaders: this.#options.redactNetworkHeaders
191+
? this.#redactNetworkHeaders(this.#request.headers())
192+
: this.#request.headers(),
169193
requestBody: this.#requestBody,
170194
requestBodyFilePath: this.#requestBodyFilePath,
171-
responseHeaders: this.#request.response()?.headers(),
195+
responseHeaders:
196+
this.#options.redactNetworkHeaders && responseHeaders
197+
? this.#redactNetworkHeaders(responseHeaders)
198+
: this.#request.response()?.headers(),
172199
responseBody: this.#responseBody,
173200
responseBodyFilePath: this.#responseBodyFilePath,
174201
failure: this.#request.failure()?.errorText,

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,8 @@ export async function createMcpServer(
197197
const response = serverArgs.slim
198198
? new SlimMcpResponse(serverArgs)
199199
: new McpResponse(serverArgs);
200+
201+
response.setRedactNetworkHeaders(serverArgs.redactNetworkHeaders);
200202
if ('pageScoped' in tool && tool.pageScoped) {
201203
const page =
202204
serverArgs.experimentalPageIdRouting &&

tests/McpContext.test.js.snapshot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ exports[`McpContext > should include detailed network request in structured cont
66
"url": "http://example.com/detail",
77
"status": "pending",
88
"requestHeaders": {
9-
"content-size": "10"
9+
"content-size": "<redacted>"
1010
}
1111
}
1212
}

tests/McpResponse.test.js.snapshot

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ exports[`McpResponse > add network request when attached 1`] = `
22
## Request http://example.com
33
Status: pending
44
### Request Headers
5-
- content-size:10
5+
- content-size:<redacted>
66
## Network requests
77
Showing 1-1 of 1 (Page 1 of 1).
88
reqid=1 GET http://example.com [pending]
@@ -16,7 +16,7 @@ exports[`McpResponse > add network request when attached 2`] = `
1616
"url": "http://example.com",
1717
"status": "pending",
1818
"requestHeaders": {
19-
"content-size": "10"
19+
"content-size": "<redacted>"
2020
}
2121
},
2222
"pagination": {
@@ -44,7 +44,7 @@ exports[`McpResponse > add network request when attached with POST data 1`] = `
4444
## Request http://example.com
4545
Status: 200
4646
### Request Headers
47-
- content-size:10
47+
- content-size:<redacted>
4848
### Request Body
4949
{"request":"body"}
5050
### Response Headers
@@ -64,7 +64,7 @@ exports[`McpResponse > add network request when attached with POST data 2`] = `
6464
"url": "http://example.com",
6565
"status": "200",
6666
"requestHeaders": {
67-
"content-size": "10"
67+
"content-size": "<redacted>"
6868
},
6969
"requestBody": "{\\"request\\":\\"body\\"}",
7070
"responseHeaders": {

0 commit comments

Comments
 (0)