Open-source MCP server · Mass spectrometry

Ask your AI assistant about your mass spectrometry data.

MSMCP puts your own data in front of an AI client — Claude, Zed, or any other MCP host. Ask it to open an mzML, MGF or imzML file, check a precursor mass against a formula, compute isotope and adduct patterns, score an MS/MS spectrum against your MSP library, or summarise QC across a run.

The model reasons. The tools compute.

MCP — the Model Context Protocol — is the open standard that lets an assistant call tools and read files it is given. MSMCP is the mass spectrometry end of it.

  • 15 tools
  • mzML · MGF · imzML
  • stdio, local only
  • no credentials
  • MIT

Run it now

uvx --python 3.13 --from msmcp==1.0.2 msmcp

How the peaks stay out of the prompt

  1. 1an acquisition file is parsed in the server process. mzML, MGF and optional imzML are read locally; vendor formats are refused with conversion guidance.
  2. 2load_spectrum(…) returns metadata and a reference.
  3. 3
    reference =
    "ptr:spectrum:264a5ae9…"

    An opaque, random, expiring handle — never an address, an id or a path.

  4. 4Reuse it for summary, similarity or search, and release it when finished: summarise_reference · compute_cosine · search_library · release_reference

Large peak arrays stay server-side; the host carries references, job IDs and compact reports.

Reproducible demo · release 1.0.2

A synthetic library search, not a chemical finding.

The release includes a small caffeine MGF query and an MSP library. Put both files under the configured allowed root, load the MS2 spectrum, dispatch a search, then poll its job. The fixture deliberately duplicates a library record, so this verifies the tool flow — not identification accuracy or scientific significance.

synthetic fixture · MSMCP 1.0.2 · stdio

0 · Prompt to your assistant

“Load /data/caffeine_spectrum.mgf and search it against /data/caffeine_library.msp with instrument_class="orbitrap".”

1 · Load the query

load_spectrum(file_path="/data/caffeine_spectrum.mgf", spectrum_index=0)

2 · Search and poll

search_library(database_file="/data/caffeine_library.msp", spectrum_reference="ptr:spectrum:…", scoring_method="classical", instrument_class="orbitrap")
check_search_status(job_id="<job ID returned by search_library>")

Example candidate report

Synthetic caffeine library search result
RankCandidateScorePrecursor m/z
1Caffeine C8H10N4O21.0000195.0877

These are fabricated demonstration spectra and an exact synthetic match. The score is a ranking value, not an identification probability or error rate.

Reproduce with the release 1.0.2 example files. Before ranking, search_library refuses non-MS2 queries, applies the chosen instrument class's precursor tolerance, and excludes records whose polarity, charge or adduct conflicts (entries omitting context remain ranked as unknown). Production search reports similarity-ranked candidates only; it does not report p-values, q-values or calibrated FDR.

Grounded, deterministic, and honest about its own boundaries.

LLMs should reason about mass spectrometry, not perform the arithmetic. Every scientific value on this page is a tool's output rather than a model's recollection, and every derived result carries a record of how it was made. That is the standard AI-assisted mass spectrometry should be held to, and MSMCP is infrastructure for it.

Grounded analysis

MSMCP computes exact masses, adduct shifts, isotope envelopes, ppm gates and cosine scores in deterministic Python tools. The glucose isotope figure below shows output from the released tool.

Deterministic and auditable

Long searches run as jobs that a client can poll. Loaded spectra and search reports include provenance for their inputs and parameters; a score remains a ranking, not a confidence estimate.

Data control

MSMCP runs locally over stdio, makes no network calls of its own, and confines file reads to an allowed root under size caps. The host still controls the process with your permissions, so anyone who can drive that client can drive MSMCP; run it on a machine you own, never as a network service. See the security notes.

Tool output · annotate_isotopes

annotate_isotopes("C6H12O6", isotopologues=3)

M+1 and M+2 are plotted on a 0–0.10 vertical axis (×10 magnification); on the full-scale panel above they are 6.86 % and 1.43 % of the monoisotopic peak. Values are displayed to the tool's four-decimal precision.

