Module Overview
Annotated map of the root_mcp package tree. Each sub-package is linked to
its auto-generated API reference page.
Package tree
src/root_mcp/
│
├── __init__.py — public API: Config, load_config, __version__
├── config.py — Pydantic configuration models + CLI/env helpers
├── server.py — ROOTMCPServer class and main() entry point
│
├── common/ — shared utilities (no analysis deps)
│ ├── cache.py — generic TTL/LRU caching helpers
│ ├── errors.py — custom exception hierarchy
│ ├── root_availability.py — subprocess-based ROOT probe + feature detection
│ └── utils.py — misc helpers (path normalisation, JSON serialisation)
│
├── core/ — pure-Python core (uproot, awkward, numpy, pandas only)
│ ├── io/
│ │ ├── file_manager.py — LRU file-handle cache + uproot open/close
│ │ ├── readers.py — TreeReader, HistogramReader (TTree + TH*)
│ │ ├── exporters.py — DataExporter (JSON, CSV, Parquet)
│ │ └── validators.py — PathValidator (security, protocol checks)
│ ├── operations/
│ │ └── basic_stats.py — min/max/mean/std/median for any numeric branch
│ └── tools/
│ ├── discovery.py — DiscoveryTools (list_files, inspect_file, …)
│ └── data_access.py — DataAccessTools (read_branches, get_branch_stats, …)
│
└── extended/ — full analysis (scipy + matplotlib required)
├── analysis/
│ ├── histograms.py — HistogramOperations (1D/2D, weighted, arithmetic)
│ ├── fitting.py — HistogramFitter (Gaussian, CB, Voigt, …) + fit_histogram()
│ ├── kinematics.py — KinematicsOperations (invariant mass, ΔR, pT, …)
│ ├── correlations.py — CorrelationAnalysis (Pearson, Spearman, matrices)
│ ├── plotting.py — PlottingAnalysis (matplotlib 1D/2D plot generation)
│ ├── operations.py — AnalysisOperations (high-level coordinator)
│ └── expression.py — SafeExprEvaluator (restricted expression parser)
├── tools/
│ ├── analysis.py — AnalysisTools MCP tool layer (extended tools)
│ ├── plotting.py — PlottingTools MCP tool layer
│ └── root_native.py — RootNativeTools (run_root_code, run_rdataframe, …)
└── root_native/
├── executor.py — RootCodeExecutor (subprocess isolation, timeout)
├── sandbox.py — CodeValidator (AST-based import blocking)
└── templates.py — RDataFrame and macro code templates
Sub-package details
root_mcp.common
Shared infrastructure used by all tiers. No physics or analysis dependencies.
root_mcp.common.root_availability— the ROOT probe is subprocess-based to avoid contaminating the MCP server process with ROOT’s global signal handlers. Results are cached after the first call.root_mcp.common.errors— extends the error hierarchy used throughout;SecurityErroris raised byroot_mcp.core.io.validatorson path traversal attempts.root_mcp.common.cache— generic helpers used byFileCache.
root_mcp.config
All configuration is expressed as Pydantic v2 models in
root_mcp.config. The key model is Config
which composes:
Sub-model |
Governs |
|---|---|
Name, version, mode ( |
|
Allowed roots, protocols, path depth |
|
Named data sources (URI + glob patterns) |
|
Row caps, export row limits |
|
File-handle cache size |
|
|
|
Timeout, output formats, working directory for native ROOT |
root_mcp.core
The core tier runs without scipy or matplotlib. The IO sub-package is the foundation everything else builds on:
FileManagerowns the uproot file handles and the LRU cache.PathValidatoris the single enforcement point for thesecurity.allowed_rootsand protocol allow-lists.TreeReaderandHistogramReaderprovide high-level branch and histogram reading with chunking and offset support.
root_mcp.extended
The extended tier loads lazily — only if config.server.mode == "extended"
and the scipy/matplotlib imports succeed. If they fail, the server falls back
to core mode automatically.
root_mcp.extended.analysis.fittingis the most complex module.fit_histogram()supports composite models (e.g. Gaussian + exponential background), per-parameter bounds, and fixed parameters.root_mcp.extended.root_nativeis the native ROOT execution engine.RootCodeExecutorruns user code in a subprocess;CodeValidatorperforms AST-level import blocking as a best-effort sandbox.
Adding a new analysis tool
The typical flow for adding an extended analysis capability:
Add the pure calculation to the appropriate module in
src/root_mcp/extended/analysis/(e.g.kinematics.py).Add the corresponding MCP tool method to
src/root_mcp/extended/tools/analysis.py(orplotting.py).Register the tool in
src/root_mcp/server.pyunder_register_extended_tools().Document the tool in
docs/api/tools.mdfollowing the existing table format.Add tests under
tests/.
Adding a core tool follows the same pattern but targets
src/root_mcp/core/tools/ and _register_core_tools() in the server.