-
Notifications
You must be signed in to change notification settings - Fork 225
feat(mcp): add list_tree tool #870
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(mcp): add list_tree tool #870
Conversation
This tool allows an agent to list files and directories from a repository path. This can be used as a simple directory listing tool or for a directory tree tool by specifying a depth > 1
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughAdds a new MCP tool Changes
Sequence DiagramsequenceDiagram
participant Client as MCP Client
participant Server as MCP Server
participant TreeAPI as Tree API (/api/tree)
Client->>Server: list_tree(request: repo,path,ref,depth,filters,maxEntries)
Server->>Server: normalizeTreePath(path)
Server->>Server: enforceBounds(depth,maxEntries)
alt includeFiles OR includeDirectories
Server->>TreeAPI: POST /api/tree (breadth-first per depth)
TreeAPI-->>Server: tree nodes
Server->>Server: buildTreeNodeIndex(nodes)
Server->>Server: extract, dedupe, filter entries
Server->>Server: sortTreeEntries(entries)
Server->>Server: truncateWhenMaxReached()
else both filters false
Server->>Server: return empty entries
end
Server-->>Client: ListTreeResponse(entries,totalReturned,truncated)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
58af192 to
da2ca8a
Compare
| } | ||
| ); | ||
|
|
||
| server.tool( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach makes sense for the apis that we expose, and I'm happy to ship this. For context,/api/tree is designed around the file tree viewer in the code browser, and is why we accept a list of paths (representing open directories) and return a tree spanning the union.
An alternative, potentially simpler, approach I was going to suggest is that we could use ls-tree with -r to recurse from a specified path. It does not accept a max depth unfortunately, so we would need to truncate the output to the specified depth. Perf is ok (because of #791), even on large repos like UnrealEngine:
> UnrealEngine git:(release) time git ls-tree -r HEAD . > /dev/null
git ls-tree -r HEAD . > /dev/null 0.10s user 0.02s system 94% cpu 0.125 total
Regardless of the approach, we will want to move this api surface into the server s.t., we can also add a list_tree tool to the Ask agent. I'll leave that for a follow-up PR that I can open later this week.
This PR adds a
list_treetool to the MCP package. This tool allows an agent to list files and directories from a repository path. This can be used as a simple directory listing tool or for a directory tree tool by specifying a depth > 1Summary by CodeRabbit
New Features
Documentation
Bug Fixes