Skip to main content
Glama
quantnuc-inverse MCP Server

quantnuc-inverse MCP Server

by callmesobhan

quantnuc-inverse

Quantitative PET/SPECT Image-Formation, Partial-Volume (PVE), PSF-Gibbs & Cross-Scanner Harmonization Inverse Engine with Frontier Agent Harness & MCP Server

Python 3.11 | 3.12 Version: 0.2.0 License: Apache-2.0 Tests: 38 Passed Coverage: 95.4% Ruff: 0 Errors MCP: JSON-RPC 2.0

Research Software — NOT A MEDICAL DEVICE. This repository is strictly for nuclear medicine physics research, phantom benchmarking, method development, and educational exploration. It is not FDA-cleared, CE-marked, or validated for clinical diagnosis, patient staging, or therapeutic dosimetry prescription.


Why quantnuc-inverse?

General-purpose AI chat tools cannot run 3D spatially variant image-formation physics, invert ill-conditioned Geometric Transfer Matrices to machine precision, or synthesize EARL2/MIRD-23 harmonization filters under cryptographic provenance. quantnuc-inverse solves five high-stakes quantitative nuclear medicine physics problems in one auditable Python 3.12 + MCP engine:

  1. 3D Forward Image Formation & PSF-Gibbs Ringing: Spatially variant PET/SPECT PSF & collimator-detector response (CDR), OSEM/BSREM iteration convergence, and activity-conserving Difference-of-Gaussians Gibbs edge overshoot ("SUVmax inflation").

  2. Exact & Regularized Partial-Volume Correction (PVC): Multi-region Rousset Geometric Transfer Matrix (GTM, forward re-projection residual $\le 10^{-6}$), voxel-wise Müller–Gärtner PVC, and Bayesian regularized recovery with calibrated [SUV_p05, nominal, SUV_p95] bias–variance intervals.

  3. EARL1 / EARL2 / QIBA / MIRD-23 Harmonization Filter Synthesis: Bounded nonlinear optimization synthesizing the minimal Gaussian or Butterworth post-reconstruction filter (FWHM in mm) and iteration/BSREM-$\beta$ guidance across multi-vendor SiPM PET, PMT PET, TOF-PSF PET, and CZT SPECT/CT fleets.

  4. CT-AC Respiratory Mismatch Forensics: Exact line-integral attenuation bias $\exp!\left(\int \Delta\mu,ds\right)$ at the lung–diaphragm / liver-dome boundary separating false-cold liver dome vs. false-hot basal lung artifacts, gated by hard SEVERE_CT_AC_MISMATCH abstention.

  5. Frontier Agent Forensics Physicist & MCP Server: Hypothesis-falsifying longitudinal $\Delta\text{SUV}$ attribution, Saltelli–Jansen QMC global Sobol' variance decomposition, independent Critic-Verifier Audit, SHA-256 provenance ledgers, and 6 JSON-RPC 2.0 MCP tools.


Related MCP server: Auditory Binaural Masking Level Difference (BMLD) MCP Server

System Architecture

flowchart LR
    subgraph Input["Validated Physics IR & DICOM I/O"]
        IR["ir.py<br/>ScannerSpec, ReconConfig,<br/>LesionROI, EARLCorridorSpec"]
        DCM["dicom_io.py<br/>pydicom PT/NM/CT Loader<br/>SUVbw / SUVlbm + Decay Gates"]
    end

    subgraph Core["Quantitative Nuclear Physics Engine"]
        FWD["forward_image_formation.py<br/>3D PSF/CDR + Gibbs DoG +<br/>NEMA DRO + CT-AC exp(∫Δμ ds)"]
        PVC["pve_inverse_solver.py<br/>Rousset GTM (res ≤ 1e-6),<br/>Müller–Gärtner, Bayesian CI"]
        EARL["earl_harmonizer.py<br/>EARL1/EARL2/QIBA/MIRD-23<br/>Minimal Filter Optimizer"]
        SOBOL["sobol_sensitivity.py<br/>Saltelli–Jansen QMC<br/>S1, ST & Interactions"]
    end

    subgraph Audit["Provenance, Agent Harness & MCP"]
        PROV["provenance.py<br/>SHA-256 Chain Ledger &<br/>5 Hard Abstention Gates"]
        AGENT["agent_orchestrator.py<br/>ΔSUV Forensics Physicist +<br/>Critic-Verifier Audit Dossier"]
        MCP["mcp_server.py<br/>JSON-RPC 2.0 stdio<br/>6 Provenance-Gated Tools"]
    end

    IR --> FWD & PVC & EARL & SOBOL
    DCM --> PROV --> PVC & AGENT
    FWD --> PVC & EARL & AGENT
    PVC & EARL & SOBOL --> AGENT --> PROV
    AGENT --> MCP

