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

Function writeMcpEntry

src/installer/targets/codex.ts:144–162  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

142}
143
144function writeMcpEntry(): WriteResult['files'][number] {
145 const file = tomlConfigPath();
146 const dir = path.dirname(file);
147 if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
148
149 const block = buildCodegraphBlock();
150 // Single read — `existing === ''` derives both "is the file empty
151 // or absent" and "what was its content," avoiding a TOCTOU window
152 // between two `fs.existsSync` calls.
153 const existing = fs.existsSync(file) ? fs.readFileSync(file, 'utf-8') : '';
154 const created = existing.length === 0;
155 const { content: nextContent, action } = upsertTomlTable(existing, TOML_HEADER, block);
156
157 if (action === 'unchanged') {
158 return { path: file, action: 'unchanged' };
159 }
160 atomicWriteFileSync(file, nextContent);
161 return { path: file, action: created ? 'created' : 'updated' };
162}
163
164/**
165 * Strip the marker-delimited CodeGraph block from `~/.codex/AGENTS.md`

Callers 1

installMethod · 0.70

Calls 4

upsertTomlTableFunction · 0.90
atomicWriteFileSyncFunction · 0.90
tomlConfigPathFunction · 0.85
buildCodegraphBlockFunction · 0.85

Tested by

no test coverage detected