Skip to content

Commit 91642e4

Browse files
author
Piotr Paulski
committed
Add option to encode structuredContent as TOON
1 parent 85f935b commit 91642e4

5 files changed

Lines changed: 36 additions & 2 deletions

File tree

package-lock.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"@rollup/plugin-json": "^6.1.0",
5555
"@rollup/plugin-node-resolve": "^16.0.3",
5656
"@stylistic/eslint-plugin": "^5.4.0",
57+
"@toon-format/toon": "^2.2.0",
5758
"@types/debug": "^4.1.12",
5859
"@types/filesystem": "^0.0.36",
5960
"@types/node": "^25.0.0",

src/ToolHandler.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {SlimMcpResponse} from './SlimMcpResponse.js';
1313
import {ClearcutLogger} from './telemetry/ClearcutLogger.js';
1414
import {bucketizeLatency} from './telemetry/metricUtils.js';
1515
import type {CallToolResult, zod} from './third_party/index.js';
16+
import {toonEncode} from './third_party/index.js';
1617
import type {ToolCategory} from './tools/categories.js';
1718
import {labels, OFF_BY_DEFAULT_CATEGORIES} from './tools/categories.js';
1819
import type {DefinedPageTool, ToolDefinition} from './tools/ToolDefinition.js';
@@ -221,7 +222,11 @@ export class ToolHandler {
221222
}
222223
success = true;
223224
if (this.serverArgs.experimentalStructuredContent) {
224-
result.structuredContent = structuredContent as Record<string, unknown>;
225+
if (this.serverArgs.experimentalStructuredContentFormat === 'toon') {
226+
result.structuredContent = { toon: toonEncode(structuredContent)};
227+
} else {
228+
result.structuredContent = structuredContent as Record<string, unknown>;
229+
}
225230
}
226231
return result;
227232
} catch (err) {

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ export const cliOptions = {
174174
describe: 'Whether to output structured formatted content.',
175175
hidden: true,
176176
},
177+
experimentalStructuredContentFormat: {
178+
type: 'string',
179+
describe: 'The format of the structured content. Defaults to "json".',
180+
choices: ['toon', 'json'] as const,
181+
hidden: true,
182+
},
177183
experimentalIncludeAllPages: {
178184
type: 'boolean',
179185
describe:
@@ -299,7 +305,7 @@ export function parseArguments(
299305
const yargsInstance = yargs(hideBin(argv))
300306
.scriptName('npx chrome-devtools-mcp@latest')
301307
.options(cliOptions)
302-
.check(args => {
308+
.middleware(args => {
303309
// We can't set default in the options else
304310
// Yargs will complain
305311
if (
@@ -316,6 +322,19 @@ export function parseArguments(
316322
);
317323
args.usageStatistics = false;
318324
}
325+
if (args.experimentalStructuredContentFormat && args.experimentalStructuredContent === undefined) {
326+
args.experimentalStructuredContent = true;
327+
}
328+
if (args.experimentalStructuredContentFormat === undefined && args.experimentalStructuredContent) {
329+
args.experimentalStructuredContentFormat = 'json';
330+
}
331+
})
332+
.check(args => {
333+
if (args.experimentalStructuredContentFormat && !args.experimentalStructuredContent) {
334+
throw new Error(
335+
'The --experimentalStructuredContentFormat option can only be used when --experimentalStructuredContent is enabled.'
336+
);
337+
}
319338
return true;
320339
})
321340
.example([

src/third_party/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export {
5454
Browser as BrowserEnum,
5555
type ChromeReleaseChannel as BrowsersChromeReleaseChannel,
5656
} from '@puppeteer/browsers';
57+
export {encode as toonEncode} from '@toon-format/toon';
5758

5859
import {
5960
snapshot as snapshotImpl,

0 commit comments

Comments
 (0)