Skip to main content
Glama

MCP Refana Server

Model Context Protocol (MCP) server for Mu2e refana analysis workflows. Exposes core analysis functions as MCP tools for integration with agentic frameworks.

Environment Setup

This project requires the Mu2e analysis environment. On Mu2e gpvm's, activate the environment first:

source /cvmfs/mu2e.opensciencegrid.org/env/ana/current/bin/activate

This provides:

  • pyutils - Python interface to EventNtuple

  • uproot - ROOT file handling

  • awkward - Ragged array support

  • numpy, scipy, scikit-learn, xgboost, matplotlib

Related MCP server: rucio-mcp

Features

  • Event Counting: Signal/background extraction in kinematic regions

  • Cut Analysis: Definition and application of analysis cuts

  • Sensitivity Computation: Discovery significance, CLs limits, Feldman-Cousins intervals

  • ML Selection: BDT-based signal/background discrimination setup

  • Analysis Summaries: Dataset-level analysis results

Installation

# Activate Mu2e analysis environment
source /cvmfs/mu2e.opensciencegrid.org/env/ana/current/bin/activate

# Install mcp-refana in development mode
cd mcp-refana
pip install -e .

Running the Server

Important: Always activate the Mu2e environment before running.

# Source Mu2e environment
source /cvmfs/mu2e.opensciencegrid.org/env/ana/current/bin/activate

# Start server with stdio transport (default)
mcp-refana-server --transport stdio

Or with HTTP transport:

source /cvmfs/mu2e.opensciencegrid.org/env/ana/current/bin/activate
mcp-refana-server --transport streamable-http

Available Tools

healthcheck()

Returns server status.

count_signal_background(mom_list, time_list, mc_list, mom_range, time_range, sign)

Extract signal and background event counts in a defined kinematic window.

Parameters:

  • mom_list: Reconstructed momentum values

  • time_list: Reconstructed time values

  • mc_list: MC truth labels

  • mom_range: [min, max] momentum window

  • time_range: [min, max] time window

  • sign: "minus" (electrons) or "plus" (positrons)

Returns: Signal/background counts and statistics

analyze_cuts(cut_definitions, sign)

Initialize analysis cut configuration.

compute_sensitivity(s_expected, b_expected, b_sys_uncertainty, exposure, efficiency)

Compute physics sensitivity metrics:

  • Asimov significance Z

  • 95% CLs upper limit

  • 90% Feldman-Cousins confidence interval

initialize_ml_selector()

Set up machine learning event selector.

get_cut_efficiency(cuts_applied, n_total, n_surviving)

Calculate efficiency metrics for applied cuts.

summarize_analysis(dataset_name, sign, n_events_processed, signal_count, background_count, ml_score_mean)

Generate analysis summary for a dataset.

Integration with HEP-Multiagent

Register this server in the multiagent's config.py:

"refana": {
    "command": ["mcp-refana-server", "--transport", "stdio"],
    "description": "Mu2e refana analysis server",
}

Then use in worker nodes for agentic analysis workflows.

Architecture

src/mcp_refana/
├── __init__.py
├── server.py              # FastMCP server setup
└── mcp_tools/
    ├── __init__.py
    └── refana_wrappers.py # Tool definitions wrapping refana code

The server wraps the core refana analysis classes (Count, Analyze, MLSelect, SensitivityAnalyzer) as MCP tools, making them accessible to agents via tool calls.

Dependencies

  • mcp: Model Context Protocol framework

  • refana: Core analysis code (count, analyze, ML selection, sensitivity)

  • numpy, scipy: Numerical computing

  • scikit-learn, xgboost: Machine learning

  • uproot, awkward: ROOT file handling

  • matplotlib: Visualization

Development

Run tests:

pytest tests/

Format code:

ruff check . --fix

Contact

Sophie Middleton, Huma Jafree

Available Tools

4 tools
create_dataset_filelistA

Create a filelist for analysis from a SAM dataset definition.

    This tool prepares a dataset for use with refana analysis tools.
    
    Args:
        defname: SAM definition name (e.g., 'ensembleMDS3c')
        location: File location ('disk', 'tape', 'scratch', 'nersc')
        max_files: Limit to first N files (useful for testing)
        output_path: Path to save filelist (if None, generates temp path)
        
    Returns:
        Dictionary with filelist path and dataset information
    
ParametersJSON Schema
NameRequiredDescriptionDefault
defnameYes
locationNodisk
max_filesNo
output_pathNo

Output Schema

ParametersJSON Schema
NameRequiredDescription

No output parameters

TDQS

A4/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It mentions creating a filelist and using a temp path if output_path is None, but does not disclose side effects (e.g., file system writes, disk usage), required permissions, or potential risks such as overwriting existing files.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is efficiently structured with a clear opening line and labeled args/returns sections. It is concise without being terse, though minor redundancy (e.g., 'prepares a dataset') could be trimmed.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations and empty schema descriptions, the description covers the tool's core purpose, parameters, and return format. It lacks explicit usage guidance and behavioral details, but the presence of an output schema offsets the need to explain return values.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema descriptions are empty (coverage 0%), so the description provides critical meaning: defname's example, location's allowed values, max_files as testing limit, and output_path's fallback behavior. This adds substantial value beyond the raw schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly identifies the action (Create), resource (filelist from SAM dataset), and context (for analysis with refana tools). It distinguishes from sibling tools like list_available_datasets or get_dataset_info by focusing on creation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description states it prepares a dataset for refana analysis tools, implying usage context, but does not explicitly guide when to use this tool versus alternatives or mention when not to use it.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

