MCPcopy Create free account
hub / github.com/ChromeDevTools/chrome-devtools-mcp / parseConfigFile

Method parseConfigFile

src/config/ConfigParser.ts:90–121  ·  view source on GitHub ↗

* Step 2: reads the JSON config file and runs it through yargs to reject * unknown keys and apply coercions, without applying defaults.

(
    configPath: string,
    rawContent?: string,
  )

Source from the content-addressed store, hash-verified

88 * unknown keys and apply coercions, without applying defaults.
89 */
90 static parseConfigFile(
91 configPath: string,
92 rawContent?: string,
93 ): Partial<ParsedArguments> {
94 try {
95 const content = rawContent ?? readFileSync(configPath, 'utf-8');
96 // Strip a leading UTF-8 byte order mark (U+FEFF). Windows PowerShell 5.1
97 // writes one by default, and JSON.parse rejects it.
98 const fileContent: unknown = JSON.parse(content.replace(/^\uFEFF/, ''));
99 if (!isPlainObject(fileContent)) {
100 throw new Error('Config must be a JSON object');
101 }
102 const configOptions = withoutDefaults(mcpOptions);
103 delete configOptions.config;
104 const parsed = yargs([])
105 .parserConfiguration({
106 'strip-aliased': true,
107 'camel-case-expansion': false,
108 })
109 .options(configOptions)
110 .help(false)
111 .version(false)
112 .config(fileContent)
113 .strict()
114 .fail(false)
115 .exitProcess(false)
116 .parseSync([]);
117 return stripYargsPositionalArgs(parsed);
118 } catch (err) {
119 throw new Error(`Invalid JSON config file: ${getErrorMessage(err)}`);
120 }
121 }
122
123 parseConfigFile(
124 configPath: string,

Callers 3

#resolveConfigMethod · 0.95
#reloadConfigMethod · 0.80

Calls 6

isPlainObjectFunction · 0.85
withoutDefaultsFunction · 0.85
stripYargsPositionalArgsFunction · 0.85
getErrorMessageFunction · 0.85
parseMethod · 0.80
failMethod · 0.80

Tested by

no test coverage detected