fix: support JSONC in config files

Use the existing parseJsonBuffer helper (which leverages jsonc-parser)
instead of JSON.parse() when reading config files. This enables:

- Single-line comments (//)
- Multi-line comments (/* */)
- Trailing commas

The jsonc-parser dependency was already present but wasn't being used
for the main config file parsing.
This commit is contained in:
Saatvik Arya 2026-01-28 05:46:42 +05:30 committed by Peter Steinberger
parent 83db4fb1ec
commit 16a09ae048

View File

@ -4,6 +4,7 @@ import os from 'node:os';
import path from 'node:path';
import { pathsForImport, readExternalEntries } from './config-imports.js';
import { normalizeServerEntry } from './config-normalize.js';
import { parseJsonBuffer } from './config/imports/shared.js';
import {
DEFAULT_IMPORTS,
type LoadConfigOptions,
@ -209,7 +210,7 @@ async function readConfigFile(configPath: string, explicit: boolean): Promise<Ra
}
try {
const buffer = await fs.readFile(configPath, 'utf8');
return RawConfigSchema.parse(JSON.parse(buffer));
return RawConfigSchema.parse(parseJsonBuffer(buffer));
} catch (error) {
if (!explicit && isMissingConfigError(error)) {
return { mcpServers: {} };