file_tree
Generate a visual directory tree structure with Git tracking information to analyze project organization and version control status.
Instructions
Lists directory tree structure with git tracking support
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"path": "<path>"
},
"name": "file_tree"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes |
Implementation Reference
- The core handler function for the 'file_tree' tool. Generates a directory tree visualization, optionally using git-tracked files or gitignore patterns to filter contents.
async def file_tree(self, path: str) -> tuple[str, int, int]: """Generate tree view of directory structure. Args: path: Root directory path Returns: Tree view as string """ path = await self.validate_path(path) base_path = path # Try git tracking first tracked_files = self._get_tracked_files(path) gitignore = self._load_gitignore(path) if tracked_files is None else [] def gen_tree(path: Path, prefix: str = "") -> tuple[list[str], int, int]: entries = [] dir_count = 0 file_count = 0 items = sorted(path.iterdir(), key=lambda x: (x.is_file(), x.name)) for i, item in enumerate(items): rel_path = str(item.relative_to(base_path)) # Skip if file should be ignored if tracked_files is not None: if rel_path not in tracked_files and not any(str(p.relative_to(base_path)) in tracked_files for p in item.rglob("*") if p.is_file()): continue else: # Use gitignore if self._should_ignore(rel_path, gitignore): continue is_last = i == len(items) - 1 curr_prefix = "└── " if is_last else "├── " curr_line = prefix + curr_prefix + item.name if item.is_dir(): next_prefix = prefix + (" " if is_last else "│ ") subtree, sub_dirs, sub_files = gen_tree(item, next_prefix) if tracked_files is not None and not subtree: continue entries.extend([curr_line] + subtree) dir_count += 1 + sub_dirs file_count += sub_files else: if tracked_files is not None and rel_path not in tracked_files: continue entries.append(curr_line) file_count += 1 return entries, dir_count, file_count tree_lines, _, _ = gen_tree(path) return "\n".join(tree_lines) - Pydantic schema/model defining the input for the file_tree tool: a path string.
class FileTree(BaseModel): path: str - src/mcp_server_code_assist/server.py:115-119 (registration)Tool registration in @server.list_tools(), defining name, description, and input schema for 'file_tree'.
Tool( name=CodeAssistTools.FILE_TREE, description="Lists directory tree structure with git tracking support", inputSchema=ListDirectory.model_json_schema(), ), - src/mcp_server_code_assist/server.py:191-194 (registration)Tool dispatch/execution handler in @server.call_tool() for 'file_tree', validating input with FileTree model and calling the file_tools.file_tree method.
case CodeAssistTools.FILE_TREE: model = FileTree(path=arguments["path"]) result = await file_tools.file_tree(model.path) return [TextContent(type="text", text=result)] - src/mcp_server_code_assist/server.py:25-25 (registration)Enum value definition for the 'file_tree' tool name in CodeAssistTools.
FILE_TREE = "file_tree"