Path lexical common ancestor
path-lexical-common-ancestor · version 1.0.0 · File paths (lexical) · free, no key needed
Compute the deepest common ancestor directory of a set of paths.
Use when you need to: common ancestor · longest common path prefix · shared ancestor directory.
Supported
- common ancestor
- longest common path prefix
- shared ancestor directory
Not supported
- stat file
- resolve symlinks
- filesystem access
Behavior
- Compute deepest common ancestor directory by comparing normalized segments.
- ancestor is common prefix directory path, or null if no common prefix.
- depth is number of common directory segments (0 if no common prefix).
- Windows: case-insensitive segment comparison. POSIX: case-sensitive.
- Paths on different drives return {ancestor:null,format:"windows",depth:0}.
- Single path input: ancestor is the parent directory of that path.
Input
paths(array of string, required): min items 1; max items 500; each min length 1; each max length 4096format(one of "posix", "windows", "auto", optional)
Output
ancestor(string or null, required)format(one of "posix", "windows", required)depth(integer, required): min 0
Limits
- max paths: 500
- max path bytes: 4096
Example
Request input:
{
"paths": [
"/a/b/c",
"/a/b/d",
"/a/b/e/f"
]
}
Response:
{
"result": {
"ancestor": "/a/b",
"format": "posix",
"depth": 2
}
}
How to call it
MCP
Connect https://computefirst.net/mcp (setup), then call execute with:
{
"id": "path-lexical-common-ancestor",
"version": "1.0.0",
"input": {
"paths": [
"/a/b/c",
"/a/b/d",
"/a/b/e/f"
]
}
}
HTTP (no key)
curl -X POST https://computefirst.net/v1/tools/path-lexical-common-ancestor/versions/1.0.0/execute \
-H "Content-Type: application/json" \
-d '{"paths":["/a/b/c","/a/b/d","/a/b/e/f"]}'
The machine-readable contract is at /v1/tools/path-lexical-common-ancestor/versions/1.0.0.
CLI
node cli.mjs run path-lexical-common-ancestor 1.0.0 --input input.json --base-url https://computefirst.net
Get the client at /clients/cli/.
Related tools
- Path lexical contains: Check whether a child path is lexically inside a parent directory.
- Path set prefix strip: Strip a common directory prefix or base path from an array of paths lexically.
- Path lexical join: Join an array of path segments lexically, resolving absolute reset boundaries and normalizing separators.
- Path lexical normalize: Normalize a path lexically: collapse redundant separators, resolve "." and ".." segments.
- Path lexical parse: Decompose a file path into its lexical components without accessing the filesystem.
- Path lexical relative: Compute the lexical relative path from one path to another without filesystem access.