Skip to main content
Glama

CI PyPI License Language

Repository Mirror: This repository is mirrored to CERN GitLab for CERN users. PyPI releases are published via GitHub Actions using attestation-based trusted publishing.

ROOT-MCP empowers Large Language Models (LLMs) to natively understand and analyze CERN ROOT files.

By exposing a set of specialized tools via the Model Context Protocol (MCP) or a token-efficient CLI interface, it turns Claude (and other MCP-compliant agents) into capable physics research assistants that can:

  • Inspect ROOT file structures (Trees, RNTuples, Branches, Histograms)

  • Analyze data distributions (Compute Histograms, Statistics)

  • Compute kinematic quantities (Invariant Mass)

  • Visualize results (Plot 1D/2D histograms directly)

  • Filter data using physics cuts ("selections")

Why this matters: Instead of asking an LLM to "write a script" that you have to debug and run, you can ask the LLM to "Check the muon pT distribution in this file" and it will just do it.


Two Interfaces: MCP Server and CLI

ROOT-MCP provides two ways to interact with ROOT files:

1. MCP Server (for Codex, Claude Code and other MCP clients)

  • Full JSON-RPC protocol support

  • Structured input/output for programmatic use

  • Best for: MCP-compliant LLM clients, automated workflows

2. ROOT CLI (root-cli)

  • Human-readable output by default

  • Simpler architecture (no server process)

  • Best for: Direct LLM interaction, debugging, scripting

Both interfaces share the same analysis backend. MCP also provides resource discovery and server capability information.


Related MCP server: XRootD MCP Server

Quick Start

1. Install

pip install root-mcp

Optional: For remote file access via XRootD protocol:

pip install "root-mcp[xrootd]"

2. Configure

Fastest path — no config file needed:

# MCP Server
root-mcp --data-path /path/to/your/data

# CLI (token-efficient)
root-cli -d /path/to/your/data ls

Or set an environment variable once:

export ROOT_MCP_DATA_PATH=/path/to/your/data

3. Connect a coding agent

# Codex
codex mcp add root-mcp -- uvx root-mcp --data-path /absolute/path/to/data

# Claude Code (project scope)
claude mcp add --transport stdio --scope project root-mcp -- uvx root-mcp --data-path /absolute/path/to/data

Use /mcp in your client to check the connection. See the LLM integration guide for development checkouts, Antigravity CLI, Qwen Code, Pi/OMP, VS Code, Cursor, Zed, community harnesses, authenticated HTTP and bounded analysis workflows.

The server uses MCP Python SDK 2.3+ and the 2026-07-28 protocol, with SDK compatibility for older clients. It provides discovery instructions, explicit tool safety hints, validated inputs, structured results and readable resource catalogs. Remote deployments retain authentication, resource ACLs and quotas. See the v0.3.1 release notes for the full change list.


The CLI provides a token-efficient, human-readable interface that provides significant token savings compared to the MCP JSON protocol.

Basic Usage

# List files
root-cli ls

# Inspect a file
root-cli inspect /data/sample.root

# Create histogram with fit
root-cli histogram /data/sample.root events muon_pt --bins 100 --fit gaussian

# Read data with selection
root-cli read /data/sample.root events met muon_pt --selection "met > 50"

# Plot results
root-cli plot1d /tmp/root_mcp/muon_pt_hist.json -o plot.png --title "Muon pT"

Example LLM Workflow

Ask your LLM: "Plot the muon pT distribution"

The LLM generates:

root-cli histogram /data/sample.root events muon_pt --bins 50 && \
root-cli plot1d /tmp/root_mcp/muon_pt_hist.json -o muon_pt.png --title "Muon pT Distribution"

Documentation

See docs/skills/root-cli.md for complete command reference with examples.


MCP Server

Zero-config one-liners:

# Core mode (lightweight, no scipy/matplotlib needed)
root-mcp --data-path /data --mode core

# Explicit stdio transport (same runtime as the compatibility default)
root-mcp serve-stdio --data-path /data

# Extended mode with native ROOT, restricted to one directory
root-mcp --data-path /data --enable-root --allowed-root /data

# Remote XRootD resource, no YAML needed
root-mcp --resource cms=root://xrootd.cern.ch//store --allow-remote --mode extended

# Docker / container — fully env-var driven
ROOT_MCP_DATA_PATH=/data ROOT_MCP_MODE=extended ROOT_MCP_EXPORT_PATH=/exports root-mcp

# Quiet server (only warnings+) with a cache increase
root-mcp --data-path /data --log-level WARNING --cache-size 100

root-mcp serve-http serves the MCP Streamable HTTP endpoint for central deployments. It requires explicit auth, Origin validation, restrictive central policy, and safe bind-address settings before it starts.

For shared deployments, start with the operator docs: docs/operator/central_deployment.md and docs/operator/security_checklist.md. Restrictive starter configs and Kubernetes manifests live in examples/central/.

Operators can preview and apply export retention with root-mcp cleanup-exports --config /etc/root-mcp/config.yaml --dry-run. The external HTTP smoke script at scripts/smoke_external_http_client.py starts a temporary central server and checks it with the MCP Streamable HTTP client.

Generate a starter config (optional):

root-mcp init --permissive   # creates config.yaml pre-filled with current directory

Manual config file — for persistent settings, remote resources, or native ROOT:

server:
  mode: "extended"   # "core" or "extended"

resources:
  - name: "my_analysis"
    uri: "file:///path/to/data"
    allowed_patterns: ["*.root"]

security:
  allowed_roots: []  # empty = any local path is accessible (permissive)

Local-use warning: The permissive allowed_roots: [] default is intended for trusted local stdio sessions. Do not expose that configuration as a shared HTTP service; restrict roots and require an authenticated deployment profile before central or multi-user use.

Mode Selection:

  • mode: "core" — Lightweight: file operations and basic statistics

  • mode: "extended" — Full analysis: histograms, fitting, kinematics, correlations

Switch modes at runtime with the switch_mode tool — no restart required.

Run with Claude Desktop

Add to your claude_desktop_config.json:

{
  "mcpServers": {
    "root-mcp": {
      "command": "root-mcp",
      "args": ["--data-path", "/path/to/your/data"]
    }
  }
}

Or with a persistent config file:

{
  "mcpServers": {
    "root-mcp": {
      "command": "root-mcp",
      "env": {
        "ROOT_MCP_CONFIG": "/path/to/config.yaml"
      }
    }
  }
}

Architecture

ROOT-MCP organizes analysis capabilities into analysis tiers:

  • Core Mode: File I/O, data reading, and basic statistics

  • Extended Mode: Full analysis capabilities including fitting, kinematics, and correlations

The mode is controlled via configuration, and the server automatically loads only the components you need. Runtime mode switching is also available.

Optional Native ROOT Support

ROOT-MCP can optionally integrate with a native ROOT/PyROOT installation to unlock capabilities beyond what uproot provides:

  • run_root_code: Execute arbitrary PyROOT/Python code and get structured results

  • run_rdataframe: Compute histograms using ROOT's RDataFrame (no boilerplate needed)

  • run_root_macro: Execute C++ ROOT macros via gROOT.ProcessLine

This feature is entirely optional — ROOT-MCP works fully without ROOT installed. When ROOT is available and enabled, these additional tools appear automatically.

Requirements: A working ROOT installation (via conda-forge, system package, or binary tarball). ROOT is not pip-installable at this time.

Enable it by setting enable_root: true in your config.yaml:

features:
  enable_root: true

# Optional: tune execution settings
root_native:
  execution_timeout: 60
  working_directory: "/tmp/root_mcp_native"

Use get_server_info to check ROOT availability at runtime:

{
  "root_native_available": true,
  "root_native_enabled": true,
  "root_version": "6.32/02",
  "root_features": {"rdataframe": true, "roofit": true, "tmva": false}
}

Documentation

The full documentation site is built with Sphinx and covers installation, configuration, all 20 MCP tools, LLM integration patterns, and the developer guide with auto-generated API reference.

Read online: The docs are hosted at root-mcp docs

pip install "root-mcp[docs]"
./scripts/build_docs.sh
# open docs/_build/html/index.html

For live-reload while writing docs:

cd docs && make livehtml

Highlights:

  • User Guide — installation, quickstart, modes, configuration, LLM integration

  • Tool Reference — complete catalogue of all tools and their JSON payloads

  • CLI Reference — complete command reference for root-cli with examples

  • Developer Guide — architecture, module overview, dev setup, contributing

  • API Reference — auto-generated from source docstrings

Citation

