(loc: Location)
| 228 | * cause side effects callers don't expect. |
| 229 | */ |
| 230 | export function writeMcpEntry(loc: Location): WriteResult['files'][number] { |
| 231 | const file = mcpJsonPath(loc); |
| 232 | const existing = readJsonFile(file); |
| 233 | const before = existing.mcpServers?.codegraph; |
| 234 | const after = getMcpServerConfig(); |
| 235 | |
| 236 | if (jsonDeepEqual(before, after)) { |
| 237 | // Already exactly what we'd write — preserve byte-identical file. |
| 238 | return { path: file, action: 'unchanged' }; |
| 239 | } |
| 240 | // 'created' here means: the file itself did not exist before this |
| 241 | // write. A pre-existing MCP JSON file (`~/.claude.json` globally, |
| 242 | // `./.mcp.json` locally) containing other MCP servers (no |
| 243 | // `codegraph` key) is 'updated', not 'created' — we're adding an |
| 244 | // entry to a file that was already there. Codex uses a different |
| 245 | // idiom (empty-content => 'created') because its config.toml is |
| 246 | // ours alone to manage. |
| 247 | const action: 'created' | 'updated' = before ? 'updated' : (fs.existsSync(file) ? 'updated' : 'created'); |
| 248 | if (!existing.mcpServers) existing.mcpServers = {}; |
| 249 | existing.mcpServers.codegraph = after; |
| 250 | writeJsonFile(file, existing); |
| 251 | return { path: file, action }; |
| 252 | } |
| 253 | |
| 254 | /** |
| 255 | * Strip the codegraph entry from a legacy project-local |
no test coverage detected