Also verified in the tree

  • 15 tools across inspection, chemistry, similarity, chromatograms, quality control and library search. Their names match the 1.0.2 server's registered tool surface.
  • Readers for mzML (including zlib-compressed arrays, parsed by MSMCP itself), strict MGF, and imzML imaging data through the optional extra. Vendor formats are refused with conversion guidance.
  • MSP/NIST and MGF libraries are read from disk behind the same security boundary as an acquisition, so search_library can search supported local libraries without an upload or hosted service.
  • Similarity validation is documented as PARTIAL: the pinned comparison is reproducible, but it does not establish open-set accuracy or calibrated confidence.
  • Spectral foundation models plug in behind one adapter (DreaMS runs real inference; LSM-MS2 awaits public weights). Core MSMCP never requires model weights — and if a model is unavailable it says so rather than returning a number that looks learned.

Instrument-class defaults

Tools that apply tolerances accept instrument_class and record the chosen defaults in provenance. Unit-resolution classes use Da rather than ppm because a fixed ppm gate shrinks below 1 Da at small-molecule masses.

MSMCP 1.0.2 instrument class default tolerances
ClassPrecursorMS2 / diag.SNR bands
generic
default
5.0 ppm0.02 Da5 / 20
orbitrap
accurate mass
5.0 ppm0.01 Da5 / 20
tof
reflectron TOF
15.0 ppm0.05 Da5 / 20
ion_trap
unit resolution
0.5 Da0.5 Da5 / 20
triple_quad
unit resolution
0.7 Da0.7 Da5 / 20

These are documented conventions, not measured from raw file headers; compute_cosine also accepts an explicit ms2_tolerance override in Da.

Validation status (1.0.2)

Passing unit tests is not scientific validation. MSMCP separates software tests from independent evidence in SCIENTIFIC_VALIDATION.md.

VALIDATEDExact-mass chemistry
annotate_isotopes (exact multinomial expansion collapsed to nominal centroids; AME2020/CIAAW constants cited) and predict_adduct_offset (14 canonical adducts; CODATA constants).
PARTIALmzML 1.1.0, similarity & MCP
mzML float32/64 + zlib decoding against an independent writer (vendor quirks and Numpress excluded); ClassicalScorer vs matchms 0.33.1 on MassBank 2026.03 positive ESI MS2; stdio + SHA-256 provenance.
NOT VALIDATEDSearch significance, MGF & imzML
Production search reports similarity rankings only (p/q-values and FDR are withdrawn). MGF, imzML, and embedding scorers lack independent reference validation. Hardware control is permanently out of scope.

Install MSMCP 1.0.2 from PyPI.

MSMCP 1.0.2 is published on PyPI and requires Python 3.13 or later. Install it in an isolated environment with uv; the command below is pinned to the published version. No API key, account or hosted service is needed.

PyPI quickstart (recommended)

uvx --python 3.13 --from msmcp==1.0.2 msmcp

This is the stdio server command for your MCP host. The release wheel is fetched from PyPI into uv's isolated tool environment; source cloning is not required.

pip, uv tool & optional extras

uv tool install --python 3.13 msmcp==1.0.2
pip install msmcp==1.0.2
msmcp[imaging]
Adds imzML (+ .ibd) reading via massflow>=0.1.2,<0.2. Keep separate from the unrelated analytical MassFlow engine; importing the imaging package creates a logs/ directory in the working directory.
msmcp[chem]
Installs RDKit for SMILES-to-formula conversion in annotate_isotopes(is_smiles=True). Explicit formulas work in the core install without RDKit.
msmcp[ml] + dreams
Installs PyTorch for embedding similarity; DreaMS weights require installing dreams from source, and LSM-MS2 awaits public weights.
pynumpress
Optional decoder required only if your .mzML files use MS-Numpress compression (zlib-compressed mzML works out of the box).

Claude Desktop & standard MCP hosts

{
  "mcpServers": {
    "msmcp": {
      "command": "uvx",
      "args": [
        "--python",
        "3.13",
        "--from",
        "msmcp==1.0.2",
        "msmcp"
      ],
      "env": {
        "MSMCP_ALLOWED_ROOT": "/absolute/path/to/ms-data"
      }
    }
  }
}

Uses the standard mcpServers schema. Keep uvx on the host's PATH (or pass its full path) and point MSMCP_ALLOWED_ROOT at the directory containing your acquisitions and libraries.

Zed configuration

{
  "context_servers": {
    "msmcp": {
      "command": "uvx",
      "args": [
        "--python",
        "3.13",
        "--from",
        "msmcp==1.0.2",
        "msmcp"
      ],
      "env": {
        "MSMCP_ALLOWED_ROOT": "/absolute/path/to/ms-data"
      }
    }
  }
}

