coleam00/Archon · error

MCP config file is not valid JSON: ${mcpPath} - ${detail}

Error message

MCP config file is not valid JSON: ${mcpPath} - ${detail}

What it means

After reading succeeds, the file must parse as JSON. loadMcpConfig catches the SyntaxError and rethrows it with the config path plus the parser's detail (position and reason), so you can find and fix the malformed line instead of getting a bare 'Unexpected token' with no file context.

Source

Thrown at packages/providers/src/mcp/config.ts:150

  const fullPath = isAbsolute(mcpPath) ? mcpPath : resolve(cwd, mcpPath);

  let raw: string;
  try {
    raw = await readFile(fullPath, 'utf-8');
  } catch (err) {
    const e = err as NodeJS.ErrnoException;
    if (e.code === 'ENOENT') {
      throw new Error(`MCP config file not found: ${mcpPath} (resolved to ${fullPath})`);
    }
    throw new Error(`Failed to read MCP config file: ${mcpPath} - ${e.message}`);
  }

  let parsed: Record<string, unknown>;
  try {
    parsed = JSON.parse(raw) as Record<string, unknown>;
  } catch (parseErr) {
    const detail = (parseErr as SyntaxError).message;
    throw new Error(`MCP config file is not valid JSON: ${mcpPath} - ${detail}`);
  }

  if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
    throw new Error(`MCP config must be a JSON object (Record<string, ServerConfig>): ${mcpPath}`);
  }

  const normalized = normalizeMcpConfig(parsed, mcpPath);
  const { expanded, missingVars } = expandEnvVars(normalized, envSource);
  const serverNames = Object.keys(expanded);
  return { servers: expanded, serverNames, missingVars };
}

View on GitHub (pinned to 0773b97458)

Solutions

  1. Open the file at the position given in the detail message and fix the JSON syntax (remove comments/trailing commas/conflict markers).
  2. Validate with a JSON linter or `node -e 'JSON.parse(require("fs").readFileSync(p))'` before loading.
  3. If the file is empty or half-written, restore it from backup or recreate it.

Example fix

// before
{
  "mcpServers": { "fs": { "command": "npx" } }, // my servers
}
// after
{
  "mcpServers": { "fs": { "command": "npx" } }
}
Defensive patterns

Strategy: validation

Validate before calling

try {
  JSON.parse(readFileSync(mcpPath, 'utf-8'));
} catch (e) {
  throw new Error(`${mcpPath} is not valid JSON: ${(e as Error).message}. Remove comments/trailing commas.`);
}

Try / catch

// try { await loadMcpConfig(p, cwd); }
// catch (err) {
//   if (err.message.includes('not valid JSON')) {
//     console.error(`Fix JSON syntax in ${p}: ${err.message}`);
//   } else throw err;
// }

Prevention

When it happens

Trigger: loadMcpConfig on a file containing JSON5/JSONC syntax (comments, trailing commas), empty file, truncated write, or non-JSON content (YAML, TOML, shell script).

Common situations: Adding // comments to a .json file; editor left a trailing comma after deleting the last entry; concurrent writes truncated the file; someone saved YAML into a .json path; merge-conflict markers (<<<<<<<) left in the file.

Related errors


AI-assisted analysis of coleam00/Archon@0773b97458 (2026-09-01). Data as JSON: /api/errors/5d9be74cd550b7da. Report an issue: GitHub.