Skip to content

Fix create_directory for nested paths with non-existent parents - #4679

Open
sachinsharma3191 wants to merge 1 commit into
modelcontextprotocol:mainfrom
sachinsharma3191:fix/4629-create-directory-recursive
Open

Fix create_directory for nested paths with non-existent parents#4679
sachinsharma3191 wants to merge 1 commit into
modelcontextprotocol:mainfrom
sachinsharma3191:fix/4629-create-directory-recursive

Conversation

@sachinsharma3191

Copy link
Copy Markdown

Summary

Fixes #4629

  • Added ValidatePathOptions interface with allowNonExistentAncestors flag to validatePath()
  • When the flag is set, walks up via path.dirname() to find the first existing ancestor and validates it against allowed directories
  • create_directory handler now passes { allowNonExistentAncestors: true } so mkdir -p style recursive creation works correctly
  • 4 new tests covering: allowed deep paths, paths outside allowed dirs, default behavior unchanged, and root walkup exhaustion

Test plan

  • create_directory with nested non-existent parents succeeds when ancestor is in allowed dirs
  • create_directory still rejects paths outside allowed directories
  • Default validatePath() behavior (without flag) unchanged — existing tests pass
  • All 54 tests pass

…tories

validatePath() now accepts an `allowNonExistentAncestors` option that walks
up using path.dirname() until it finds an existing ancestor directory, then
validates that ancestor against the allowed directories list. This enables
recursive mkdir (mkdir -p) to work when multiple levels of parent directories
don't exist yet, matching the documented behavior of create_directory.

Fixes modelcontextprotocol#4629
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