Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^16.0.3",
"@stylistic/eslint-plugin": "^5.4.0",
"@blackwell-systems/gcf": "2.1.2",
"@toon-format/toon": "^2.2.0",
"@types/debug": "^4.1.12",
"@types/filesystem": "^0.0.36",
Expand Down
22 changes: 13 additions & 9 deletions src/McpResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import type {McpContext} from './McpContext.js';
import type {McpPage} from './McpPage.js';
import {UncaughtError} from './PageCollector.js';
import {TextSnapshot} from './TextSnapshot.js';
import {DevTools, toonEncode, type Protocol} from './third_party/index.js';
import {DevTools, toonEncode, gcfEncode, type Protocol} from './third_party/index.js';
import type {
ConsoleMessage,
ImageContent,
Expand Down Expand Up @@ -525,6 +525,7 @@ export class McpResponse implements Response {
toolName: string,
context: McpContext,
useToon = false,
useGcf = false,
): Promise<{
content: Array<TextContent | ImageContent>;
structuredContent: object;
Expand Down Expand Up @@ -771,6 +772,7 @@ export class McpResponse implements Response {
errorMessage: this.#error?.message,
},
useToon,
useGcf,
);
}

Expand All @@ -792,10 +794,12 @@ export class McpResponse implements Response {
errorMessage?: string;
},
useToon: boolean,
useGcf = false,
): Promise<{
content: Array<TextContent | ImageContent>;
structuredContent: object;
}> {
const compactEncode = useGcf ? gcfEncode : useToon ? toonEncode : null;
const structuredContent: {
snapshot?: object;
snapshotFilePath?: string;
Expand Down Expand Up @@ -1057,8 +1061,8 @@ Call ${handleDialog.name} to handle it before continuing.`);
structuredContent.snapshot = data.snapshot.toJSON();
response.push('## Latest page snapshot');
response.push(
useToon
? toonEncode(structuredContent.snapshot)
compactEncode
? compactEncode(structuredContent.snapshot)
: data.snapshot.toString(),
);
}
Expand Down Expand Up @@ -1095,8 +1099,8 @@ Call ${handleDialog.name} to handle it before continuing.`);

structuredContent.heapSnapshotData = formatter.toJSON();
response.push(
useToon
? toonEncode(structuredContent.heapSnapshotData)
compactEncode
? compactEncode(structuredContent.heapSnapshotData)
: formatter.toString(),
);
}
Expand Down Expand Up @@ -1244,8 +1248,8 @@ Call ${handleDialog.name} to handle it before continuing.`);
i.toJSON(),
);
response.push(
...(useToon
? [toonEncode(structuredContent.networkRequests)]
...(compactEncode
? [compactEncode(structuredContent.networkRequests)]
: paginationData.items.map(i => i.toString())),
);
}
Expand All @@ -1269,8 +1273,8 @@ Call ${handleDialog.name} to handle it before continuing.`);
item.toJSON(),
);
response.push(...paginationData.info);
if (useToon) {
response.push(toonEncode(structuredContent.consoleMessages));
if (compactEncode) {
response.push(compactEncode(structuredContent.consoleMessages));
} else {
response.push(...paginationData.items.map(item => item.toString()));
}
Expand Down
1 change: 1 addition & 0 deletions src/ToolHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ export class ToolHandler {
this.tool.name,
context,
this.serverArgs.experimentalToonFormat ?? false,
this.serverArgs.experimentalGcfFormat ?? false,
);
const result: CallToolResult & {
structuredContent?: Record<string, unknown>;
Expand Down
6 changes: 6 additions & 0 deletions src/bin/chrome-devtools-mcp-cli-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ export const cliOptions = {
'Whether to format structured data in text response using Token-Oriented Object Notation. Defaults to false which represents the embedded content as formatted JSON instead.',
hidden: true,
},
experimentalGcfFormat: {
type: 'boolean',
describe:
'Whether to format structured data in text response using Graph Compact Format. Defaults to false which represents the embedded content as formatted JSON instead.',
hidden: true,
},
experimentalIncludeAllPages: {
type: 'boolean',
describe:
Expand Down
1 change: 1 addition & 0 deletions src/third_party/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export {
type ChromeReleaseChannel as BrowsersChromeReleaseChannel,
} from '@puppeteer/browsers';
export {encode as toonEncode} from '@toon-format/toon';
export {encodeGeneric as gcfEncode} from '@blackwell-systems/gcf';

import {
snapshot as snapshotImpl,
Expand Down