MCP server for X-ray spectroscopy analysis via xraylarch
Project description
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
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:
- Call
larch_load_spectrumto read your data - Call
larch_normalizeto perform pre-edge subtraction and normalization - Call
larch_plotwithplot_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
- Ask Claude to interactively normalize your spectrum
- An HTML page opens in your browser with Plotly.js plots and sliders
- Adjust E0, pre-edge range, post-edge range, and polynomial degree — plots update in real time
- Click Save Parameters to download a JSON file, or Copy to Clipboard
- 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 referencelarch://docs/io— I/O functions referencelarch://docs/fitting— Fitting referencelarch://docs/feff— FEFF interface referencelarch://docs/interactive— Interactive tools referencelarch://docs/examples/xanes— XANES workflow examplelarch://docs/examples/exafs— EXAFS workflow example
Links
License
BSD-3-Clause (matching xraylarch)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xraylarch_mcp-0.3.3.tar.gz.
File metadata
- Download URL: xraylarch_mcp-0.3.3.tar.gz
- Upload date:
- Size: 46.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
565ba6a441237391037a719dddb2a2f864a32a3189b7bf3150e7d2bf9006b638
|
|
| MD5 |
78c29cfa469960e5a9765c82a85eac19
|
|
| BLAKE2b-256 |
a51a13341be49aef333dcdeec706411c32689cc862e5467f50766a85f9a4d9cb
|
File details
Details for the file xraylarch_mcp-0.3.3-py3-none-any.whl.
File metadata
- Download URL: xraylarch_mcp-0.3.3-py3-none-any.whl
- Upload date:
- Size: 41.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
10e474fe788c1f8abefa56a4d5170e9fd645240836008df9c33122dbb11814d9
|
|
| MD5 |
7b22914a9e19576ac99090f50e091d9d
|
|
| BLAKE2b-256 |
b1041060db23b65ef0b35aa9ed210a87a6102df704e147c7ca6d1823171daf0a
|