{"record":{"id":"775885188df9fcef","repo":"JuliusBrussee/caveman","slug":"could-not-remove-caveman-cloud-mcp-for-agent","errorCode":null,"errorMessage":"could not remove caveman-cloud MCP for ${agent}","messagePattern":"could not remove caveman-cloud MCP for (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":2379,"sourceCode":"}\n\nfunction installAgentNativeCloudMcp(agent: \"claude\" | \"codex\", mcp: { command: string; args: string[] }): void {\n  if (agentNativeCloudMcpMatches(agent, mcp)) {\n    writeMcpServerMarker(agent, \"caveman-cloud\", mcp, \"caveman_context\");\n    return;\n  }\n  const installed = agent === \"claude\"\n    ? installMcpJson(join(homedir(), \".claude.json\"), [\"mcpServers\", \"caveman-cloud\"], { command: mcp.command, args: mcp.args })\n    : installMcpForAgent(findAgent(agent)!, mcp, \"caveman-cloud\");\n  if (!installed) throw new Error(`could not install caveman-cloud MCP for ${agent}`);\n  writeMcpServerMarker(agent, \"caveman-cloud\", mcp, \"caveman_context\");\n}\n\nfunction uninstallAgentNativeCloudMcp(agent: \"claude\" | \"codex\"): void {\n  const removed = agent === \"claude\"\n    ? removeMcpJson(join(homedir(), \".claude.json\"), [\"mcpServers\", \"caveman-cloud\"])\n    : uninstallMcpForAgent(findAgent(agent)!, \"caveman-cloud\");\n  if (!removed) throw new Error(`could not remove caveman-cloud MCP for ${agent}`);\n  try { unlinkSync(mcpServerMarkerPath(agent, \"caveman-cloud\")); } catch (error) {\n    if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;\n  }\n}\n\nfunction agentNativeSkillFiles(agent: \"claude\" | \"codex\"): Array<{ name: string; file: string; body: string }> {\n  const names = AGENT_SKILL_SUITES[\"agent-native\"] ?? [];\n  const root = agent === \"claude\" ? join(homedir(), \".claude\", \"skills\") : join(homedir(), \".codex\", \"skills\");\n  return names.map((name) => ({ name, file: join(root, name, \"SKILL.md\"), body: SKILLS[name]! }));\n}\n\nfunction restoreAgentNativeBundleSkills(skills: AgentNativeBundleSkill[]): void {\n  for (const skill of [...skills].reverse()) {\n    const before = skill.before_base64 === null ? null : Buffer.from(skill.before_base64, \"base64\");\n    if (before) atomicWriteFile(skill.file, before);\n    else {\n      try { unlinkSync(skill.file); } catch (error) {\n        if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") throw error;","sourceCodeStart":2361,"sourceCodeEnd":2397,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/27d5a3981a347890211bb1bf2439e5c821a63bc9/packages/cli/src/index.ts#L2361-L2397","documentation":"The mirror of error 328 for uninstall: uninstallAgentNativeCloudMcp() tries removeMcpJson (~/.claude.json mcpServers.caveman-cloud) or uninstallMcpForAgent (codex) and throws when the removal helper reports it could not perform the deletion. The marker file cleanup afterwards only tolerates ENOENT, so a failed removal is fatal rather than silently leaving stale state.","triggerScenarios":"Uninstalling the agent-native bundle when ~/.claude.json or ~/.codex/config.toml is unreadable, unwritable, or malformed, so the mcpServers entry cannot be deleted.","commonSituations":"Read-only home dir; config file corrupted by another tool; running uninstall concurrently with the agent app rewriting its own config.","solutions":["Verify the agent config file is valid and writable","Close the agent app so it is not rewriting the config mid-uninstall","Manually delete the caveman-cloud entry from mcpServers (Claude) or the [mcp_servers.caveman-cloud] table (Codex) and re-run uninstall to finish marker cleanup"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"function agentConfigRemovable(path: string, isClaude: boolean): boolean {\n  try {\n    const raw = readFileSync(path, \"utf8\");\n    if (isClaude) JSON.parse(raw);\n    accessSync(path, constants.W_OK);\n    return true;\n  } catch { return false; }\n}","typeGuard":"function isMcpRemoveError(e: unknown): boolean {\n  return e instanceof Error && e.message.startsWith(\"could not remove caveman-cloud MCP for \");\n}","tryCatchPattern":"try {\n  runCavemanUninstall();\n} catch (e) {\n  if (isMcpRemoveError(e)) {\n    // remove the caveman-cloud entry by hand, then re-run uninstall to clean the marker\n  } else throw e;\n}","preventionTips":["Ensure the agent app is closed before uninstall so it is not rewriting its config","Keep agent config files owned and writable by your user","Remove MCP entries through caveman commands so markers and host state stay in sync"],"tags":["mcp","uninstall","config","agent-native"],"backgroundTag":null,"analyzedSha":"27d5a3981a347890211bb1bf2439e5c821a63bc9","analyzedAt":"2026-08-15T09:26:11.751Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}