Uses Zed's context_servers schema with the exact same pinned uvx command and MSMCP_ALLOWED_ROOT boundary. Once connected, ask your assistant to run ping or inspect a file inside the allowed root.

Environment configuration

Every runtime limit has a conservative default; if MSMCP_ALLOWED_ROOT is unset, it defaults to the server's working directory. Set these in your MCP client's env block when needed.

MSMCP 1.0.2 environment configuration variables
VariableDefaultEffect
MSMCP_ALLOWED_ROOTprocess working directoryDirectory subtree that all file-reading tools (including library paths) are confined to.
MSMCP_MAX_FILE_SIZE_BYTES500 MiBPer-file ceiling, enforced on inflated bytes for .gz and zlib-compressed arrays.
MSMCP_MAX_SPECTRA1000Per-request spectrum cap for indexed loads and QC scans (extract_chromatograms caps at 10,000).
MSMCP_MAX_REFERENCES128Maximum live ptr:spectrum:… handles held in server memory before new registrations fail.
MSMCP_MAX_TOTAL_BYTES512 MiBTotal payload ceiling across active server-side data references.
MSMCP_REFERENCE_TTL_SECONDS3600Reference expiration in seconds (0 disables lazy expiry).
MSMCP_EMBEDDING_BACKENDrealreal requires installed DreaMS/LSM-MS2 weights; mock selects test-only stand-ins.

15 tools, one question each.

Every call below matches the signature and defaults the server advertises in tools/list. When a spectrum is loaded with load_spectrum, summarise_reference, compute_cosine and search_library accept its ptr:spectrum:… handle instead of copying peaks across MCP/JSON.

Inspection and references

load_mzml_summaryread-only · text summary

What is in this file?

load_mzml_summary(file_path="/data/run.mzML", max_spectra=5)

Per spectrum: MS level, retention time, total ion current, peak count, base peak (with optional noise_threshold filter; max_spectra 1–50). The footer states the file's total spectrum count.

list_spectraread-only · text index

Which spectra are MS2, and which index do I want?

list_spectra(file_path="/data/run.mzML", ms_level=2)

An index table — spectrum index, MS level, retention time, precursor m/z, peak count — across .mzML, .mzML.gz, .mgf, .mgf.gz, or .imzML (supports ms_level, min_peaks, and max_spectra up to 1,000).

load_spectrumread-only · metadata + ptr handle

Hold one spectrum server-side.

load_spectrum(file_path="/data/run.mzML", spectrum_index=0)

Metadata plus a ptr:spectrum:… handle. The peak array stays in the server's memory instead of entering the conversation; index must sit below MSMCP_MAX_SPECTRA.

summarise_referenceread-only · text + provenance

What is behind this handle?

summarise_reference(reference="ptr:spectrum:264a5ae9…")

The same compact spectrum block, read from memory rather than the file, followed by the reference's provenance.

release_referencestate-changing · idempotent · confirmation

Free that memory now rather than waiting for expiry.

release_reference(reference="ptr:spectrum:264a5ae9…")

Confirmation. Releasing an unknown or already-released reference is reported, not raised, so a retry is safe.

Exact-mass chemistry

validate_precursorread-only · verdict + ppm

Does this precursor mass fit the formula I think it does?

validate_precursor(theoretical_mass=180.0634, experimental_mass=180.0634)

Mass error and a PASSED or REJECTED verdict against the optional instrument_class (default generic: 5.0 ppm; unit-resolution classes use Da).

predict_adduct_offsetread-only · mass shift

What does [M+H]+ add, exactly?

predict_adduct_offset(adduct_string="[M+H]+")

Polarity, charge state, exact mass shift in daltons and offset formula for 14 canonical adducts: [M+H]+, [M+Na]+, [M+K]+, [M+NH4]+, [M+H-H2O]+, [M+2H]2+, [M+3H]3+, [M+2Na-H]+, [M-H]-, [M+Cl]-, [M+HCOO]-, [M+CH3COO]-, [M-H2O-H]-, and [M+Na-2H]-. Anything else is refused.

annotate_isotopesread-only · isotope table

What should the isotope envelope look like for this formula?

annotate_isotopes(identifier="C6H12O6", isotopologues=3)

