Skip to main content

Module roots

Module roots 

Source

Functions§

best_root_from_uris
Select the best project root from MCP client roots. Only considers paths that are existing directories. Prefers roots with project markers (.git, Cargo.toml, etc.). Falls back to the first valid directory if none have markers — but never accepts a broad/unsafe root (HOME, filesystem root, agent sandbox dirs), which would otherwise contaminate sessions across projects.
root_from_env
Detect project root from IDE-specific environment variables. Priority: LEAN_CTX_PROJECT_ROOT > CLAUDE_PROJECT_DIR
uri_to_path
Parse a file:// URI to a validated local path string. Rejects non-file URIs, null bytes, .. traversal, and non-directory paths. Returns a canonicalized absolute path.
valid_dir_paths_from_uris
Filter and validate URIs to existing directories only.