Skip to content

feat(filesystem): add maxDepth parameter to directory_tree#4023

Open
factspark23-hash wants to merge 1 commit intomodelcontextprotocol:mainfrom
factspark23-hash:feat/directory-tree-max-depth
Open

feat(filesystem): add maxDepth parameter to directory_tree#4023
factspark23-hash wants to merge 1 commit intomodelcontextprotocol:mainfrom
factspark23-hash:feat/directory-tree-max-depth

Conversation

@factspark23-hash
Copy link
Copy Markdown

What

Add an optional maxDepth parameter to the directory_tree tool that limits recursive traversal depth.

Why

When exploring large monorepos, deep node_modules trees, or complex project structures, the full recursive tree can be:

  • Slow — thousands of entries take seconds to enumerate
  • Overwhelming — produces massive JSON output that wastes context window
  • Unnecessary — often you only need 2-3 levels deep

How

  • maxDepth=0 — shows only root directory entries (no subdirectories expanded)
  • maxDepth=1 — root + immediate children
  • maxDepth=N — N levels deep
  • Omit for unlimited depth (backward compatible, no behavior change)

Directories at the max depth boundary are shown with empty children: [] arrays, preserving tree structure.

Changes

  • src/filesystem/index.ts:
    • Added maxDepth to DirectoryTreeArgsSchema (optional, int, min 0)
    • Updated buildTree() to track and limit depth
    • Updated tool description to document the new parameter

Limits recursive traversal depth when exploring directory trees.
- maxDepth=0 shows only root directory entries
- maxDepth=1 shows root + immediate children
- Omit for unlimited depth (backward compatible)

Useful for large monorepos or deep node_modules trees where
full traversal is slow and produces overwhelming output.
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.

1 participant