ROOT MCP Server

io.github.omazapa由 GitHub 账号 omazapa 发布v1.0.0更新于 Oct 24, 2026

ROOT-based MCP server exposing root_python and root_cpp tools (stdio transport).

已验证STDIO仅桌面开发者工具数据与分析

概览

AI 生成的概览

本地 MCP 服务器,借助 CERN ROOT/PyROOT 在进程内执行 Python 与 C++ 代码,并返回标准输出、错误输出和错误信息。

可以做什么
  • 执行已自动加载 ROOT 的 Python 代码,返回 stdout、stderr 与错误元数据
  • 通过 ROOT 的 cling 解释器执行 C++ 代码,并依据返回码和 stderr 识别编译错误
  • 创建直方图、画布等 ROOT 图形对象,支持事件循环,并可启用内嵌 HTTP 服务器查看交互式画布
  • 把每次执行的带行号代码与结果记录到 MCP 控制台
适用场景
适合让助手在本机直接运行基于 ROOT 的数据分析、直方图统计或绘图代码,例如在 VS Code 配合 Copilot Chat 时,而不只是生成代码让你自己运行。
运行要求
以本地 stdio 进程运行(Docker 镜像或 pip 安装)。需要 ROOT 6.x 或更高版本并启用 PyROOT、Python 3.10+,启动前还需加载 ROOT 环境(例如 thisroot.sh)。
安装前请注意
提交的代码与服务器在同一进程内运行,没有子进程隔离,因此拥有当前用户账户的全部权限,可读取、修改或删除本地文件。执行内容(含代码本身)会记录到 MCP 控制台。启用图形功能时可能开启内嵌 HTTP 服务器,把画布暴露到网络上。

安装

在 SourceWeft 中

  1. 打开 控制台中的 ROOT MCP Server,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

[ROOT Logo]

root_mcp_server: MCP Server for ROOT

Model Context Protocol server for executing Python and C++ code with PyROOT

[ROOT] [MCP] [Python]


Minimal MCP (Model Context Protocol) server that allows LLMs and other MCP clients to execute Python and C++ code directly using PyROOT, without HTTP endpoints or external APIs.

Features

  • Direct Python execution: Run Python code with PyROOT available automatically
  • Direct C++ execution: Run C++ code via ROOT's cling interpreter
  • In-process: All code runs in the same process (no subprocess isolation)
  • Error detection: Automatic detection of C++ compilation errors via return codes and stderr
  • Console logging: Pretty-printed code execution with results in MCP console
  • Graphics support: TCanvas and ROOT graphics objects with event loop support

Architecture

Below is the architecture diagram for the root_mcp_server project. The image contains a visual representation of the components and their interactions.

[Architecture Diagram]

Description:

  • MCP Client (VS Code / CLI / Programmatic): connects to the MCP server and sends execution requests. Clients can be interactive (e.g. VS Code + Copilot Chat) or scripted CLI clients.
  • FastMCP Server: receives MCP tool calls (root_python, root_cpp) and dispatches them to the in-process executor.
  • RootExecutor (in-process PyROOT): runs Python or C++ code with the ROOT runtime, manages graphics mode, and can expose an embedded HTTP server (THttpServer) for interactive canvases.
  • ROOT Web Canvas (THttpServer / JSROOT): when graphics are enabled, canvases created in the ROOT session are available via the embedded HTTP server; clients can open the provided URL to inspect plots interactively.
  • Artifacts & Outputs: execution results (stdout/stderr and error metadata) are returned to the MCP client; interactive canvases are accessible via the HTTP endpoint.

This architecture keeps ROOT running in-process for low-latency execution while providing a web-backed path for interactive visualization.

Installation

Prerequisites

  • ROOT (6.x or later) with PyROOT enabled
  • Python 3.10+

Install the package

bash
pip install -e .

Usage

Option 1: VS Code with GitHub Copilot Chat

The easiest way to use this MCP server is through VS Code with GitHub Copilot Chat.

1. Install GitHub Copilot Chat extension

Make sure you have the GitHub Copilot Chat extension installed in VS Code.

2. Configure MCP server in VS Code

