Path lexical relative
path-lexical-relative · version 1.0.0 · File paths (lexical) · free, no key needed
Compute the lexical relative path from one path to another without filesystem access.
Use when you need to: path relative · relative path · compute relative path from to.
Supported
- path relative
- relative path
- compute relative path from to
Not supported
- stat file
- resolve symlinks
- filesystem access
- cross-drive relative path
Behavior
- Compute relative path from "from" to "to" using lexicalRelative.
- same: true if from and to normalize to the same path.
- Cross-drive Windows paths and absolute/relative mismatches throw badInput.
- relative is empty string "" when from and to are same (same:true).
Input
from(string, required): min length 1; max length 4096to(string, required): min length 1; max length 4096format(one of "posix", "windows", "auto", optional)
Output
relative(string, required)format(one of "posix", "windows", required)same(boolean, required)
Limits
- max path bytes: 4096
Example
Request input:
{
"from": "/a/b",
"to": "/a/c/d"
}
Response:
{
"result": {
"relative": "../c/d",
"format": "posix",
"same": false
}
}
How to call it
MCP
Connect https://computefirst.net/mcp (setup), then call execute with:
{
"id": "path-lexical-relative",
"version": "1.0.0",
"input": {
"from": "/a/b",
"to": "/a/c/d"
}
}
HTTP (no key)
curl -X POST https://computefirst.net/v1/tools/path-lexical-relative/versions/1.0.0/execute \
-H "Content-Type: application/json" \
-d '{"from":"/a/b","to":"/a/c/d"}'
The machine-readable contract is at /v1/tools/path-lexical-relative/versions/1.0.0.
CLI
node cli.mjs run path-lexical-relative 1.0.0 --input input.json --base-url https://computefirst.net
Get the client at /clients/cli/.
Related tools
- Path lexical sanitize: Sanitize an untrusted path to produce a safe relative path, stripping roots, drive letters, traversal segments, and illegal characters.
- Path set hierarchy tree: Transform a flat array of file paths into a nested deterministic directory tree structure.
- Path format convert: Convert file paths between POSIX and Windows formats, handling slashes, drive letters, and roots lexically.
- Path lexical common ancestor: Compute the deepest common ancestor directory of a set of paths.
- Path lexical contains: Check whether a child path is lexically inside a parent directory.
- Path lexical join: Join an array of path segments lexically, resolving absolute reset boundaries and normalizing separators.