Skip to content

fix(setup): refuse to overwrite unparseable JSON MCP config - #414

Open
HeyImBG wants to merge 1 commit into
AVIDS2:mainfrom
HeyImBG:fix/setup-invalid-json-overwrite
Open

HeyImBG wants to merge 1 commit into
AVIDS2:mainfrom
HeyImBG:fix/setup-invalid-json-overwrite

Conversation

@HeyImBG

@HeyImBG HeyImBG commented Nov 29, 2026

Copy link
Copy Markdown

What was wrong

installMcpConfig → mergeJsonMcpConfig (src/cli/commands/setup.ts) treated an existing config file that is not valid JSON as {}, then rewrote the file with only the memorix entry. A common case is opencode.json with JSONC comments or a trailing comma: memorix setup silently deleted all of the user's other settings in it.

What changed

If the existing content cannot be parsed, or is not a JSON object, setup now throws a clear error and leaves the file untouched. An empty file still works as before.

How it was tested

  • New test in tests/cli/setup-command.test.ts: setup rejects a JSONC opencode.json and leaves it unchanged. It fails on main ("promise resolved ... instead of rejecting") and passes with the fix; the file is 43/43.
  • After npm install && npm run build, full npm test: 3366 passed, 5 skipped, 0 failed.

Side effect to note: when setup runs for several agents in one go, it now stops at the first unparseable file instead of overwriting it.

AI disclosure

This change was found, written and tested with Claude Code (Anthropic). I'm responsible for it and happy to rework anything.


🤖 Generated with Claude Code

https://claude.ai/code/session_01A3CSud8Qn852zfCa7YofiN

mergeJsonMcpConfig treated invalid existing JSON (JSONC comments, trailing
commas) as empty and rewrote the file with only the memorix entry, silently
deleting the user's other settings. Throw instead and leave the file intact.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant