root_mcp.config module
Configuration management for ROOT-MCP server.
- class root_mcp.config.AnalysisConfig(*args, **kwargs)[source]
Bases:
BaseModelAnalysis operation settings.
- Parameters:
args (Any)
kwargs (Any)
- Return type:
Any
- class root_mcp.config.CacheConfig(*args, **kwargs)[source]
Bases:
BaseModelFile-handle cache settings.
- Parameters:
args (Any)
kwargs (Any)
- Return type:
Any
- class root_mcp.config.Config(*args, **kwargs)[source]
Bases:
BaseModelRoot 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:
BaseModelCore mode configuration.
- Parameters:
args (Any)
kwargs (Any)
- Return type:
Any
- class root_mcp.config.ExtendedConfig(*args, **kwargs)[source]
Bases:
BaseModelExtended mode configuration.
- Parameters:
args (Any)
kwargs (Any)
- Return type:
Any
- class root_mcp.config.FeatureFlags(*args, **kwargs)[source]
Bases:
BaseModelFeature toggles.
- Parameters:
args (Any)
kwargs (Any)
- Return type:
Any
- class root_mcp.config.HistogramConfig(*args, **kwargs)[source]
Bases:
BaseModelHistogram-specific settings.
- Parameters:
args (Any)
kwargs (Any)
- Return type:
Any
- class root_mcp.config.LimitsConfig(*args, **kwargs)[source]
Bases:
BaseModelResource limits for safety.
- Parameters:
args (Any)
kwargs (Any)
- Return type:
Any
- class root_mcp.config.OutputConfig(*args, **kwargs)[source]
Bases:
BaseModelOutput and export settings.
- Parameters:
args (Any)
kwargs (Any)
- Return type:
Any
- validate_export_path()
Ensure export path is absolute.
- class root_mcp.config.PlottingConfig(*args, **kwargs)[source]
Bases:
BaseModelPlotting and visualization settings.
- Parameters:
args (Any)
kwargs (Any)
- Return type:
Any
- class root_mcp.config.ResourceConfig(*args, **kwargs)[source]
Bases:
BaseModelConfiguration for a data resource (MCP root).
- Parameters:
args (Any)
kwargs (Any)
- Return type:
Any
- validate_name()
Ensure resource name is valid.
- class root_mcp.config.RootNativeConfig(*args, **kwargs)[source]
Bases:
BaseModelConfiguration for native ROOT/PyROOT execution.
- Parameters:
args (Any)
kwargs (Any)
- Return type:
Any
- class root_mcp.config.SecurityConfig(*args, **kwargs)[source]
Bases:
BaseModelSecurity and access control settings.
- Parameters:
args (Any)
kwargs (Any)
- Return type:
Any
- 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 therootprotocol without requiringallow_remote: trueor manually addingroottoallowed_protocols.- Parameters:
resources (list) – List of
ResourceConfigobjects (passconfig.resources).- Returns:
Deduplicated list of permitted protocol strings.
- Return type:
- 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:
BaseModelServer-level settings.
- Parameters:
args (Any)
kwargs (Any)
- Return type:
Any
- 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
argsattribute is explicitly set (notNone).** Server & Mode**:
args.mode→Config.server.modeargs.server_name→Config.server.name
** Security**:
args.allowed_root→Config.security.allowed_roots(list; replaces)args.allow_remote→Config.security.allow_remote(True/False/None)args.allowed_protocols→Config.security.allowed_protocols(comma-string, split on parse)args.max_path_depth→Config.security.max_path_depth
** Output / Export**:
args.export_path→Config.output.export_base_pathargs.export_formats→Config.output.allowed_formats(comma-string)args.enable_export→Config.features.enable_export(False when--no-exportis given,Nonewhen not specified)
** Core Limits & Cache**:
args.max_rows→Config.core.limits.max_rows_per_callargs.max_export_rows→Config.core.limits.max_export_rowsargs.cache_enabled→Config.core.cache.enabled(False when--no-cacheis given,Nonewhen not specified)args.cache_size→Config.core.cache.file_cache_size
** Extended Analysis**:
args.max_bins_1d→Config.extended.histogram.max_bins_1dargs.max_bins_2d→Config.extended.histogram.max_bins_2dargs.fitting_iterations→Config.extended.fitting_max_iterationsargs.plot_dpi→Config.extended.plotting.dpiargs.plot_format→Config.extended.plotting.default_formatargs.plot_width→Config.extended.plotting.figure_widthargs.plot_height→Config.extended.plotting.figure_height
** Native ROOT Execution**:
args.root_timeout→Config.root_native.execution_timeoutargs.root_workdir→Config.root_native.working_directoryargs.root_max_output→Config.root_native.max_output_sizeargs.root_max_code→Config.root_native.max_code_length
** Remote Resources**:
args.resource→Config.resources(repeatedNAME=URI[|DESCRIPTION]specs; YAML-declared URIs take precedence via deduplication)
- Parameters:
args (Namespace) – Parsed
argparse.Namespacefrom the server’s argument parser.
- Returns:
The same config object (mutated) for convenience.
- Raises:
ValueError – When a CLI flag contains an invalid value.
- Return type:
- 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
ResourceConfigonly when no existing resource already points to the same URI (YAML-declared resources take precedence). Whensecurity.allowed_rootsis 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-pathCLI flag and theROOT_MCP_DATA_PATHenvironment variable.
- 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
--flagon the command line.Only non-empty env vars are applied; missing or empty vars leave the corresponding field untouched.
** Server & Mode**:
ROOT_MCP_MODE→Config.server.mode(coreorextended)ROOT_MCP_SERVER_NAME→Config.server.name
** Security**:
ROOT_MCP_ALLOWED_ROOTS→Config.security.allowed_roots(colon-separated paths; replaces the YAML list)ROOT_MCP_ALLOW_REMOTE→Config.security.allow_remote(1/true/yes→True)ROOT_MCP_ALLOWED_PROTOCOLS→Config.security.allowed_protocols(comma-separated; replaces the YAML list)ROOT_MCP_MAX_PATH_DEPTH→Config.security.max_path_depth(positive integer)
Output / Export:
ROOT_MCP_EXPORT_PATH→Config.output.export_base_path(directory string)ROOT_MCP_EXPORT_FORMATS→Config.output.allowed_formats(comma-separated; replaces the YAML list)ROOT_MCP_ENABLE_EXPORT→Config.features.enable_export(1/true/yes→True, anything else →False)
** Core Limits & Cache**:
ROOT_MCP_MAX_ROWS→Config.core.limits.max_rows_per_call(positive int)ROOT_MCP_MAX_EXPORT_ROWS→Config.core.limits.max_export_rows(positive int)ROOT_MCP_CACHE→Config.core.cache.enabled(1/true/yes→True, anything else →False)ROOT_MCP_CACHE_SIZE→Config.core.cache.file_cache_size(positive int)
** Extended Analysis**:
ROOT_MCP_MAX_BINS_1D→Config.extended.histogram.max_bins_1d(positive int)ROOT_MCP_MAX_BINS_2D→Config.extended.histogram.max_bins_2d(positive int)ROOT_MCP_FITTING_ITERATIONS→Config.extended.fitting_max_iterations(positive int)ROOT_MCP_PLOT_DPI→Config.extended.plotting.dpi(positive int)ROOT_MCP_PLOT_FORMAT→Config.extended.plotting.default_format(png,pdf, orsvg)ROOT_MCP_PLOT_WIDTH→Config.extended.plotting.figure_width(positive float)ROOT_MCP_PLOT_HEIGHT→Config.extended.plotting.figure_height(positive float)
** Native ROOT Execution**:
ROOT_MCP_ROOT_TIMEOUT→Config.root_native.execution_timeout(positive int, seconds)ROOT_MCP_ROOT_WORKDIR→Config.root_native.working_directory(path string)ROOT_MCP_ROOT_MAX_OUTPUT→Config.root_native.max_output_size(positive int, bytes)ROOT_MCP_ROOT_MAX_CODE→Config.root_native.max_code_length(positive int, chars)
** Remote Resources**:
ROOT_MCP_RESOURCES→Config.resources(semicolon-sep list ofNAME=URIorNAME=URI|DESCRIPTIONspecs; YAML-declared URIs take precedence via deduplication)
- Parameters:
- 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:
- root_mcp.config.apply_log_level(level_str)[source]
Set the Python root logger’s level.
This is called in
main()beforeload_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:
data_path (Path | None) – Local directory to use as the resource URI. When
NoneandpermissiveisTrue, defaults to the current working directory. WhenNoneandpermissiveisFalse, writes a placeholder that the user must edit before use.permissive (bool) – When
True(default),security.allowed_rootsis left empty (allow any OS-readable path). Ignored whendata_pathisNoneandpermissiveisFalse.
- 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_PATHenvironment variable is checked. Any colon-separated directory paths it contains are merged into the config as resources viaapply_data_paths(), exactly as if those directories had been passed via--data-pathon the CLI. YAML-declared resources always take precedence over env-var paths; CLI--data-pathflags (applied inmain()) take precedence over both.Config merge priority (ascending — later wins):
Built-in Pydantic defaults
ROOT_MCP_DATA_PATHenvironment variable--data-pathCLI flags (applied inmain())YAML config file values