MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / writeMcpEntry

Function writeMcpEntry

src/installer/targets/claude.ts:230–252  ·  view source on GitHub ↗
(loc: Location)

Source from the content-addressed store, hash-verified

228 * cause side effects callers don't expect.
229 */
230export 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

Callers 2

writeMcpConfigFunction · 0.90
installMethod · 0.70

Calls 5

readJsonFileFunction · 0.90
getMcpServerConfigFunction · 0.90
jsonDeepEqualFunction · 0.90
writeJsonFileFunction · 0.90
mcpJsonPathFunction · 0.70

Tested by

no test coverage detected