Add the MCP server configuration to your VS Code settings. Open your settings.json (Ctrl/Cmd + Shift + P → "Preferences: Open User Settings (JSON)") and add:

json
{  "github.copilot.chat.codeGeneration.instructions": [    {      "text": "Use ROOT MCP server for data analysis"    }  ],  "mcp.servers": {		"root/mcp-server": {			"type": "stdio",			"command": "root_mcp_server",			"args": []		}  }}

Important: Replace /path/to/ROOT/build/bin/thisroot.sh with the actual path to your ROOT installation's thisroot.sh script.

3. Use in Copilot Chat

Once configured, you can use the MCP tools in GitHub Copilot Chat:

@workspace Use #root_python to execute Python code with PyROOT
@workspace Use #root_cpp to execute C++ code with ROOT

The server will automatically log executed code and results to the MCP console (visible in VS Code's Output panel).

Option 2: Command line

Start the MCP server directly:

bash
root_mcp_server

Option 3: Programmatic usage

python
from mcp.client.stdio import stdio_client, StdioServerParametersfrom mcp.client.session import ClientSession
server_params = StdioServerParameters(    command="bash",    args=["-lc", "source /path/to/thisroot.sh && python3 -m root_mcp_server.cli"],    env=None)
async with stdio_client(server_params) as (read, write):    async with ClientSession(read, write) as session:        await session.initialize()
        # Execute Python code        result = await session.call_tool("root_python", arguments={            "code": "import ROOT; print(ROOT.gROOT.GetVersion())"        })        print(result)

Available Tools

The server exposes two MCP tools:

1. root_python

Execute Python code with ROOT automatically available in scope.

Arguments:

  • code (string): Python code to execute

Returns:

json
{  "ok": boolean,  "stdout": string,  "stderr": string,  "error": string | null,  "error_type": string | null}

Example:

python
code = """import ROOTh = ROOT.TH1F("h", "Gaussian", 100, -5, 5)for i in range(10000):    h.Fill(ROOT.gRandom.Gaus(0, 1))print(f"Mean: {h.GetMean():.3f}")"""

2. root_cpp

Execute C++ code via ROOT's cling interpreter.

Arguments:

  • code (string): C++ code to execute

Returns:

json
{  "ok": boolean,  "stdout": string,  "stderr": string,  "error": string | null,  "error_type": string | null}

Example:

cpp
TH1F* h = new TH1F("h", "Gaussian;X;Y", 100, -5, 5);for(int i=0; i<10000; i++) h->Fill(gRandom->Gaus(0,1));TCanvas* c = new TCanvas("c", "Canvas", 900, 600);h->Draw();c->Update();std::cout << "Mean: " << h->GetMean() << std::endl;

Features in Detail

Error Detection

The server automatically detects C++ compilation errors by:

  • Checking the return code from ROOT.gInterpreter.ProcessLine()
  • Scanning stderr for error keywords (error:, Error:, fatal error:)

Errors are reported with ok=false and detailed error messages.

Console Logging

All code execution is logged to stderr (MCP console) with:

  • Pretty-printed code with line numbers
  • Execution status (✓ success / ❌ failure)
  • Complete stdout, stderr, and error details

Example output:

============================================================EXECUTING PYTHON CODE:  1 | import ROOT  2 | print(ROOT.gROOT.GetVersion())============================================================✓ EXECUTION SUCCESSSTDOUT:6.39/01

Graphics Support

The server initializes TApplication and supports ROOT graphics:

  • TCanvas windows (batch mode can be disabled)
  • Histogram plotting
  • ROOT event loop for interactive graphics
  • Object persistence to prevent garbage collection

Development

Running tests

bash
# Test basic functionalitypython test_mcp_client.py
# Test persistent graphicspython test_persistent_window.py
# Test histogram creationpython test_histogram.py

Project Structure

root_mcp_server/├── root_mcp_server/│   ├── __init__.py│   ├── cli.py          # Entry point│   ├── executor.py     # Code execution │   └── server.py       # MCP server definition├── test_mcp_client.py├── test_persistent_window.py├── test_histogram.py└── README.md

License

See LICENSE file.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Acknowledgments

来源:README.md,提交 0dd2d95

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

1
  1. v1.0.0最新Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分