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

Function removeMcpEntryAt

src/installer/targets/opencode.ts:273–316  ·  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

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