root_mcp.config module

Configuration management for ROOT-MCP server.

class root_mcp.config.AnalysisConfig(*args, **kwargs)[source]

Bases: BaseModel

Analysis operation settings.

Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

Any

default_chunk_size: int = 10000
default_read_limit: int = 1000
class root_mcp.config.CacheConfig(*args, **kwargs)[source]

Bases: BaseModel

File-handle cache settings.

Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

Any

enabled: bool = True
file_cache_size: int = 50
class root_mcp.config.Config(*args, **kwargs)[source]

Bases: BaseModel

Root configuration for ROOT-MCP server.

Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

Any

get_default_resource()[source]

Get the first configured resource (default).

Return type:

ResourceConfig | None

get_resource(name)[source]

Get resource configuration by name.

Parameters:

name (str)

Return type:

ResourceConfig | None

class root_mcp.config.CoreConfig(*args, **kwargs)[source]

Bases: BaseModel

Core mode configuration.

Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

Any

class root_mcp.config.ExtendedConfig(*args, **kwargs)[source]

Bases: BaseModel

Extended mode configuration.

Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

Any

fitting_max_iterations: int = 10000
class root_mcp.config.FeatureFlags(*args, **kwargs)[source]

Bases: BaseModel

Feature toggles.

Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

Any

enable_export: bool = True
enable_root: bool = False
class root_mcp.config.HistogramConfig(*args, **kwargs)[source]

Bases: BaseModel

Histogram-specific settings.

Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

Any

max_bins_1d: int = 10000
max_bins_2d: int = 1000
class root_mcp.config.LimitsConfig(*args, **kwargs)[source]

Bases: BaseModel

Resource limits for safety.

Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

Any

max_export_rows: int = 10000000
max_rows_per_call: int = 1000000
class root_mcp.config.OutputConfig(*args, **kwargs)[source]

Bases: BaseModel

Output and export settings.

Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

Any

export_base_path: str = '/tmp/root_mcp_output'
validate_export_path()

Ensure export path is absolute.

class root_mcp.config.PlottingConfig(*args, **kwargs)[source]

Bases: BaseModel

Plotting and visualization settings.

Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

Any

data_color: str = 'black'
default_format: str = 'png'
dpi: int = 100
error_bar_cap_size: float = 2.0
figure_height: float = 6.0
figure_width: float = 10.0
fit_line_color: str = 'red'
fit_line_style: str = '-'
grid_alpha: float = 0.3
grid_enabled: bool = True
hist_fill_alpha: float = 0.2
hist_fill_color: str = 'blue'
line_width: float = 2.0
marker_size: float = 4.0
marker_style: str = 'o'
class root_mcp.config.ResourceConfig(*args, **kwargs)[source]

Bases: BaseModel

Configuration for a data resource (MCP root).

Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

Any

description: str = ''
name: str
uri: str
validate_name()

Ensure resource name is valid.

class root_mcp.config.RootNativeConfig(*args, **kwargs)[source]

Bases: BaseModel

Configuration for native ROOT/PyROOT execution.

Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

Any

execution_timeout: int = 60
max_code_length: int = 100000
max_output_size: int = 10000000
working_directory: str = '/tmp/root_mcp_native'
class root_mcp.config.SecurityConfig(*args, **kwargs)[source]

Bases: BaseModel

Security and access control settings.

Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

Any

allow_remote: bool = False
effective_protocols(resources)[source]

Return the union of explicitly allowed protocols and protocols inferred from the URI scheme of declared resources.

This means a resource with uri: "root://…" automatically permits the root protocol without requiring allow_remote: true or manually adding root to allowed_protocols.

Parameters:

resources (list) – List of ResourceConfig objects (pass config.resources).

Returns:

Deduplicated list of permitted protocol strings.

Return type:

list[str]

max_path_depth: int = 10
validate_roots()

Ensure allowed roots are absolute paths.

An empty list is valid and means permissive / zero-config mode: the server will allow access to any path the OS permits.

class root_mcp.config.ServerConfig(*args, **kwargs)[source]

Bases: BaseModel

Server-level settings.

Parameters:
  • args (Any)

  • kwargs (Any)

Return type:

Any

mode: str = 'extended'
name: str = 'root-mcp'
root_mcp.config.apply_cli_overrides(config, args)[source]