Quantitative Benchmark Dashboard

Metric / Verification Gate

Target / Standard

Verified Engine Performance

Rousset GTM Re-Projection Residual (6-sphere 3D NEMA DRO)

<= 1.0e-6

4.4e-16 (machine precision)

Total Activity Conservation Error (closed partition & Gibbs DoG)

<= 1.0e-6

< 1.0e-10

Multi-Vendor Fleet Corridor Violation (SiPM, TOF-PSF, PMT → EARL2; CZT SPECT → MIRD-23)

0.000 across all 6 spheres

4 / 4 feasible, max violation 0.0000

PET DICOM SUVbw / SUVlbm Round-Trip Fidelity (START & ADMIN decay)

< 0.1% vs. analytical

< 0.05%

CT-AC +10 mm / −10 mm Shift (511 keV PET)

Physical exponential bias

−25.8% (false-cold) / +34.7% (false-hot)

ΔSUV Attribution Conservation Error (4 clinical scenarios)

<= 0.15%

0.01%

Test Suite, Coverage & Static Analysis

>= 25 tests, 0 warnings, >= 75% cov

38 passed, 0 warnings, 95.38% coverage, 0 ruff errors


Publication-Grade Visual Benchmarks (300-DPI PNG + Vector PDF)

All six figures are reproducibly generated via scripts/generate_figures.py and audited visually for publication clarity.

1. NEMA NU 2-2018 6-Sphere Image Formation, PSF-Gibbs Overshoot & Rousset GTM Recovery

NEMA PSF-Gibbs Formation and GTM Recovery

2. Multi-Scanner EARL1 / EARL2 / MIRD-23 Recovery Coefficient Corridors (Pre vs. Post Harmonization)

EARL Harmonization Corridors

3. Partial-Volume Bias vs. Inverse Recovery & 90% Bias–Variance Uncertainty Ribbons

PVE Inverse Uncertainty Curve

4. CT-PET/SPECT Lung–Liver Dome Respiratory AC Mismatch Forensics & Hard Abstention Gate

CT-AC Respiratory Mismatch Forensics

5. Frontier Agent Longitudinal ΔSUV Forensics Attribution Waterfall

Longitudinal SUV Attribution

6. Saltelli–Jansen QMC Global Sobol' Sensitivity (Small vs. Large Lesion Regime Crossover)

Sobol Quantitative Variance Sensitivity

7. MIRD-26 $^{177}\text{Lu}$ PVE-Propagated Theranostic Absorbed Dose & PET Positron-Range Loss (v0.2.0)

Theranostics PVE Dosimetry and Positron Range

8. Noise-Constrained EARL2 Pareto Frontier ($\text{COV} \le 15%$) & Necrotic-Core RBV PVC (v0.2.0)

EARL2 Noise Pareto Frontier and RBV PVC


Quick Start

# Install with uv (Python 3.12 recommended)
uv sync --python 3.12 --extra dev

# Stage NEMA NU 2-2018 DRO DICOMs + SHA-256 manifest
uv run python scripts/fetch_public_nucmed_sample.py

# Regenerate all 6 publication-grade figures (PNG + PDF)
uv run python scripts/generate_figures.py

# Run test suite, coverage, and linter
uv run pytest --cov=quantnuc_inverse --cov-report=term-missing
uv run ruff check src tests scripts

API, Agent Harness & MCP Workflows

from quantnuc_inverse import (
    LesionROI,
    build_reference_scanner_fleet,
    get_corridor_spec,
    invert_lesion_activity,
    synthesize_harmonization_filter,
)

# 1. Synthesize minimal Gaussian EARL2 filter for a Digital SiPM TOF-PSF PET scanner
sipm_scanner, sipm_recon = build_reference_scanner_fleet()[0]
harm = synthesize_harmonization_filter(sipm_scanner, sipm_recon, get_corridor_spec("EARL2"))
print(f"Optimal FWHM: {harm.optimal_post_filter_fwhm_mm:.2f} mm | Post violation: {harm.max_corridor_violation_after:.4f}")