Monoisotopic mass and M … M+(n-1) masses (isotopologues 1–10) with abundances normalised to M = 1.0000 via exact multinomial expansion (collapsed to nominal centroids). Set is_smiles=True with msmcp[chem] for SMILES input; fails closed without RDKit.

Spectral similarity

compute_cosineread-only · score + unmatched peaks

How similar are these two MS/MS spectra?

compute_cosine(query_peaks=[[100.0, 1.0]], reference_peaks=[[100.0, 1.0]])

A cosine score and matched/unmatched peak details. Each side accepts inline peaks or a ptr:spectrum:… reference (query_reference / reference_reference). Defaults to scoring_method='classical' (greedy 1-to-1 matching under ms2_tolerance or instrument_class); 'dreams' and 'lsm-ms2' require model weights.

Chromatograms

extract_chromatogramsread-only · structuredContent (v1.0)

Extract TIC, BPC and target-ion traces from an mzML acquisition.

extract_chromatograms(file_path="/data/run.mzML", targets_mz=[195.0877], tolerance=5.0, tolerance_unit="ppm", ms_level=1)

Structured scan-level traces (schema_version '1.0' in structuredContent) with mandatory SHA-256 digest and completeness metadata. Accepts up to 20 XIC targets, optional retention_time_range_min, and up to 10,000 scanned spectra. No smoothing, blank subtraction or identification is performed.

Quality control

generate_qc_summaryread-only · QC report

Was this run worth searching?

generate_qc_summary(file_path="/data/run.mzML")

Spectrum and total-ion-current counts, peak density, estimated signal-to-noise ratio, and diagnostic-ion prevalence (optional instrument_class). Scans up to MSMCP_MAX_SPECTRA and states when full-acquisition coverage is unconfirmed.

search_libraryread-only · async job ID

Match this MS2 against the library I already have.

search_library(database_file="/data/libraries/MassBank.msp", spectrum_reference="ptr:spectrum:…", scoring_method="classical")

Returns a job ID immediately (accepts spectrum_reference or experimental_file + spectrum_index, plus optional instrument_class). Reads .msp/.msp.gz and .mgf/.mgf.gz from disk behind the allowed root; unrecognised paths fall back to a labelled synthetic library. Refuses non-MS2 queries and gates candidates on precursor tolerance, polarity, charge and adduct; reports similarity rankings only.

check_search_statusread-only · status / ranked report

Is the scan finished?

check_search_status(job_id="2aafd7b8f1c44b42a987a34b0f724610")

Queued, running, completed, failed or cancelled — then delivers the full ranked report once (later polls return a short digest unless full_report=True), naming the scorer, tolerances, library source and provenance.

cancel_searchstate-changing · idempotent · cancellation

Stop the scan.

cancel_search(job_id="2aafd7b8f1c44b42a987a34b0f724610")

Cancellation. A job that already finished is reported as finished, and a cancelled scan's partial work is discarded.

Diagnostics

pingread-only · health status

Is the server alive?

ping()

Operational status and optional imaging-distribution metadata. This does not verify imzML compatibility; call it first when another tool fails unexpectedly.

MCP integration notes

  • Transport & framing: JSON-RPC over stdio (mcp[cli]>=2.2.0). Diagnostics write to stderr; stdout carries MCP framing only.
  • Annotations: all 15 tools declare open_world_hint=False. Thirteen are read_only_hint=True; only release_reference and cancel_search mark state mutation (both idempotent_hint=True).
  • Structured outputs: extract_chromatograms publishes an MCP outputSchema (schema_version: "1.0") and returns parallel arrays in structuredContent.
  • Async execution:search_library uses an in-memory job executor (4 concurrent jobs max, 1-hour finished-job TTL) polled via check_search_status; MSMCP does not implement the MCP Tasks protocol, and in-flight jobs do not survive a server restart.
  • Failure modes: boundary, format, and dependency failures (PathEscapeError, UnsupportedFormatError, MalformedFileError, MissingDependencyError, SpectrumCountExceededError, EmbeddingBackendUnavailable) surface as MCP tool errors with diagnostic details in stderr logs.

Everything authoritative lives with the code.

The package, release notes and scientific documentation are pinned to 1.0.2 so their contracts stay aligned with this page.

Reproducible examples

Contact. There is no mailing list and no contact form. Bug reports, questions and feature discussion belong in GitHub Issues, where the answer stays searchable for the next person.