Repository navigation
fix(mcp-migrator): handle malformed JSON in legacy .kilocode/mcp.json - #7012
Merged
marius-kilocode merged 1 commit intoMar 13, 2026
Conversation
readMcpSettings() called JSON.parse() without try/catch. In migrate(),
if .kilocode/mcp.json existed but contained malformed JSON, the uncaught
exception propagated out of the dual-read loop, preventing .kilo/mcp.json
from ever being read. The outer loadMcpConfig() catch returned {} instead
of the valid config — silently losing MCP server configuration.
Wrap the file read + parse in try/catch, log a warning, and return null
so the loop continues to the next config directory.
Regression tests added for both readMcpSettings (unit) and migrate
(integration) to prove the bug and verify the fix.
Refs: Kilo-Org#6881
Contributor
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (2 files)
Reviewed by gpt-5.4-20260305 · 79,842 tokens |
marius-kilocode
approved these changes
Mar 13, 2026
catrielmuller
approved these changes
Mar 13, 2026
jliounis
pushed a commit
to jliounis/kilocode
that referenced
this pull request
May 18, 2026
…Kilo-Org#7012) readMcpSettings() called JSON.parse() without try/catch. In migrate(), if .kilocode/mcp.json existed but contained malformed JSON, the uncaught exception propagated out of the dual-read loop, preventing .kilo/mcp.json from ever being read. The outer loadMcpConfig() catch returned {} instead of the valid config — silently losing MCP server configuration. Wrap the file read + parse in try/catch, log a warning, and return null so the loop continues to the next config directory. Regression tests added for both readMcpSettings (unit) and migrate (integration) to prove the bug and verify the fix. Refs: Kilo-Org#6881
t7tran
pushed a commit
to t7tran/kilocode
that referenced
this pull request
Aug 14, 2026
…Kilo-Org#7012) readMcpSettings() called JSON.parse() without try/catch. In migrate(), if .kilocode/mcp.json existed but contained malformed JSON, the uncaught exception propagated out of the dual-read loop, preventing .kilo/mcp.json from ever being read. The outer loadMcpConfig() catch returned {} instead of the valid config — silently losing MCP server configuration. Wrap the file read + parse in try/catch, log a warning, and return null so the loop continues to the next config directory. Regression tests added for both readMcpSettings (unit) and migrate (integration) to prove the bug and verify the fix. Refs: Kilo-Org#6881 Co-authored-by: marius-kiloclaw <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What's wrong
readMcpSettings()callsJSON.parse()without a try/catch. Inmigrate(), the function iterates over[".kilocode", ".kilo"]directories to load MCP config with a "later wins" precedence strategy. If.kilocode/mcp.jsonexists but contains malformed JSON, the uncaughtSyntaxErrorpropagates out of the loop, and.kilo/mcp.jsonis never read.The outer
loadMcpConfig()catches the error and returns{}— silently losing all valid MCP server configuration from.kilo/mcp.json.Scenario: User has a stale/corrupt
.kilocode/mcp.jsonleftover from a previous install, and a perfectly valid.kilo/mcp.json. Their MCP servers silently fail to load.The fix
Wrap the file read + JSON parse in
readMcpSettings()with a try/catch. On parse failure, log a warning with the filepath and error, then returnnullso the migration loop continues to the next directory.This is the minimal, correct fix — the function already returns
nullfor non-existent files, so returningnullfor unparseable files is consistent.Tests
Two regression tests added:
readMcpSettings): Verifies that a malformed JSON file returnsnullinstead of throwingmigrate): Writes malformed JSON to.kilocode/mcp.jsonand valid config to.kilo/mcp.json, then verifiesmigrate()successfully returns the valid.kiloconfigBoth tests fail without the fix and pass with it.
Found during automated review of #6881. cc @marius-kilocode