{"record":{"id":"8054b5f7dfebeda7","repo":"modelcontextprotocol/servers","slug":"parent-directory-does-not-exist-parentdir","errorCode":null,"errorMessage":"Parent directory does not exist: ${parentDir}","messagePattern":"Parent directory does not exist: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/filesystem/lib.ts","lineNumber":135,"sourceCode":"    const normalizedReal = normalizePath(realPath);\n    if (!isPathWithinAllowedDirectories(normalizedReal, allowedDirectories)) {\n      throw new Error(`Access denied - symlink target outside allowed directories: ${realPath} not in ${allowedDirectories.join(', ')}`);\n    }\n    return realPath;\n  } catch (error) {\n    // Security: For new files that don't exist yet, verify parent directory\n    // This ensures we can't create files in unauthorized locations\n    if ((error as NodeJS.ErrnoException).code === 'ENOENT') {\n      const parentDir = path.dirname(absolute);\n      try {\n        const realParentPath = await fs.realpath(parentDir);\n        const normalizedParent = normalizePath(realParentPath);\n        if (!isPathWithinAllowedDirectories(normalizedParent, allowedDirectories)) {\n          throw new Error(`Access denied - parent directory outside allowed directories: ${realParentPath} not in ${allowedDirectories.join(', ')}`);\n        }\n        return absolute;\n      } catch {\n        throw new Error(`Parent directory does not exist: ${parentDir}`);\n      }\n    }\n    throw error;\n  }\n}\n\n\n// File Operations\nexport async function getFileStats(filePath: string): Promise<FileInfo> {\n  const stats = await fs.stat(filePath);\n  return {\n    size: stats.size,\n    created: stats.birthtime,\n    modified: stats.mtime,\n    accessed: stats.atime,\n    isDirectory: stats.isDirectory(),\n    isFile: stats.isFile(),\n    permissions: stats.mode.toString(8).slice(-3),","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/modelcontextprotocol/servers/blob/76d64c822f5125032f89eb71dbdb94e42b434821/src/filesystem/lib.ts#L117-L153","documentation":"Thrown by `validatePath` when the target file does not exist (ENOENT) AND its parent directory also does not exist (realpath of the parent throws). This distinguishes a legitimate new-file creation (parent exists) from an impossible one (parent missing), preventing creation cascades into nonexistent locations.","triggerScenarios":"Calling a write/create tool with a path whose parent directory does not exist on disk — e.g. `write_file({ path: '/home/me/projects/nested/deep/x.txt' })` when `nested/deep` was never created.","commonSituations":"Forgetting to `create_directory` first, typos in intermediate path segments, or assuming a directory exists when it doesn't. The catch-all around the parent realpath turns any failure (including ENOENT of the parent) into this message.","solutions":["Create the parent directory first with `create_directory`, then write the file.","Verify the full parent path exists before issuing the write.","Check for typos in intermediate directory names."],"exampleFix":"// before\nwrite_file({ path: '/home/me/projects/new/sub/x.txt', content: 'hi' })\n// after\ncreate_directory({ path: '/home/me/projects/new/sub' })\nwrite_file({ path: '/home/me/projects/new/sub/x.txt', content: 'hi' })","handlingStrategy":"validation","validationCode":"import fs from 'node:fs/promises';\nasync function parentExists(p: string): Promise<boolean> {\n  try { await fs.access(path.dirname(p)); return true; } catch { return false; }\n}\nif (!await parentExists(args.path)) {\n  await callTool('create_directory', { path: path.dirname(args.path) });\n}","typeGuard":null,"tryCatchPattern":"try {\n  await writeFile({ path, content });\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('Parent directory does not exist')) {\n    await createDirectory({ path: dirname(path) });\n    await writeFile({ path, content });\n  }\n}","preventionTips":["Create parent directories with create_directory before writing files.","Verify the full parent path exists before issuing writes.","Check intermediate path segments for typos."],"tags":["mcp","typescript","filesystem-server","validation","filesystem","enoent"],"backgroundTag":null,"analyzedSha":"76d64c822f5125032f89eb71dbdb94e42b434821","analyzedAt":"2026-08-12T10:02:41.718Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}