Skip to main content

xraylarch-mcp

MCP (Model Context Protocol) server that wraps xraylarch for X-ray spectroscopy analysis. Load, process, analyze, and plot XAS/XAFS spectra through Claude Desktop or Claude Code with natural language tool calls. Supports XANES normalization, EXAFS extraction, Fourier transforms, linear combination fitting, PCA, FEFFIT shell fitting, and publication-quality plotting.

Installation

pip install xraylarch-mcp

Requires Python 3.11 or newer. The server is built on version 2 of the MCP Python SDK (mcp>=2).

Configuration

Claude Desktop

Add to your Claude Desktop configuration (claude_desktop_config.json):

{
  "mcpServers": {
    "xraylarch": {
      "command": "python",
      "args": ["-m", "xraylarch_mcp"]
    }
  }
}

Claude Code

claude mcp add xraylarch -- python -m xraylarch_mcp

Quick Start

Ask Claude:

"Load the spectrum at ~/data/fe_foil.xdi and show me the normalized XANES"

Claude will:

  1. Call larch_load_spectrum to read your data
  2. Call larch_normalize to perform pre-edge subtraction and normalization
  3. Call larch_plot with plot_type="norm" to generate a publication-quality plot

Tool Reference

I/O Tools

Tool Description
larch_load_spectrum Load a spectrum from file (.xdi, .dat, .csv, .prj, etc.)
larch_read_athena_project Read/inspect Athena project files
larch_list_groups List all loaded spectrum groups
larch_inspect_group Detailed view of a group's arrays and scalars
larch_remove_group Remove a group to free memory

XAFS Analysis Tools

Tool Description
larch_normalize Pre-edge subtraction and normalization (wraps pre_edge)
larch_autobk EXAFS background removal (AUTOBK algorithm)
larch_xftf Forward Fourier transform: chi(k) -> chi(R)
larch_xftr Back Fourier transform: chi(R) -> chi(q)
larch_fluo_corr Fluorescence self-absorption correction
larch_mback_norm MBACK normalization (alternative for problematic data)
larch_estimate_noise Noise estimation in chi(k) and chi(R)
larch_cauchy_wavelet Cauchy wavelet transform for simultaneous k- and R-resolution
larch_rebin Rebin to standard 3-region XAFS energy grid

Plot Tools

Tool Description
larch_plot Publication-quality plots (mu, norm, flat, dmude, chi_k, chi_r, chi_q, cauchy_wavelet)

Math Tools

Tool Description
larch_smooth Smooth arrays with Lorentzian/Gaussian/Voigt kernel
larch_deriv Numerical derivative
larch_interpolate Interpolate onto new energy grid
larch_merge_groups Merge/average multiple spectra
larch_deglitch Remove glitch points

Fitting Tools

Tool Description
larch_lcf Linear combination fitting against standards
larch_pca Principal Component Analysis
larch_feffit FEFFIT EXAFS shell fitting
larch_peak_fit Peak fitting (Gaussian, Voigt, etc.)

Interactive Tools

Tool Description
larch_interactive_norm Open an interactive HTML page to tune normalization parameters
larch_apply_norm_params Apply normalization parameters from a saved JSON file

Interactive normalization workflow

  1. Ask Claude to interactively normalize your spectrum
  2. An HTML page opens in your browser with Plotly.js plots and sliders
  3. Adjust E0, pre-edge range, post-edge range, and polynomial degree — plots update in real time
  4. Click Save Parameters to download a JSON file, or Copy to Clipboard
  5. Tell Claude to apply the saved parameters

"Load Pdfoil.prj and let me interactively choose the normalization parameters"

Advanced

Tool Description
larch_run_code Execute arbitrary Python code in the larch session

Resources

The server exposes documentation resources that Claude can read on demand:

  • larch://docs/xafs — XAFS analysis reference
  • larch://docs/io — I/O functions reference
  • larch://docs/fitting — Fitting reference
  • larch://docs/feff — FEFF interface reference
  • larch://docs/interactive — Interactive tools reference
  • larch://docs/examples/xanes — XANES workflow example
  • larch://docs/examples/exafs — EXAFS workflow example

Releasing

Releases go to PyPI from GitHub Actions (.github/workflows/publish.yml), with no token: PyPI trusts this repository's workflow directly.

  1. Set the new version in pyproject.toml and src/xraylarch_mcp/__init__.py, and merge that to main.
  2. Tag the merge commit and push the tag, e.g. git tag v0.4.1 && git push origin v0.4.1, or publish a GitHub release with a new tag v0.4.1.

The workflow runs the tests, checks that the tag matches both version strings, builds the package and uploads it.

One-time setup: in the project's PyPI settings under Publishing, add a GitHub publisher with owner Joint-Photon-Sciences-Institute, repository xraylarch-mcp, workflow publish.yml and environment pypi.

License

BSD-3-Clause (matching xraylarch)

Metadata

Release files for xraylarch-mcp 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xraylarch-mcp 0.4.0
File Size Uploaded Provenance
xraylarch_mcp-0.4.0.tar.gz 83.2 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for xraylarch-mcp 0.4.0
File Interpreter ABI Platform
xraylarch_mcp-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 128.0 kB

Release files / xraylarch_mcp-0.4.0.tar.gz

Download URL xraylarch_mcp-0.4.0.tar.gz
Size 83.2 kB
Tags Source
SHA-256 checksum
How to use checksums
780b2a18500466669ead8192037c690834da97c649842262a9e678df3f3a7b9f
BLAKE2b-256 checksum
How to use checksums
19b66551e4792942b4a97d43874ffb7d5da6208b49f32e50a89c374533428770
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 17, 2026.

Transparency log

Release files / xraylarch_mcp-0.4.0-py3-none-any.whl

Download URL xraylarch_mcp-0.4.0-py3-none-any.whl
Size 44.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
48cbe732fed64587602189cd1c6ab6930394de57f8ac5facbefb2bfd188703cc
BLAKE2b-256 checksum
How to use checksums
97c621cf830a1b2e2e01b83b004313dd0832f89e73525826086e6da79a5c25bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 17, 2026.

Transparency log

Security for xraylarch-mcp 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for xraylarch_mcp-0.4.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 17, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page