# Path set hierarchy tree

`path-set-hierarchy-tree` · version 1.0.0 · File paths (lexical) · free, no key needed

Transform a flat array of file paths into a nested deterministic directory tree structure.

**Use when you need to: path hierarchy tree · build directory tree from paths · path list to tree.**

## Supported

- path hierarchy tree
- build directory tree from paths
- path list to tree

## Not supported

- stat file
- filesystem access
- readdir

## Behavior

- Build a nested directory tree from a flat path list. Directories have children; files are leaves. Prototype-safe (uses Map internally). Deduplicates paths before building.

## Input

- `paths` (array of string, required): max items 5000
- `format` (one of "posix", "windows", "auto", optional)
- `sort_children` (boolean, optional)

## Output

- `tree` (array of any, optional)
- `format` (string, optional)

## Limits

- max paths: 5000
- max path bytes: 4096
- max tree depth: 64

## Example

Request input:

```json
{
  "paths": [
    "src/index.ts",
    "src/utils/helper.ts",
    "README.md"
  ]
}
```

Response:

```json
{
  "result": {
    "tree": [
      {
        "name": "src",
        "type": "directory",
        "children": [
          {
            "name": "utils",
            "type": "directory",
            "children": [
              {
                "name": "helper.ts",
                "type": "file"
              }
            ]
          },
          {
            "name": "index.ts",
            "type": "file"
          }
        ]
      },
      {
        "name": "README.md",
        "type": "file"
      }
    ],
    "format": "posix"
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "path-set-hierarchy-tree",
  "version": "1.0.0",
  "input": {
    "paths": [
      "src/index.ts",
      "src/utils/helper.ts",
      "README.md"
    ]
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/path-set-hierarchy-tree/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"paths":["src/index.ts","src/utils/helper.ts","README.md"]}'
```

The machine-readable contract is at [/v1/tools/path-set-hierarchy-tree/versions/1.0.0](/v1/tools/path-set-hierarchy-tree/versions/1.0.0).

### CLI

```sh
node cli.mjs run path-set-hierarchy-tree 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [Path set partition directory](/tools/path-set-partition-directory): Partition an array of file paths into buckets grouped by parent directory or directory at a specified depth.
- [Path set prefix strip](/tools/path-set-prefix-strip): Strip a common directory prefix or base path from an array of paths lexically.
- [Path lexical relative](/tools/path-lexical-relative): Compute the lexical relative path from one path to another without filesystem access.
- [Path set classify](/tools/path-set-classify): Classify an array of file paths by file extension, depth histogram, and path format.
- [Path set dedupe](/tools/path-set-dedupe): Deduplicate an array of paths based on lexical equivalence while preserving first or last seen order.
- [Path set difference](/tools/path-set-difference): Compute the set difference (A \ B) of two path collections using lexical path equivalence.