If you use ROOT-MCP in your research, please cite:

@software{root_mcp,
  title = {ROOT-MCP: Production-Grade MCP Server for CERN ROOT Files},
  author = {Mohamed Elashri},
  year = {2025},
  url = {https://github.com/MohamedElashri/root-mcp}
}

License

MIT License - see LICENSE for details.

Available Tools

9 tools
export_dataA
Destructive

Export selected ROOT branches to a JSON, CSV or Parquet file. Writes output_path and may overwrite it. Central deployments require an artifact-relative output path and export permission.

Inputs: path (required), format (required), branches (required), tree_name (required), +3 more.

get_branch_statsC
Read-onlyIdempotent

Get statistics for branches (supports derived variables via defines)

Inputs: path (required), branches (required), tree_name (required), defines, +1 more.

get_server_infoA
Read-onlyIdempotent

Discover ROOT analysis mode, capabilities, accessible named resources and request limits. Use before choosing analysis tools; native ROOT requires a separate installation.

Inputs: no named parameters.

inspect_fileA
Read-onlyIdempotent

Inspect a ROOT file's directories, TTrees, RNTuples and histograms before reading data. Accepts a returned path or @resource/relative.root reference. Does not modify files.

Inputs: path (required).

list_branchesA
Read-onlyIdempotent

List branch names and types in a ROOT TTree or RNTuple. Use before selecting branches for reads, statistics or histograms. Does not modify files.

Inputs: path (required), tree_name (required), pattern.

list_filesA
Read-onlyIdempotent

List CERN ROOT files in a configured named resource. Use pattern and limit to bound discovery; inspect a returned path next. Does not modify files.

Inputs: resource (required), limit, pattern.

read_branchesA
Read-onlyIdempotent

Read selected branches from a ROOT TTree or RNTuple, optionally with a cut expression. Set entry_start/entry_stop to bound rows; prefer get_branch_stats or histograms for large datasets. Does not modify files.

Inputs: path (required), branches (required), tree_name (required), limit, +6 more.

switch_modeA
Idempotent

Change the local server-wide analysis tier between core and extended. Affects all calls to this process; list tools again afterward. Disabled in central deployments.

Inputs: mode (required).

validate_fileC
Read-onlyIdempotent

Validate ROOT file integrity

Inputs: path (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.7/5.0

    Scored across 9 tools

    Disambiguation5/5

    Each tool targets a distinct stage of ROOT file analysis: discovery (list_files), structure inspection (inspect_file), branch listing, validation, reading, statistics, export, and server metadata/mode control. Overlap between inspect_file and list_branches is clarified by descriptions focusing on file structure versus TTree/RNTuple branches.

    Naming Consistency5/5

    All names use snake_case with verb_noun structure (list_files, inspect_file, read_branches, get_branch_stats, export_data, get_server_info). switch_mode fits the verb_noun convention despite being administrative rather than analytical.

    Tool Count5/5

    Nine tools is well-scoped for a read-only ROOT analysis server, covering discovery through export without redundant operations. Each tool has a clear, non-overlapping role in the workflow.

    Completeness3/5

    The surface covers discovery, inspection, validation, reading, statistics, and export, but references histograms as an alternative in tool descriptions without providing any histogram or plotting tool. This creates a notable dead end for a core ROOT analysis operation, though agents can partially work around it via stats and export.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      An MCP server that publishes CLI tools on your machine for discoverability by LLMs
      7 npm
      1
      MIT
    • A
      license
      A
      quality
      B
      maintenance
      An MCP server providing access to XRootD file systems, allowing LLMs to browse directories, read file metadata, and access contents via the root:// protocol. It supports advanced features like campaign discovery, file searching, and ROOT file analysis for scientific data management.
      18
      1
      MIT
    • A
      license
      A
      quality
      B
      maintenance
      An MCP server that connects LLMs to CERN GitLab to discover and analyze High Energy Physics code, documentation, and analysis examples. It provides 14 tools for repository browsing, dependency parsing, and CI/CD configuration analysis.
      15
      54 PyPI
      4
      AGPL 3.0
    • A
      license
      Not graded
      quality
      C
      maintenance
      An MCP server that exposes Rucio distributed data management operations as tools for LLMs. Designed for ATLAS physicists working with grid data on analysis facilities, but usable with any Rucio instance.
      6
      Apache 2.0