Skip to content

feat: Add tree tool to generate hierarchical directory structures #8

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tomholford
Copy link

This PR adds a new tree tool that generates a hierarchical JSON representation of directory structures. It provides both human-readable output and AI-friendly structured data that can be analyzed and traversed programmatically.

Implementation Details

  • Added a FileNode struct to represent nodes in the directory tree
  • Implemented a recursive buildTree method that traverses directories
  • Added configurability through optional parameters:
    • depth: Controls traversal depth (default: 3)
    • follow_symlinks: Controls symlink handling (default: false)
  • Each node includes rich metadata (path, size, type, modification time)
  • Security measures:
    • Respects allowed directory boundaries
    • Validates symlink targets before following
    • Skips problematic files instead of failing
  • Returns results as formatted JSON via both text content and embedded resource

User Experience

Example usage:

Claude: Show me the structure of my /projects directory with a depth of 2.
MCP: [Calls tree tool with path="/projects", depth=2]

The tool returns a structured JSON representation that both:

  1. Shows in the conversation as formatted text
  2. Is available as an embedded resource for programmatic use

Documentation

Updated the README.md to include:

  • New tool capabilities in the feature list
  • Detailed documentation for the tree tool
  • Parameter descriptions and default values

@tomholford tomholford marked this pull request as ready for review March 23, 2025 01:06
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