Apply parsed CLI arguments onto config in-place.

CLI flags are the highest-priority source — they override both YAML and env vars. This function only mutates a field when the corresponding args attribute is explicitly set (not None).

** Server & Mode**:

  • args.modeConfig.server.mode

  • args.server_nameConfig.server.name

** Security**:

  • args.allowed_rootConfig.security.allowed_roots (list; replaces)

  • args.allow_remoteConfig.security.allow_remote (True/False/None)

  • args.allowed_protocolsConfig.security.allowed_protocols (comma-string, split on parse)

  • args.max_path_depthConfig.security.max_path_depth

** Output / Export**:

  • args.export_pathConfig.output.export_base_path

  • args.export_formatsConfig.output.allowed_formats (comma-string)

  • args.enable_exportConfig.features.enable_export (False when --no-export is given, None when not specified)

** Core Limits & Cache**:

  • args.max_rowsConfig.core.limits.max_rows_per_call

  • args.max_export_rowsConfig.core.limits.max_export_rows

  • args.cache_enabledConfig.core.cache.enabled (False when --no-cache is given, None when not specified)

  • args.cache_sizeConfig.core.cache.file_cache_size

** Extended Analysis**:

  • args.max_bins_1dConfig.extended.histogram.max_bins_1d

  • args.max_bins_2dConfig.extended.histogram.max_bins_2d

  • args.fitting_iterationsConfig.extended.fitting_max_iterations

  • args.plot_dpiConfig.extended.plotting.dpi

  • args.plot_formatConfig.extended.plotting.default_format

  • args.plot_widthConfig.extended.plotting.figure_width

  • args.plot_heightConfig.extended.plotting.figure_height

** Native ROOT Execution**:

  • args.root_timeoutConfig.root_native.execution_timeout

  • args.root_workdirConfig.root_native.working_directory

  • args.root_max_outputConfig.root_native.max_output_size

  • args.root_max_codeConfig.root_native.max_code_length

** Remote Resources**:

  • args.resourceConfig.resources (repeated NAME=URI[|DESCRIPTION] specs; YAML-declared URIs take precedence via deduplication)

Parameters:
Returns:

The same config object (mutated) for convenience.

Raises:

ValueError – When a CLI flag contains an invalid value.

Return type:

Config

root_mcp.config.apply_data_paths(config, paths)[source]

Merge a list of local directory paths into config as resources.

Each path is added as a new ResourceConfig only when no existing resource already points to the same URI (YAML-declared resources take precedence). When security.allowed_roots is non-empty (restrictive mode), the path is also appended there so the validator permits access.

This is the shared building block used by both the --data-path CLI flag and the ROOT_MCP_DATA_PATH environment variable.

Parameters:
  • config (Config) – The Config to update in-place.

  • paths (list[str]) – List of local directory paths (resolved to absolute).

Returns:

The same config object (mutated) for convenience.

Return type:

Config

root_mcp.config.apply_env_overrides(config)[source]

Read ROOT_MCP_* environment variables and merge into config in-place.

Env vars sit between the YAML file (priority 2) and CLI flags (priority 4) in the merge chain — i.e. an env var overrides the YAML but is itself overridden by an explicit --flag on the command line.

Only non-empty env vars are applied; missing or empty vars leave the corresponding field untouched.

** Server & Mode**:

  • ROOT_MCP_MODEConfig.server.mode (core or extended)

  • ROOT_MCP_SERVER_NAMEConfig.server.name

** Security**:

  • ROOT_MCP_ALLOWED_ROOTSConfig.security.allowed_roots (colon-separated paths; replaces the YAML list)

  • ROOT_MCP_ALLOW_REMOTEConfig.security.allow_remote (1/true/yesTrue)

  • ROOT_MCP_ALLOWED_PROTOCOLSConfig.security.allowed_protocols (comma-separated; replaces the YAML list)

  • ROOT_MCP_MAX_PATH_DEPTHConfig.security.max_path_depth (positive integer)

Output / Export:

  • ROOT_MCP_EXPORT_PATHConfig.output.export_base_path (directory string)

  • ROOT_MCP_EXPORT_FORMATSConfig.output.allowed_formats (comma-separated; replaces the YAML list)

  • ROOT_MCP_ENABLE_EXPORTConfig.features.enable_export (1/true/yesTrue, anything else → False)