get_dataset_infoA

Get information about a specific SAM dataset definition.

    Args:
        defname: SAM definition name (e.g., 'ensembleMDS3c')
        location: File location ('disk', 'tape', 'scratch', 'nersc')
        
    Returns:
        Dictionary with dataset information: file count, size, availability
    
ParametersJSON Schema
NameRequiredDescriptionDefault
defnameYes
locationNodisk

Output Schema

ParametersJSON Schema
NameRequiredDescription

No output parameters

TDQS

A3.8/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided. Description mentions return fields (file count, size, availability) but does not disclose if the operation is read-only, requires authentication, or has any side effects. Adequate but minimal.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Description is concise, structured with Args and Returns sections, and front-loaded with purpose. No extraneous text.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Output schema exists (not shown but indicated), so description doesn't need to detail return format. However, usage guidelines are missing, and parameter semantics could be slightly richer. Overall fairly complete for a simple info tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, but description adds examples for defname and lists allowed values for location (disk, tape, scratch, nersc), which adds meaning. However, it doesn't mention the default value for location.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Description clearly states 'Get information about a specific SAM dataset definition' with specific verb and resource. It provides example parameter values and distinguishes from sibling tools like list_available_datasets.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use this tool versus siblings. For instance, it doesn't contrast with 'list_available_datasets' or suggest scenarios for querying a specific definition.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

list_available_datasetsA

List available SAM dataset definitions for Mu2e analysis.

    Returns:
        Dictionary with available datasets and their descriptions
    
ParametersJSON Schema
NameRequiredDescriptionDefault

No parameters

Output Schema

ParametersJSON Schema
NameRequiredDescription

No output parameters

TDQS

A3.8/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided; description only states return type, lacking details on idempotency, authorization, or side effects. As a read-only list, it could note that it is safe to call repeatedly.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two sentences with no filler: states purpose and return value. Highly efficient and front-loaded.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Adequate for a parameterless tool with an output schema; clearly identifies what is listed and the return format. No missing elements for its simplicity.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

No parameters, so schema coverage is trivially 100%. Description adds no param info since none exist, earning baseline of 4.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Describes listing available SAM dataset definitions for Mu2e analysis, with a clear verb and resource; distinguishes from sibling tools like get_dataset_info or create_dataset_filelist.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Implied usage for browsing datasets before using other tools, but no explicit guidance on when to use or not use this tool versus alternatives.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

summarize_analysisA

Generate a summary of analysis results for a dataset.

    Args:
        dataset_name: Name of the dataset analyzed
        sign: Particle sign
        n_events_processed: Total events processed
        signal_count: Reconstructed signal events
        background_count: Reconstructed background events
        ml_score_mean: Mean ML BDT score (if available)
        
    Returns:
        Dictionary with analysis summary
    
ParametersJSON Schema
NameRequiredDescriptionDefault
signNominus
dataset_nameYes
signal_countNo
ml_score_meanNo
background_countNo
n_events_processedNo

Output Schema

ParametersJSON Schema
NameRequiredDescription

No output parameters

TDQS

A3.5/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden but fails to disclose behavioral traits such as whether the tool is read-only, requires authentication, or has side effects. It only describes the input and output without warning of any limitations or behaviors.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise and well-structured with a clear one-line purpose followed by Args and Returns sections. However, the parameter list is somewhat formulaic, and the Returns section is minimal.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the existence of an output schema (not shown), the description's minimal return statement is acceptable. Parameter descriptions are complete for basic use, but the tool's purpose is fully covered. It is complete enough for the given complexity.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Despite 0% schema description coverage, the description provides clear semantic meanings for all 6 parameters in the Args block (e.g., 'Total events processed' for n_events_processed). This adds value beyond the schema, though some details like allowed values for 'sign' are missing.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description states 'Generate a summary of analysis results for a dataset.' which is a specific verb ('generate') and resource ('summary of analysis results'), and it clearly distinguishes from sibling tools like 'list_available_datasets' or 'get_dataset_info'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives, no prerequisites, and no exclusions. It only states the basic function.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

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

  1. 4 tool updatesv0.1.0
    • First observedcreate_dataset_filelist
    • First observedget_dataset_info
    • First observedlist_available_datasets
    • First observedsummarize_analysis

TDQS

A4/5.0

Scored across 4 tools

Disambiguation5/5

Each tool has a distinct purpose: listing datasets, retrieving dataset info, creating filelists, and summarizing analysis results. No overlap.

Naming Consistency5/5

All tool names follow a consistent verb_noun pattern in snake_case, making them predictable and easy to navigate.

Tool Count5/5

Four tools is appropriate for a specialized analysis server, covering key steps without being excessive or insufficient.

Completeness4/5

The set covers dataset discovery, preparation, and result summarization, but lacks a tool to trigger or configure an actual analysis run, which is a minor gap.

Maintenance

ActivitySlowing
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

  • 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