Chrome DevTools for coding agents
fix(config): accept native JSON objects for wsHeaders in config files (#3262)
Nikolay Vitkov371e6c2f87f1
diff --git a/src/config/ConfigParser.ts b/src/config/ConfigParser.tsindex a2ae9c08..d6d75c74 100644--- a/src/config/ConfigParser.ts+++ b/src/config/ConfigParser.ts@@ -96,12 +96,16 @@ export class ConfigParser {if (!isPlainObject(fileContent)) {throw new Error('Config must be a JSON object');}+ const configOptions = withoutDefaults(mcpOptions);+ delete configOptions.config;const parsed = yargs([]).parserConfiguration({'strip-aliased': true,'camel-case-expansion': false,})- .options(withoutDefaults(mcpOptions))+ .options(configOptions)+ .help(false)+ .version(false).config(fileContent).strict().fail(false)diff --git a/src/config/browser-options.ts b/src/config/browser-options.tsindex 9a3bb748..97658ddf 100644--- a/src/config/browser-options.ts+++ b/src/config/browser-options.ts@@ -59,19 +59,30 @@ export const browserOptions = {type: 'string',description:'Custom headers for WebSocket connection in JSON format (e.g., \'{"Authorization":"Bearer token"}\'). Only works with --wsEndpoint.',- coerce: (val: string | undefined) => {+ coerce: (val: unknown) => {if (!val) {return;}try {- const parsed = JSON.parse(val);- if (typeof parsed !== 'object' || Array.isArray(parsed)) {+ const parsed: unknown = typeof val === 'string' ? JSON.parse(val) : val;+ if (+ typeof parsed !== 'object' ||+ parsed === null ||+ Array.isArray(parsed)+ ) {throw new Error('Headers must be a JSON object');}- return parsed as Record<string, string>;+ const headers: Record<string, string> = {};+ for (const [key, value] of Object.entries(parsed)) {+ if (typeof value !== 'string') {+ throw new Error(`Header "${key}" must have a string value`);+ }+ headers[key] = value;+ }+ return headers;} catch (error) {throw new Error(- `Invalid JSON for wsHeaders: ${(error as Error).message}`,+ `Invalid JSON for wsHeaders: ${error instanceof Error ? error.message : String(error)}`,);}},diff --git a/tests/config/mcp-options.test.ts b/tests/config/mcp-options.test.tsindex 4ee93852..01bbe1bf 100644--- a/tests/config/mcp-options.test.ts+++ b/tests/config/mcp-options.test.ts@@ -67,6 +67,43 @@ describe('mcp-options steps', () => {/Invalid JSON config file: Config must be a JSON object/,);});++ it('accepts wsHeaders as a JSON object and validates string values', () => {+ using validFile = createTempFile(+ JSON.stringify({+ wsEndpoint: 'ws://localhost:9222',+ wsHeaders: {Authorization: 'Bearer token'},+ }),+ 'cd4a.wsheaders.valid.json',+ );+ const args = parser.parseConfigFile(validFile.path);+ assert.deepStrictEqual(args.wsHeaders, {Authorization: 'Bearer token'});++ using invalidFile = createTempFile(+ JSON.stringify({+ wsEndpoint: 'ws://localhost:9222',+ wsHeaders: {Authorization: 123},+ }),+ 'cd4a.wsheaders.invalid.json',+ );+ assert.throws(+ () => parser.parseConfigFile(invalidFile.path),+ /Header "Authorization" must have a string value/,+ );+ });++ it('rejects config, help, and version keys inside a config file', () => {+ for (const forbiddenKey of ['config', 'help', 'version']) {+ using configFile = createTempFile(+ JSON.stringify({[forbiddenKey]: true}),+ `cd4a.forbidden.${forbiddenKey}.json`,+ );+ assert.throws(+ () => parser.parseConfigFile(configFile.path),+ new RegExp(`Invalid JSON config file: .*${forbiddenKey}`),+ );+ }+ });});describe('config discovery', () => {