JuliusBrussee/caveman · error · Error
MCP config path contains dangling symlink
Error message
MCP config path contains dangling symlink ${ancestor}; refusing mutation What it means
When resolving the real path of an MCP config file whose ancestors may not exist yet, the CLI walks up the directory chain with realpathSync. If an existing ancestor is a dangling symlink (realpath fails and lstat says it is a symlink), the CLI refuses to mutate the config to avoid creating files in an unintended location or following a broken link.
Solutions
- Find the dangling link: `find <parent-dir> -xtype l` and either remove it or re-point it to an existing target
- Recreate the symlink's target directory if it should exist, then re-run the MCP command
- Replace the symlink with a real directory (copy contents, remove link) if the indirection is no longer needed
Example fix
# before $ ls -l ~/.config/kilo kilo -> /mnt/old-drive/kilo # target gone # after $ rm ~/.config/kilo && mkdir -p ~/.config/kilo
Defensive patterns
Strategy: validation
Validate before calling
import { realpathSync, lstatSync } from "node:fs";
const dir = dirname(configPath);
try { realpathSync(dir); } catch {
let a = dir;
while (a !== dirname(a)) {
try { if (lstatSync(a).isSymbolicLink()) throw new Error(`dangling symlink at ${a}`); } catch (e) { if ((e as any).code !== "ENOENT") throw e; }
a = dirname(a);
}
} Try / catch
try {
await addMcpServer(name, config);
} catch (e) {
if ((e as Error).message.includes("dangling symlink")) {
const link = (e as Error).message.match(/symlink (\S+);/)?.[1];
console.error(`Remove or repair the link at ${link}: find $(dirname ${link}) -xtype l`);
} else throw e;
} Prevention
- Periodically run `find ~/.config -xtype l` to detect dangling symlinks
- Ensure symlink targets (external drives, other volumes) are mounted before CLI use
- Prefer real directories over symlinked config roots for agent configs
- Restore backups with links re-pointed to valid targets
When it happens
Trigger: Adding/removing an MCP server whose config path contains a symlinked ancestor whose target no longer exists — realpathSync throws ENOENT, lstat confirms a symlink, and this error is thrown. Also rethrown for non-ENOENT lstat errors at that ancestor.
Common situations: Dotfile managers symlinking ~/.config/agent to a target that was deleted or on an unmounted volume; restoring a home directory where link targets moved; deleted external drives holding symlinked config trees.
Understand the failure class
Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.
Related errors
- caveman build: package artifact symlink is not lockable
- caveman build: source graph symlink escapes project root
- failed to canonicalize CODEX_HOME
- is a symlink; refusing transactional ownership mutation
- resolve sqlite parent
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/51eb5606b8c9f2c3.
Report an issue: GitHub.
Appendix: source
Thrown at packages/cli/src/index.ts:11237
agent: "kilo" | "qwen";
path: string;
before: Buffer | null;
beforeMode: number;
after: Buffer | null;
changed: boolean;
};
function canonicalMcpConfigPath(path: string): string {
const absolute = normalize(resolve(path));
const missing: string[] = [];
let ancestor = absolute;
while (true) {
try {
return normalize(join(realpathSync(ancestor), ...missing));
} catch {
try {
if (lstatSync(ancestor).isSymbolicLink()) {
throw new Error(`MCP config path contains dangling symlink ${ancestor}; refusing mutation`);
}
} catch (error) {
if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
}
const parent = dirname(ancestor);
if (parent === ancestor) return absolute;
missing.unshift(basename(ancestor));
ancestor = parent;
}
}
}
function ownedMcpConfigPlan(
agent: "kilo" | "qwen",
path: string,
loaded: { bytes: Buffer | null; exists: boolean },
after: Buffer | null,
): OwnedMcpConfigPlan {View on GitHub (pinned to 3ee70a1026)