# 2. Invert true lesion SUV from observed partial-volume-corrupted ROI mean
harm_recon = sipm_recon.model_copy(update={"post_filter_fwhm_mm": harm.optimal_post_filter_fwhm_mm})
roi = LesionROI(lesion_id="L_12mm", diameter_mm=12.0, observed_suv_mean=5.1, background_suv=2.0)
result = invert_lesion_activity(roi, sipm_scanner, harm_recon, method="GTM_EXACT")
print(
    f"Recovered SUV: {result.recovered_activity_nominal:.2f} "
    f"[p05={result.recovered_activity_p05:.2f}, p95={result.recovered_activity_p95:.2f}] "
    f"| Re-proj residual={result.forward_reprojection_residual:.2e}"
)
from quantnuc_inverse.harness.agent_orchestrator import QuantitativeImagingForensicsAgent

agent = QuantitativeImagingForensicsAgent()
dossier = agent.build_complete_dossier()
md_path, json_path = dossier.write_bundle("outputs/dossier")
print(f"Audit Passed: {dossier.audit_report.overall_passed} | Gate: {dossier.audit_report.quantifiability_gate}")
print(f"Dossier: {md_path} | SHA-256 Ledger: {json_path}")

Start the stdio MCP server via:

uv run quantnuc-mcp

Or register in an MCP client configuration:

{
  "mcpServers": {
    "quantnuc-inverse": {
      "command": "uv",
      "args": ["run", "--directory", "/path/to/quantnuc-inverse", "quantnuc-mcp"]
    }
  }
}

Exposed Provenance-Gated Tools (9):

  • quantnuc_forward_nema_rc — 3D NEMA NU 2-2018 6-sphere RCmean / RCmax / RCpeak simulation.

  • quantnuc_invert_pve_activity — Rousset GTM, Müller–Gärtner, or Bayesian PVC inversion with 90% CI.

  • quantnuc_synthesize_earl_filter — Minimal Gaussian/Butterworth EARL1/EARL2/QIBA/MIRD-23 filter synthesizer.

  • quantnuc_audit_ct_ac_mismatch — Exact $\exp(\int \Delta\mu,ds)$ CT-AC respiratory bias & abstention audit.

  • quantnuc_diagnose_suv_shift — Longitudinal $\Delta\text{SUV}$ hypothesis falsification & attribution.

  • quantnuc_run_sobol_sensitivity — Saltelli–Jansen QMC global Sobol' sensitivity ($S_1, S_T$, bootstrap CIs).

  • quantnuc_compute_theranostic_dose — MIRD-23/26 PVE-propagated multi-timepoint tumor absorbed dose (Gy).

  • quantnuc_audit_3d_ct_ac_volume — 3D bilinear HU-to-$\mu(E)$ volumetric CT-AC respiratory bias audit.

  • quantnuc_generate_physics_dossier — Autonomous Forensics Physicist + Critic-Verifier Audit dossier.

CLI Subcommands (uv run quantnuc ...):

uv run quantnuc harmonize --pet-standard EARL2 --noise-constrained
uv run quantnuc pvc --diameter 12 --observed-suv 5.1 --background-suv 2.0
uv run quantnuc audit-ac --shift-mm 10.0 --energy-kev 511.0
uv run quantnuc dose --diameter 14 --isotope Lu-177
uv run quantnuc dossier --output-dir outputs/dossier

Documentation & Provenance

Available Tools

9 tools
quantnuc_audit_3d_ct_ac_volumeC

Compute 3D bilinear HU-to-mu(E) ray-traced CT-AC respiratory mismatch bias across a lung-liver dome volume.

Inputs: breathing_shift_mm (required), raise_on_severe, photon_energy_kev.

quantnuc_audit_ct_ac_mismatchC

Compute exact CT-PET/SPECT respiratory attenuation-correction line-integral bias exp(int delta_mu ds) and abstention status.

Inputs: breathing_shift_mm (required), raise_on_severe, photon_energy_kev.

quantnuc_compute_theranostic_doseC

