Skip to content

Commit 3273670

Browse files
author
Piotr Paulski
committed
Add option to encode structuredContent as TOON
1 parent 90d368d commit 3273670

6 files changed

Lines changed: 66 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/transformation.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 = { format: 'toon', data: 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
@@ -169,6 +169,12 @@ export const cliOptions = {
169169
type: 'boolean',
170170
describe: 'Whether to output structured formatted content.',
171171
},
172+
experimentalStructuredContentFormat: {
173+
type: 'string',
174+
describe: 'The format of the structured content. Defaults to "json".',
175+
choices: ['toon', 'json'] as const,
176+
hidden: true,
177+
},
172178
experimentalIncludeAllPages: {
173179
type: 'boolean',
174180
describe:
@@ -293,7 +299,7 @@ export function parseArguments(
293299
const yargsInstance = yargs(hideBin(argv))
294300
.scriptName('npx chrome-devtools-mcp@latest')
295301
.options(cliOptions)
296-
.check(args => {
302+
.middleware(args => {
297303
// We can't set default in the options else
298304
// Yargs will complain
299305
if (
@@ -310,6 +316,19 @@ export function parseArguments(
310316
);
311317
args.usageStatistics = false;
312318
}
319+
if (args.experimentalStructuredContentFormat && args.experimentalStructuredContent === undefined) {
320+
args.experimentalStructuredContent = true;
321+
}
322+
if (args.experimentalStructuredContentFormat === undefined && args.experimentalStructuredContent) {
323+
args.experimentalStructuredContentFormat = 'json';
324+
}
325+
})
326+
.check(args => {
327+
if (args.experimentalStructuredContentFormat && !args.experimentalStructuredContent) {
328+
throw new Error(
329+
'The --experimentalStructuredContentFormat option can only be used when --experimentalStructuredContent is enabled.'
330+
);
331+
}
313332
return true;
314333
})
315334
.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,

tests/third_party_notices.test.js.snapshot

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,6 +1622,36 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
16221622
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16231623

16241624

1625+
-------------------- DEPENDENCY DIVIDER --------------------
1626+
1627+
Name: @toon-format/toon
1628+
URL: https://toonformat.dev
1629+
Version: <VERSION>
1630+
License: MIT
1631+
1632+
MIT License
1633+
1634+
Copyright (c) 2025-PRESENT Johann Schopplich
1635+
1636+
Permission is hereby granted, free of charge, to any person obtaining a copy
1637+
of this software and associated documentation files (the "Software"), to deal
1638+
in the Software without restriction, including without limitation the rights
1639+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1640+
copies of the Software, and to permit persons to whom the Software is
1641+
furnished to do so, subject to the following conditions:
1642+
1643+
The above copyright notice and this permission notice shall be included in all
1644+
copies or substantial portions of the Software.
1645+
1646+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1647+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1648+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1649+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1650+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1651+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1652+
SOFTWARE.
1653+
1654+
16251655
-------------------- DEPENDENCY DIVIDER --------------------
16261656

16271657
Name: chrome-devtools-frontend

0 commit comments

Comments
 (0)