root_mcp.common package

Common utilities shared between core and extended modes.

exception root_mcp.common.AnalysisError[source]

Bases: ROOTMCPError

Raised when analysis operations fail.

exception root_mcp.common.FileOperationError[source]

Bases: ROOTMCPError

Raised when file operations fail.

class root_mcp.common.LRUCache(max_size)[source]

Bases: Generic[T]

Generic LRU cache implementation.

Parameters:

max_size (int)

__init__(max_size)[source]

Initialize LRU cache.

Parameters:

max_size (int) – Maximum number of items to cache

clear()[source]

Clear the cache.

Return type:

None

get(key)[source]

Get item from cache.

Parameters:

key (str) – Cache key

Returns:

Cached item or None if not found

Return type:

T | None

put(key, value)[source]

Add item to cache.

Parameters:
  • key (str) – Cache key

  • value (T) – Item to cache

Return type:

None

size()[source]

Get current cache size.

Return type:

int

exception root_mcp.common.ROOTMCPError[source]

Bases: Exception

Base exception for ROOT-MCP errors.

exception root_mcp.common.SecurityError[source]

Bases: ROOTMCPError

Raised when a security constraint is violated.

exception root_mcp.common.ValidationError[source]

Bases: ROOTMCPError

Raised when validation fails.

root_mcp.common.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.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.get_root_features()[source]

Get a dict of optional ROOT feature availability.

Example return:

{“rdataframe”: True, “roofit”: True, “tmva”: False, “minuit2”: True}

Returns empty dict if ROOT is not available. Result is cached after the first call.

Return type:

dict[str, bool]

root_mcp.common.get_root_version()[source]

Get the ROOT version string (e.g. ‘6.32/02’), or None if not available.

Result is cached after the first call.

Return type:

str | None

root_mcp.common.is_root_available()[source]

Check whether native ROOT/PyROOT is importable.

Result is cached after the first call.

Return type:

bool

root_mcp.common.sanitize_filename(filename)[source]

Sanitize a filename by removing/replacing invalid characters.

Parameters:

filename (str) – Original filename

Returns:

Sanitized filename

Return type:

str

Submodules