feat: JuliaMSI MCP server v0.1.0 — 20 tools ready for testing
CI / test (push) Has been cancelled

Implements the Model Context Protocol server for the JuliaMSI mass
spectrometry imaging engine, covering phases 1–3 of the implementation
plan plus the main phase-4 items.

Tools (20):
  session/dataset:   msi_open_dataset, msi_close_dataset, msi_dataset_info,
                     msi_get_dataset_stats
  spectra:           msi_get_spectrum_at_coord, msi_get_spectrum_by_index
  ion images:        msi_get_mz_slice, msi_get_multiple_mz_slices,
                     msi_plan_ion_image, msi_plan_multiple_slices
  preprocessing:     msi_plan_preprocessing, msi_plan_streaming_pipeline,
                     msi_plan_analytics
  execution:         msi_execute_runspec, msi_list_plans,
                     msi_get_task_status, msi_get_task_result,
                     msi_cancel_task, msi_list_tasks
  maintenance:       msi_clean_artifacts

Resources (msi://): dataset/metadata, dataset/stats,
  tasks/{task_id}/status, tasks/{task_id}/result
Prompts: analyze_region_of_interest, standard_pipeline, diagnose_task

- Persistent session: one MSIData kept alive between tool calls
- Plan -> execute -> poll async core (SHA-256 RunSpecs + background tasks)
- Results as on-disk artifacts (CSV/PGM/MatrixMarket) with compact previews
- Structured JSON-RPC error mapping with suggested actions
- stdio and Streamable HTTP transports, optional shared-token auth
- Artifact retention (age + size budgets) and glibc malloc_trim cleanup
- 107 tests + end-to-end stdio smoke test; validated on HR2MSI bladder
  (imzML) and T9_A1/Col_1 (mzML)

Required JuliaMSI engine fixes are tracked in patches/ (already upstream
on the rel/Windows_Mac_Recompatibility branch and GitHub main).
This commit is contained in:
Pixelguy14
2026-11-25 13:25:13 -06:00
commit c3d5daeec5
35 changed files with 7927 additions and 0 deletions
+52
View File
@@ -0,0 +1,52 @@
#!/usr/bin/env julia
# ---------------------------------------------------------------------------
# Build a custom system image (AOT) for the JuliaMSI MCP server.
#
# This bakes JuliaMSI_MCP + MSI_src (and their reachable code) into a native
# shared object so the server starts without the first-call JIT latency.
#
# julia scripts/build_sysimage.jl
#
# Environment:
# JULIA_MSI_PATH Path to the JuliaMSI engine checkout (default ../JuliaMSI)
# JULIA_MSI_MCP_SYSIMAGE Output path (default build/sys_mcp.so)
#
# Run the server with the image afterwards:
# julia --project=. --threads=auto --sysimage=build/sys_mcp.so bin/run_server.jl
# ---------------------------------------------------------------------------
using Pkg
const MCP_DIR = normpath(joinpath(@__DIR__, ".."))
const ENGINE = get(ENV, "JULIA_MSI_PATH", normpath(joinpath(MCP_DIR, "..", "JuliaMSI")))
const EXT = Sys.iswindows() ? ".dll" : Sys.isapple() ? ".dylib" : ".so"
const OUT = get(ENV, "JULIA_MSI_MCP_SYSIMAGE", joinpath(MCP_DIR, "build", "sys_mcp" * EXT))
isfile(joinpath(ENGINE, "Project.toml")) ||
error("JuliaMSI engine not found at $(ENGINE). Set JULIA_MSI_PATH to the checkout.")
println("--- JuliaMSI_MCP system image build ---")
println("engine : ", ENGINE)
println("output : ", OUT)
mkpath(dirname(OUT))
# Use a throwaway environment so the runtime project stays lean. The engine is
# developed first so its package name/uuid (MSI_src) resolves for JuliaMSI_MCP.
Pkg.activate(; temp=true)
Pkg.develop(PackageSpec(path=ENGINE))
Pkg.develop(PackageSpec(path=MCP_DIR))
Pkg.add("PackageCompiler")
using PackageCompiler
create_sysimage(
[:JuliaMSI_MCP],
sysimage_path = OUT,
precompile_execution_file = joinpath(@__DIR__, "sysimage_warmup.jl"),
incremental = true,
)
println("--- System image written to: ", OUT, " ---")
println("Run the server with:")
println(" julia --project=$(MCP_DIR) --threads=auto --sysimage=$(OUT) $(joinpath(MCP_DIR, "bin", "run_server.jl"))")
+26
View File
@@ -0,0 +1,26 @@
#!/usr/bin/env julia
# ---------------------------------------------------------------------------
# One-time setup: point Pkg at the local JuliaMSI engine and instantiate.
#
# JULIA_MSI_PATH=/path/to/JuliaMSI julia scripts/setup.jl
#
# By default the sibling `../JuliaMSI` directory (relative to this project) is
# used, matching the default layout of the development workspace.
# ---------------------------------------------------------------------------
using Pkg
project_dir = dirname(@__DIR__)
default_engine = normpath(joinpath(project_dir, "..", "JuliaMSI"))
engine = get(ENV, "JULIA_MSI_PATH", default_engine)
if !isfile(joinpath(engine, "Project.toml"))
error("JuliaMSI engine not found at $(engine). Set JULIA_MSI_PATH to the JuliaMSI checkout.")
end
println("Using JuliaMSI engine at: $(abspath(engine))")
Pkg.develop(PackageSpec(path=abspath(engine)))
Pkg.instantiate()
Pkg.precompile()
println("Setup complete. Start the server with:")
println(" julia --project=$(project_dir) --threads=auto $(joinpath(project_dir, "bin", "run_server.jl"))")
+58
View File
@@ -0,0 +1,58 @@
# scripts/sysimage_warmup.jl
# ---------------------------------------------------------------------------
# Precompile warm-up workload for the JuliaMSI MCP server sysimage.
#
# This file is executed by PackageCompiler (scripts/build_sysimage.jl) inside a
# subprocess that already has `JuliaMSI_MCP` baked in. It exercises every
# engine/MCP code path the server uses, so the resulting system image contains
# native code for them instead of paying JIT on first use.
# ---------------------------------------------------------------------------
using JuliaMSI_MCP
const J = JuliaMSI_MCP
tmp = mktempdir()
ENV["JULIA_MSI_MCP_ARTIFACTS"] = joinpath(tmp, "artifacts")
include(joinpath(@__DIR__, "..", "test", "synthetic.jl"))
imzml_path = write_synthetic_imzml(tmp; width=3, height=3)
# Persistent session + metadata.
J.open_dataset(imzml_path; precompute_analytics=true)
# Random-access spectrum query.
mz, intensity = J.MSI_src.GetSpectrum(J.require_data(), 1)
# Ion image (sync execution path).
J._run_ion_image(
J._sync_runspec(:ion_image, Dict(
"mass" => 300.0, "tolerance" => 0.5, "mask_path" => nothing,
"include_matrix" => true, "preview_max_dim" => 32, "output_name" => "warm")),
J._sync_task(:ion_image), J.require_data())
# Multiple slices (hierarchy inversion).
J._run_multiple_slices(
J._sync_runspec(:multiple_slices, Dict(
"masses" => [100.0, 300.0, 500.0], "tolerance" => 0.5, "mask_path" => nothing,
"include_matrix" => false, "preview_max_dim" => 32, "output_name" => "warm")),
J._sync_task(:multiple_slices), J.require_data())
# Streaming preprocessing (Sprint 2).
J._run_streaming_pipeline(
J._sync_runspec(:streaming_pipeline, Dict(
"steps" => [
Dict("name" => "smoothing", "params" => Dict("method" => "savitzky_golay", "window" => 5, "order" => 2)),
Dict("name" => "normalization", "params" => Dict("method" => "tic")),
Dict("name" => "peak_picking", "params" => Dict("method" => "profile", "snr_threshold" => 3.0)),
],
"num_bins" => 50, "min_peaks_per_bin" => 1, "frequency_threshold" => 0.0,
"reference_peaks" => Float64[], "mask_path" => nothing,
"include_matrix" => false, "output_name" => "warm")),
J._sync_task(:streaming_pipeline), J.require_data())
J.close_dataset()
# Register tools/resources/prompts so the schema builders are compiled too.
J.build_server()
println("sysimage warmup complete")