root_mcp.common.utils module

Common utility functions.

root_mcp.common.utils.ensure_path_exists(path)[source]

Ensure a path exists, creating parent directories if needed.

Parameters:

path (str | Path) – Path to ensure exists

Returns:

Path object

Return type:

Path

root_mcp.common.utils.format_bytes(size_bytes)[source]

Format bytes as human-readable string.

Parameters:

size_bytes (int) – Size in bytes

Returns:

Formatted string (e.g., “1.5 MB”)

Return type:

str

root_mcp.common.utils.sanitize_filename(filename)[source]

Sanitize a filename by removing/replacing invalid characters.

Parameters:

filename (str) – Original filename

Returns:

Sanitized filename

Return type:

str