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

Function removeMcpEntryAt

src/installer/targets/opencode.ts:270–313  ·  view source on GitHub ↗

* Surgically drop our CodeGraph entry from one config file — either the * OpenCode 2 native `mcp.servers.codegraph` or a pre-#1698 `mcp.codegraph`. * Leaves sibling servers, comments, and formatting untouched; drops emptied * `mcp.servers` / `mcp` wrappers too. Shared by uninstall and the * lega

(file: string)

Source from the content-addressed store, hash-verified

268 * legacy-%APPDATA% sweep.
269 */
270function removeMcpEntryAt(file: string): WriteResult['files'][number] {
271 if (!fs.existsSync(file)) return { path: file, action: 'not-found' };
272 let text = readConfigText(file);
273 const config = parseConfig(text);
274 if (!hasCodegraphEntry(config)) return { path: file, action: 'not-found' };
275
276 let updated = text;
277 if (config.mcp?.servers?.codegraph) {
278 const edits = modify(updated, ['mcp', 'servers', 'codegraph'], undefined, {
279 formattingOptions: FORMATTING,
280 });
281 updated = applyEdits(updated, edits);
282 }
283 // Re-parse after the native removal so a file that held BOTH shapes
284 // (unusual, but possible mid-migration) still drops the v1 leftover.
285 const mid = parseConfig(updated);
286 if (mid.mcp?.codegraph) {
287 const edits = modify(updated, ['mcp', 'codegraph'], undefined, {
288 formattingOptions: FORMATTING,
289 });
290 updated = applyEdits(updated, edits);
291 }
292
293 // If `mcp.servers` is now an empty object, drop that wrapper.
294 let afterParsed = parseConfig(updated);
295 if (afterParsed.mcp?.servers && typeof afterParsed.mcp.servers === 'object' &&
296 Object.keys(afterParsed.mcp.servers).length === 0) {
297 const edits = modify(updated, ['mcp', 'servers'], undefined, {
298 formattingOptions: FORMATTING,
299 });
300 updated = applyEdits(updated, edits);
301 afterParsed = parseConfig(updated);
302 }
303
304 // If `mcp` is now an empty object, drop the wrapper too.
305 if (afterParsed.mcp && typeof afterParsed.mcp === 'object' &&
306 Object.keys(afterParsed.mcp).length === 0) {
307 const edits = modify(updated, ['mcp'], undefined, { formattingOptions: FORMATTING });
308 updated = applyEdits(updated, edits);
309 }
310
311 atomicWriteFileSync(file, updated);
312 return { path: file, action: 'removed' };
313}
314
315/**
316 * Remove whatever a pre-#535 install left in `%APPDATA%/opencode` — an MCP

Callers 2

uninstallMethod · 0.85

Calls 5

atomicWriteFileSyncFunction · 0.90
hasCodegraphEntryFunction · 0.85
applyEditsFunction · 0.85
readConfigTextFunction · 0.70
parseConfigFunction · 0.70

Tested by

no test coverage detected