Context7 Platform -- Up-to-date docs for AI agents
fix(cli): handle malformed MCP config files in remove detection (#2574)
Fahreddin Özcan6c71e4deb43f
diff --git a/.changeset/handle-mcp-config-detection-errors.md b/.changeset/handle-mcp-config-detection-errors.mdnew file mode 100644index 00000000..a906dce0--- /dev/null+++ b/.changeset/handle-mcp-config-detection-errors.md@@ -0,0 +1,5 @@+---+"ctx7": patch+---++Handle malformed MCP config files gracefully during `ctx7 remove` agent detection. Previously, an unparseable JSON config at any agent's well-known path (e.g. a hand-edited `~/.claude.json`) would crash the command with an unhandled `SyntaxError` before it could do anything. The detector now skips the offending file and logs a warning naming the path and parse error so the user can fix it, while detection continues for the remaining agents.diff --git a/packages/cli/src/commands/remove.ts b/packages/cli/src/commands/remove.tsindex 5ec08990..190cfcb8 100644--- a/packages/cli/src/commands/remove.ts+++ b/packages/cli/src/commands/remove.ts@@ -198,7 +198,15 @@ async function hasMcpConfig(agentName: SetupAgent, scope: Scope): Promise<booleareturn readTomlServerExists(mcpPath, "context7");}- const existing = await readJsonConfig(mcpPath);+ let existing: Record<string, unknown>;+ try {+ existing = await readJsonConfig(mcpPath);+ } catch (err) {+ log.warn(+ `Skipped ${mcpPath}: could not parse (${err instanceof Error ? err.message : String(err)})`+ );+ return false;+ }const section = existing[agent.mcp.configKey];return (!!section && typeof section === "object" && !Array.isArray(section) && "context7" in section