Skip to content

fix(filesystem): allow create_directory to create nested parent directories - #4697

Open
AbhiPra24 wants to merge 1 commit into
modelcontextprotocol:mainfrom
AbhiPra24:fix/filesystem-create-directory-nested-parents
Open

fix(filesystem): allow create_directory to create nested parent directories#4697
AbhiPra24 wants to merge 1 commit into
modelcontextprotocol:mainfrom
AbhiPra24:fix/filesystem-create-directory-nested-parents

Conversation

@AbhiPra24

Copy link
Copy Markdown

Description

Fixes #4629.

The tool description and documentation for create_directory explicitly state that it can create multiple nested directories in one operation ("Creates parent directories if needed", "Can create multiple nested directories in one operation"). However, validatePath() rejected paths when their immediate parent did not yet exist with "Parent directory does not exist: <path>".

This PR adds an allowMissingParents parameter to validatePath() (defaulting to false for other file operations to maintain strict behavior). When enabled for create_directory, validatePath() securely verifies all ancestors up to the closest existing directory against the allowed directories list, ensuring path security is maintained while allowing fs.mkdir(validPath, { recursive: true }) to create intermediate directories as documented.

Changes

  • Update validatePath in src/filesystem/lib.ts to accept allowMissingParents: boolean = false and securely walk up to the nearest existing ancestor.
  • Update create_directory in src/filesystem/index.ts to pass allowMissingParents = true.
  • Add unit test in src/filesystem/__tests__/lib.test.ts verifying allowMissingParents: true succeeds for nested non-existent directory hierarchies within allowed roots.

Verification

  • Ran npm test and npm run build in src/filesystem. All 153 tests pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

server-filesystem: create_directory does not create parent directories

1 participant