{"record":{"id":"5d9be74cd550b7da","repo":"coleam00/Archon","slug":"mcp-config-file-is-not-valid-json-mcppath","errorCode":null,"errorMessage":"MCP config file is not valid JSON: ${mcpPath} - ${detail}","messagePattern":"MCP config file is not valid JSON: (.+?) - (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/providers/src/mcp/config.ts","lineNumber":150,"sourceCode":"  const fullPath = isAbsolute(mcpPath) ? mcpPath : resolve(cwd, mcpPath);\n\n  let raw: string;\n  try {\n    raw = await readFile(fullPath, 'utf-8');\n  } catch (err) {\n    const e = err as NodeJS.ErrnoException;\n    if (e.code === 'ENOENT') {\n      throw new Error(`MCP config file not found: ${mcpPath} (resolved to ${fullPath})`);\n    }\n    throw new Error(`Failed to read MCP config file: ${mcpPath} - ${e.message}`);\n  }\n\n  let parsed: Record<string, unknown>;\n  try {\n    parsed = JSON.parse(raw) as Record<string, unknown>;\n  } catch (parseErr) {\n    const detail = (parseErr as SyntaxError).message;\n    throw new Error(`MCP config file is not valid JSON: ${mcpPath} - ${detail}`);\n  }\n\n  if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {\n    throw new Error(`MCP config must be a JSON object (Record<string, ServerConfig>): ${mcpPath}`);\n  }\n\n  const normalized = normalizeMcpConfig(parsed, mcpPath);\n  const { expanded, missingVars } = expandEnvVars(normalized, envSource);\n  const serverNames = Object.keys(expanded);\n  return { servers: expanded, serverNames, missingVars };\n}\n","sourceCodeStart":132,"sourceCodeEnd":162,"githubUrl":"https://github.com/coleam00/Archon/blob/0773b9745896ef0612e709c80845a0f7db315b19/packages/providers/src/mcp/config.ts#L132-L162","documentation":"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.","triggerScenarios":"loadMcpConfig on a file containing JSON5/JSONC syntax (comments, trailing commas), empty file, truncated write, or non-JSON content (YAML, TOML, shell script).","commonSituations":"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.","solutions":["Open the file at the position given in the detail message and fix the JSON syntax (remove comments/trailing commas/conflict markers).","Validate with a JSON linter or `node -e 'JSON.parse(require(\"fs\").readFileSync(p))'` before loading.","If the file is empty or half-written, restore it from backup or recreate it."],"exampleFix":"// before\n{\n  \"mcpServers\": { \"fs\": { \"command\": \"npx\" } }, // my servers\n}\n// after\n{\n  \"mcpServers\": { \"fs\": { \"command\": \"npx\" } }\n}","handlingStrategy":"validation","validationCode":"try {\n  JSON.parse(readFileSync(mcpPath, 'utf-8'));\n} catch (e) {\n  throw new Error(`${mcpPath} is not valid JSON: ${(e as Error).message}. Remove comments/trailing commas.`);\n}","typeGuard":null,"tryCatchPattern":"// try { await loadMcpConfig(p, cwd); }\n// catch (err) {\n//   if (err.message.includes('not valid JSON')) {\n//     console.error(`Fix JSON syntax in ${p}: ${err.message}`);\n//   } else throw err;\n// }","preventionTips":["Never put comments or trailing commas in .json files (use a .jsonc loader if you need them).","Add a JSON validation step to CI or a pre-commit hook.","Resolve merge conflicts in config files before running; search for conflict markers."],"tags":["json","parse","config","mcp"],"backgroundTag":"invalid-json","analyzedSha":"0773b9745896ef0612e709c80845a0f7db315b19","analyzedAt":"2026-09-01T02:28:07.064Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}