** Core Limits & Cache**:

  • ROOT_MCP_MAX_ROWSConfig.core.limits.max_rows_per_call (positive int)

  • ROOT_MCP_MAX_EXPORT_ROWSConfig.core.limits.max_export_rows (positive int)

  • ROOT_MCP_CACHEConfig.core.cache.enabled (1/true/yesTrue, anything else → False)

  • ROOT_MCP_CACHE_SIZEConfig.core.cache.file_cache_size (positive int)

** Extended Analysis**:

  • ROOT_MCP_MAX_BINS_1DConfig.extended.histogram.max_bins_1d (positive int)

  • ROOT_MCP_MAX_BINS_2DConfig.extended.histogram.max_bins_2d (positive int)

  • ROOT_MCP_FITTING_ITERATIONSConfig.extended.fitting_max_iterations (positive int)

  • ROOT_MCP_PLOT_DPIConfig.extended.plotting.dpi (positive int)

  • ROOT_MCP_PLOT_FORMATConfig.extended.plotting.default_format (png, pdf, or svg)

  • ROOT_MCP_PLOT_WIDTHConfig.extended.plotting.figure_width (positive float)

  • ROOT_MCP_PLOT_HEIGHTConfig.extended.plotting.figure_height (positive float)

** Native ROOT Execution**:

  • ROOT_MCP_ROOT_TIMEOUTConfig.root_native.execution_timeout (positive int, seconds)

  • ROOT_MCP_ROOT_WORKDIRConfig.root_native.working_directory (path string)

  • ROOT_MCP_ROOT_MAX_OUTPUTConfig.root_native.max_output_size (positive int, bytes)

  • ROOT_MCP_ROOT_MAX_CODEConfig.root_native.max_code_length (positive int, chars)

** Remote Resources**:

  • ROOT_MCP_RESOURCESConfig.resources (semicolon-sep list of NAME=URI or NAME=URI|DESCRIPTION specs; YAML-declared URIs take precedence via deduplication)

Parameters:

config (Config) – The Config to update in-place.

Returns:

The same config object (mutated) for convenience.

Raises:

ValueError – When an env var contains an invalid value (e.g. an unrecognised mode string).

Return type:

Config

root_mcp.config.apply_log_level(level_str)[source]

Set the Python root logger’s level.

This is called in main() before load_config() so that log messages emitted during configuration loading and all subsequent startup already respect the requested verbosity.

Parameters:

level_str (str) – Case-insensitive level name. Accepted values: DEBUG, INFO, WARNING, ERROR.

Raises:

ValueError – When level_str is not one of the accepted names.

Return type:

None

root_mcp.config.create_default_config(output_path, data_path=None, permissive=True)[source]

Generate a minimal, human-readable config.yaml.

The output uses the same two-tier format as root-mcp init: a short QUICK START section with the only field most users need to change, followed by an ADVANCED section with fine-tuning knobs.

Parameters:
  • output_path (str | Path) – Destination file path.

  • data_path (Path | None) – Local directory to use as the resource URI. When None and permissive is True, defaults to the current working directory. When None and permissive is False, writes a placeholder that the user must edit before use.

  • permissive (bool) – When True (default), security.allowed_roots is left empty (allow any OS-readable path). Ignored when data_path is None and permissive is False.

Return type:

None

root_mcp.config.load_config(config_path=None)[source]

Load configuration from YAML file.

After loading (or using built-in defaults when no file is found), the ROOT_MCP_DATA_PATH environment variable is checked. Any colon-separated directory paths it contains are merged into the config as resources via apply_data_paths(), exactly as if those directories had been passed via --data-path on the CLI. YAML-declared resources always take precedence over env-var paths; CLI --data-path flags (applied in main()) take precedence over both.

Config merge priority (ascending — later wins):

  1. Built-in Pydantic defaults

  2. ROOT_MCP_DATA_PATH environment variable

  3. --data-path CLI flags (applied in main())

  4. YAML config file values

Parameters:

config_path (str | Path | None) – Path to config file. If None, looks for: 1. ROOT_MCP_CONFIG env var 2. ./config.yaml 3. ~/.config/root-mcp/config.yaml

Returns:

Validated Config object

Return type:

Config