Propagate Rousset GTM partial-volume recovery into MIRD-23/26 multi-timepoint tumor absorbed dose (Gy) with 90% uncertainty interval.

Inputs: recon (required), scanner (required), timepoints (required), lesion_diameter_mm (required), +2 more.

quantnuc_diagnose_suv_shiftC

Decompose a longitudinal delta-SUV shift into PSF-Gibbs, PVE resolution, CT-AC respiratory artifact, and true biological change.

Inputs: baseline_recon (required), followup_recon (required), baseline_lesion (required), followup_lesion (required), +3 more.

quantnuc_forward_nema_rcC

Simulate 3D NEMA NU 2-2018 6-sphere Recovery Coefficients (RCmean, RCmax, RCpeak) including PSF-Gibbs ringing.

Inputs: recon (required), scanner (required), sphere_to_bg_ratio.

quantnuc_generate_physics_dossierC

Run the end-to-end Frontier Agent Forensics Physicist (4-scanner EARL2/MIRD-23 harmonization, longitudinal attribution, Critic-Verifier Audit).

Inputs: title.

quantnuc_invert_pve_activityC

Invert true lesion activity from observed SUV using Rousset GTM, Muller-Gartner, or Bayesian PVC with p05/nominal/p95 CI.

Inputs: recon (required), lesion (required), scanner (required), method.

quantnuc_run_sobol_sensitivityC

Run Saltelli-Jansen QMC global Sobol' sensitivity analysis (S1, ST, interactions) on quantitative SUV variance.

Inputs: lesion_diameter_mm (required), true_suv, background_suv, n_base_samples.

quantnuc_synthesize_earl_filterC

Synthesize minimal post-reconstruction Gaussian/Butterworth harmonization filter for EARL1, EARL2, QIBA, or MIRD23_SPECT.

Inputs: recon (required), scanner (required), filter_type, standard_name, +1 more.

Tool Schema Changelog

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

Loading tool schema changelog…

    TDQS

    B3/5.0

    Scored across 9 tools

    Disambiguation4/5

    Each tool maps to a distinct computational step (forward RC simulation, inverse PVC, filter synthesis, CT-AC bias, SUV decomposition, Sobol, dosimetry, dossier), but `quantnuc_audit_ct_ac_mismatch` and `quantnuc_audit_3d_ct_ac_volume` are close cousins distinguished only by 'line-integral' vs '3D ray-traced volume', and the end-to-end dossier overlaps conceptually with chaining the individual tools. Descriptions do resolve the ambiguity for a careful agent.

    Naming Consistency4/5

    All tools share a `quantnuc_` prefix plus snake_case verb_noun structure (invert_pve_activity, synthesize_earl_filter, compute_theranostic_dose), which is predictable. Minor deviations: `quantnuc_forward_nema_rc` uses 'forward' as a verb and several names are heavy abbreviation strings (nema_rc, ct_ac, suv_shift) that read more like jargon than a clean pattern.

    Tool Count5/5

    Nine tools is well within the sweet spot and each corresponds to a real, non-redundant step in the quantitative nuclear-medicine workflow. The dossier tool acts as an orchestrator rather than an inflated duplicate, so nothing feels padded.

    Completeness4/5

    The surface covers the domain lifecycle end to end: forward simulation, inversion/PVC, harmonization filter synthesis, CT-AC auditing (2D and 3D), longitudinal attribution, global sensitivity, and dosimetry with uncertainty plus a final dossier. Gaps are minor—no way to enumerate/validate supported scanners, phantoms, or reconstruction protocols, and no plotting/export of intermediate results for inspection.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      B
      maintenance
      Enables MCP hosts to run provenance-aware computational epitope research workflows, including sequence and immune-evidence analysis, structure and chemistry calculations, molecular docking, and checksummed 3D artifact exports.
      46
      MIT
    • A
      license
      Not graded
      quality
      Not graded
      maintenance
      Enables agents to deterministically calculate Pelli-Robson log contrast sensitivity scores, Weber contrast thresholds, visual functional acuity, and photopic glare recovery metrics through JSON-RPC tooling.
      MIT
    • A
      license
      Not graded
      quality
      Not graded
      maintenance
      Enables agents to compute single-breath nitrogen washout closing volume, closing capacity, age-predicted reference intervals, and peripheral small airway patency through deterministic JSON-RPC tools.
      MIT