labmcp-thermo-iapi 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ .venv/
4
+ .pytest_cache/
5
+ .ruff_cache/
6
+ dist/
7
+ build/
8
+ *.egg-info/
9
+ .DS_Store
10
+ *.jsonl
11
+ !**/fixtures/*.jsonl
12
+ .idea/
13
+ .vscode/
14
+
15
+ CLAUDE.md
@@ -0,0 +1,145 @@
1
+ Metadata-Version: 2.5
2
+ Name: labmcp-thermo-iapi
3
+ Version: 0.1.0
4
+ Summary: MCP server adapter for Thermo Fisher Orbitrap mass spectrometers via the licensed Instrument API (IAPI): status, live scans, custom and repeating scans, acquisitions.
5
+ Project-URL: Homepage, https://github.com/K-Dense-AI/lab-instrument-mcps/tree/main/servers/chemistry/thermo-iapi
6
+ Author: K-Dense and LabMCP contributors
7
+ License-Expression: Apache-2.0
8
+ Keywords: iapi,lab-instrument,mass-spectrometry,mcp,orbitrap,proteomics,thermo-fisher
9
+ Requires-Python: >=3.10
10
+ Requires-Dist: labmcp<0.2,>=0.1.2
11
+ Provides-Extra: windows
12
+ Requires-Dist: pythonnet>=3.0.3; (sys_platform == 'win32') and extra == 'windows'
13
+ Description-Content-Type: text/markdown
14
+
15
+ # Thermo Orbitrap (Instrument API): MCP Server
16
+
17
+ <!-- mcp-name: io.github.K-Dense-AI/labmcp-thermo-iapi -->
18
+
19
+ Let an AI agent watch and steer a **Thermo Fisher Orbitrap mass spectrometer** in real time: check the instrument mode and vacuum, read the scans streaming off the instrument (filtered by MS order, with the most intense centroids), place validated custom scans and pick up their results, set a repeating scan, and start, pause or stop acquisitions to a raw file. It does this through Thermo's own **Instrument API (IAPI)**.
20
+
21
+ > [!IMPORTANT]
22
+ > **This is an adapter. It contains no Thermo software.** The IAPI is a Windows .NET API. To use it you need a **signed IAPI software licence agreement with Thermo Fisher Scientific**, with the licence applied to your instrument ([legal requirements](https://github.com/thermofisherlsms/iapi/blob/master/GettingStarted.md#legal-requirements), [licence FAQ](https://github.com/thermofisherlsms/iapi/blob/master/docs/API%20license%20agreement%20FAQs%20r1.3.pdf), [how to obtain a licence](https://github.com/thermofisherlsms/iapi/blob/master/docs/Orbitrap_IAPI_Online_licensing_guidance_material.pdf)). This package **never bundles or downloads** the IAPI assemblies: you point it at the ones you obtained. **It has never been tested on real hardware.** Everything below was developed against the official IAPI interface definitions and examples and a simulator.
23
+
24
+ | | |
25
+ |---|---|
26
+ | **Package** | `labmcp-thermo-iapi` (install the `[windows]` extra on the instrument PC for pythonnet) |
27
+ | **Instruments** | Orbitrap Tribrid (Fusion, Fusion Lumos, Eclipse, Ascend), Orbitrap Exploris 240/480, Q Exactive family. Not the Orbitrap Astral: Thermo states the Astral line does not support IAPI (as of fall 2025). Not the Exploris 120, which Thermo's examples say doesn't support the API. |
28
+ | **Interfaces** | .NET API on the Windows instrument PC (through [pythonnet](https://pythonnet.github.io/)) |
29
+ | **Protocol** | [Thermo Fisher Instrument API (IAPI)](https://github.com/thermofisherlsms/iapi): interface definitions in `lib/*.xml`, examples in `examples/` |
30
+ | **Status** | ๐Ÿงช **simulated**: tested against a simulated Orbitrap (FakeOrbitrap), not yet verified on hardware. [Report a hardware test](https://github.com/K-Dense-AI/lab-instrument-mcps/issues/new?template=hardware-verification.yml) |
31
+
32
+ ## Try it without hardware
33
+
34
+ ```bash
35
+ uvx labmcp-thermo-iapi --simulate --check
36
+ ```
37
+
38
+ The simulator is an Orbitrap Exploris 480 by default (`--option sim_model=eclipse` or `qexactive-hf` for the others). It runs a synthetic tryptic digest: MS1 survey scans in On mode, a data-dependent top-10 method during an acquisition, custom and repeating scans that come back with their access id, realistic transient and injection times, and a status log with vacuum readings every ~5 s.
39
+
40
+ ## Connect your instrument
41
+
42
+ On the **Windows instrument PC**, with Tune installed and your IAPI licence applied:
43
+
44
+ 1. **Get the IAPI assemblies** that come with your licence (for a Tribrid: `API-2.0.dll`, `Spectrum-1.0.dll`, `Thermo.TNG.Factory.dll` and `Fusion.API-2.0.dll` for Tune 4.3 or `Fusion.API-1.0.dll` for Tune 4.2 and earlier). Put them in a folder, e.g. `C:\IAPI`.
45
+ 2. **Install** Python 3.10+ and the server with pythonnet:
46
+ ```powershell
47
+ pip install "labmcp-thermo-iapi[windows]"
48
+ ```
49
+ 3. **Test the connection** (the instrument family picks the connection recipe from the IAPI examples):
50
+ ```powershell
51
+ labmcp-thermo-iapi --option instrument=tribrid --option assembly_dir=C:\IAPI --check # Fusion/Lumos/Eclipse/Ascend
52
+ labmcp-thermo-iapi --option instrument=exploris --option assembly_dir=C:\IAPI --check # Exploris 240/480
53
+ labmcp-thermo-iapi --option instrument=exactive --option assembly_dir=C:\IAPI --check # Q Exactive family
54
+ ```
55
+
56
+ | Family | How the server connects (from the IAPI repository) | Assemblies expected in `assembly_dir` |
57
+ |---|---|---|
58
+ | `tribrid` | `Factory<IFusionInstrumentAccessContainer>.Create()`, `StartOnlineAccess()`, `Get(1)` | `API-2.0.dll`, `Spectrum-1.0.dll`, `Thermo.TNG.Factory.dll`, `Fusion.API-2.0.dll` or `Fusion.API-1.0.dll` |
59
+ | `exploris` | `HKLM\SOFTWARE\Thermo Exploris` โ†’ `DataSystem.xml` (`ApiFileName`, `ApiClassName`) | `Thermo.API.NetStd-1.0.dll`, `Thermo.API.Exploris.NetStd-1.0.dll`, `Thermo.API.Spectrum.NetStd-1.0.dll` (4.3+) or the `Thermo.API-2.0` / `Thermo.API.Exploris-1.0` / `Thermo.API.Spectrum-1.x` set |
60
+ | `exactive` | `HKLM\SOFTWARE\Finnigan\Xcalibur\Devices\Thermo Exactive` (`ApiFileName_Clr2_32_V1`, `ApiClassName_Clr2_32_V1`) | `API-2.0.dll` (or 1.x), `Spectrum-1.0.dll`, `ESAPI-1.1.dll` (or 1.0) |
61
+
62
+ The server gives a specific message if it is not running on Windows, pythonnet is missing, the folder or an assembly is missing, the IAPI service does not connect (Tune not running), or IAPI refuses a command for lack of a licence.
63
+
64
+ Other options: `readbacks=Name1;Name2` (instrument values to show in `get_instrument_status`; the tool lists the names your instrument exposes), `exclusive_scans=true` (exclusive rather than cooperative `IScans` access), `runtime=coreclr`, `connect_timeout_s`, `buffer_size` (scans kept in memory, default 500).
65
+
66
+ ## Add to your MCP client
67
+
68
+ ```bash
69
+ claude mcp add orbitrap -- labmcp-thermo-iapi --option instrument=tribrid --option assembly_dir=C:\IAPI
70
+ ```
71
+
72
+ ```json
73
+ {
74
+ "mcpServers": {
75
+ "orbitrap": {
76
+ "command": "labmcp-thermo-iapi",
77
+ "args": ["--option", "instrument=exploris", "--option", "assembly_dir=C:\\IAPI"]
78
+ }
79
+ }
80
+ }
81
+ ```
82
+
83
+ Add `--read-only` to let the agent watch scans and status but not place scans or start acquisitions. The stop and cancel tools stay available. To reach the server from another computer, run it with `--transport http --host 0.0.0.0 --port 8000` on the instrument PC and protect that port.
84
+
85
+ ## Tools
86
+
87
+ <!-- TOOLS:START -->
88
+ | Tool | Kind | Description |
89
+ |---|---|---|
90
+ | `cancel_custom_scans` | ๐Ÿ›‘ safety | Cancel any pending custom scan and its processing delay (IAPI CancelCustomScan). |
91
+ | `cancel_repeating_scan` | ๐Ÿ›‘ safety | Cancel the repeating scan set with set_repeating_scan (IAPI CancelRepetition). |
92
+ | `get_command_log` | ๐Ÿ‘ read | Return the most recent raw commands sent to / replies received from the instrument (newest last). Useful for debugging and for recording what was done. |
93
+ | `get_connection_info` | ๐Ÿ‘ read | Report which instrument is connected (identity, address, simulated or real), whether the server is read-only, and the active safety limits. Call this first. |
94
+ | `get_instrument_status` | ๐Ÿ‘ read | Report the instrument model, IAPI service/instrument connection, system mode and state (On/Standby/Off; Running/ReadyToDownload/...), whether an acquisition can be paused or resumed, the IAPI licence where the API exposes it, requested readbacks, the latest scan status log (vacuum, source) and how many scans have arrived. |
95
+ | `get_possible_scan_parameters` | ๐Ÿ‘ read | List the scan parameters this instrument accepts for custom and repeating scans (IScans.PossibleParameters): name, allowed range or choices, default and help. The set depends on the model, licence and Tune version. |
96
+ | `get_recent_scans` | ๐Ÿ‘ read | Return the most recent scans received from the instrument (oldest first), optionally only one MS order or one custom scan's access id: scan number, MS order, precursor m/z, AGC target, injection time and the most intense centroids. Scans only arrive in On mode. |
97
+ | `pause_acquisition` | ๐Ÿ›‘ safety | Pause the running acquisition (IAPI Pause). Fails if the instrument reports it cannot pause. |
98
+ | `reconnect` | ๐Ÿ›‘ safety | Close and re-open the connection to the instrument (e.g. after it was power cycled or a cable was re-plugged). |
99
+ | `resume_acquisition` | โš ๏ธ hazard | Resume a paused acquisition (IAPI Resume). Sample consumption continues. |
100
+ | `set_repeating_scan` | โš ๏ธ hazard | Define or replace the scan the instrument repeats when no method or custom scan is running (IAPI CreateRepeatingScan/SetRepetitionScan). Values are validated like submit_custom_scan. Cancel with cancel_repeating_scan. |
101
+ | `start_acquisition` | โš ๏ธ hazard | Start an acquisition with the instrument's current settings (IAPI StartAcquisition), recording to a raw file. This consumes sample. The instrument must be On; an acquisition must not already be running. Stop it with stop_acquisition. scan_count and until_stopped acquisitions are cancelled automatically after max_acquisition_duration_s. |
102
+ | `stop_acquisition` | ๐Ÿ›‘ safety | Stop the running acquisition (IAPI CancelAcquisition), by default also cancelling custom and repeating scans, and optionally switch the instrument to Standby (switch back to On in Tune). Every step is attempted even if an earlier one fails; failures are reported. |
103
+ | `submit_custom_scan` | โš ๏ธ hazard | Place one custom scan to run next (IAPI CreateCustomScan/SetCustomScan); unset values fall back to the instrument's defaults. Every value is checked against PossibleParameters and the safety limits, and calls are rate-limited, before anything is sent. Fetch the result with wait_for_scan(access_id=running_number). |
104
+ | `wait_for_scan` | ๐Ÿ‘ read | Wait for the next scan that arrives after this call (optionally of one MS order, or the result of a custom scan by its access id) and return it. For a custom scan placed with submit_custom_scan, a result that arrived since it was placed is returned at once. Returns found=false after timeout_s if nothing matching arrived (e.g. the instrument is in Standby). |
105
+ <!-- TOOLS:END -->
106
+
107
+ `get_connection_info`, `get_command_log` and `reconnect` are built into every LabMCP server. Every IAPI control call (with the exact scan values sent) is recorded in the command log.
108
+
109
+ ## Safety limits
110
+
111
+ | Limit | Default | Meaning |
112
+ |---|---|---|
113
+ | `max_custom_scans_per_minute` | 60 scans/min | Custom scans an agent may place in any 60 s window (server-side rate limit; `reconnect` does not reset it) |
114
+ | `max_injection_time_ms` | 1000 ms | Largest maximum injection time (`MaxIT`) in a custom or repeating scan (every element of a multi-valued `MaxIT`) |
115
+ | `max_acquisition_duration_s` | 7200 s | Longest acquisition an agent may start: a `duration` above it is refused, and `scan_count` / `until_stopped` acquisitions are cancelled automatically when it runs out (wall-clock, pauses included) |
116
+
117
+ Override at launch: `--limit max_custom_scans_per_minute=600`.
118
+
119
+ On top of these limits, every custom and repeating scan value is checked against the instrument's own `IScans.PossibleParameters` before anything is sent: the parameter name must exist, numbers must lie inside the instrument's range (for example the m/z range for `FirstMass`/`LastMass`), and choice parameters such as `OrbitrapResolution` must be one of the allowed values. IAPI itself silently ignores illegal values, which is why the server checks first, and why accepted values are sent in the instrument's own spelling (`hcd` goes out as `HCD`, `2.0` for an integer parameter as `2`).
120
+
121
+ `stop_acquisition` attempts every step (cancel the acquisition, the custom scans, the repeating scan, Standby) even if one fails, and reports what failed.
122
+
123
+ ## Example prompts
124
+
125
+ - "Is the Orbitrap in On mode and what are the vacuum readings? How many scans came in during the last minute?"
126
+ - "Show me the last 5 MS2 scans with their precursor m/z, injection times and top 10 fragments."
127
+ - "Place a 120k SIM scan on m/z 524.26 with a 10 m/z window and tell me the most intense peaks you see."
128
+ - "Start a 30-minute acquisition to D:\Data\HeLa_test.raw with sample name HeLa 200 ng, then check every few minutes that MS2 scans are still arriving."
129
+
130
+ ## Notes
131
+
132
+ - **Instrument mode:** scans only arrive in **On** mode, and custom scans and acquisitions need it too. `stop_acquisition(standby=true)` switches to Standby. This server has no tool to switch back to On (do that in Tune).
133
+ - **Custom scans:** values you leave out come from the instrument's defaults, as Thermo documents for `IScanDefinition.Values`. `running_number` comes back as the scan's `access_id` (trailer item `Access Id:`). The server numbers scans automatically if you don't. A custom scan usually finishes before the agent's next tool call, so `wait_for_scan(access_id=...)` also returns a result that arrived after the scan was placed but before the wait started. IAPI leaves the result undefined when several custom scans are placed before the instrument has processed the earlier ones; the rate limit keeps this under control.
134
+ - **Parameter names differ by model and Tune version** (e.g. `Analyzer` on Tribrids). Use `get_possible_scan_parameters` and pass anything that has no named argument through `extra_parameters`.
135
+ - **Scan headers:** `scan_number`, `ms_order`, `scan_mode` and `precursor_mz` come from header keys used in Thermo's examples (`Scan`, `MSOrder`, `ScanMode`, `PrecursorMass[0]`). `master_scan_number`, `agc_target` and `injection_time_ms` are read from the trailer names Thermo raw files use (`Master Scan Number:`, `AGC Target:`, `Ion Injection Time (ms):`). The IAPI repository doesn't document these, so they may be `null` on your instrument. Use `include_header_trailer=true` to see exactly what it sends.
136
+ - **Readbacks:** IAPI has no fixed list of readback names (vacuum gauges, voltages). `get_instrument_status` shows the names from `IInstrumentValues.ValueNames` and the latest scan `StatusLog`, where the vacuum readings usually appear.
137
+ - **Licence check:** on Exploris instruments the server reports whether an API licence is present (`IExplorisInstrumentAccess.Licenses`). Tribrid and Exactive instruments enforce the licence in the instrument service, and a refused command reports it.
138
+ - **Verified API surface:** every IAPI member the pythonnet backend touches is listed with its source file in [`iapi_members.py`](src/labmcp_thermo_iapi/iapi_members.py) (checked against [thermofisherlsms/iapi@c246dcc](https://github.com/thermofisherlsms/iapi/tree/c246dcc8772d03c9c32e9b2fde486e97572c8fbf)). A test fails if the backend uses a name that isn't in that list.
139
+ - **Scan data:** each scan's .NET object is copied and disposed at once, as Thermo's examples require (otherwise the instrument's shared memory stays blocked). Up to 5 000 centroids per scan are kept. `max_centroids` limits what a tool returns, and `get_recent_scans(save_path=...)` writes all kept centroids to a new CSV file (the path must end in `.csv` and must not exist yet: existing files are never overwritten).
140
+
141
+ ## Hardware verification
142
+
143
+ | Model | Firmware | Interface | Verified by | Date |
144
+ |---|---|---|---|---|
145
+ | *none yet: [be the first](https://github.com/K-Dense-AI/lab-instrument-mcps/issues/new?template=hardware-verification.yml)* | | | | |
@@ -0,0 +1,131 @@
1
+ # Thermo Orbitrap (Instrument API): MCP Server
2
+
3
+ <!-- mcp-name: io.github.K-Dense-AI/labmcp-thermo-iapi -->
4
+
5
+ Let an AI agent watch and steer a **Thermo Fisher Orbitrap mass spectrometer** in real time: check the instrument mode and vacuum, read the scans streaming off the instrument (filtered by MS order, with the most intense centroids), place validated custom scans and pick up their results, set a repeating scan, and start, pause or stop acquisitions to a raw file. It does this through Thermo's own **Instrument API (IAPI)**.
6
+
7
+ > [!IMPORTANT]
8
+ > **This is an adapter. It contains no Thermo software.** The IAPI is a Windows .NET API. To use it you need a **signed IAPI software licence agreement with Thermo Fisher Scientific**, with the licence applied to your instrument ([legal requirements](https://github.com/thermofisherlsms/iapi/blob/master/GettingStarted.md#legal-requirements), [licence FAQ](https://github.com/thermofisherlsms/iapi/blob/master/docs/API%20license%20agreement%20FAQs%20r1.3.pdf), [how to obtain a licence](https://github.com/thermofisherlsms/iapi/blob/master/docs/Orbitrap_IAPI_Online_licensing_guidance_material.pdf)). This package **never bundles or downloads** the IAPI assemblies: you point it at the ones you obtained. **It has never been tested on real hardware.** Everything below was developed against the official IAPI interface definitions and examples and a simulator.
9
+
10
+ | | |
11
+ |---|---|
12
+ | **Package** | `labmcp-thermo-iapi` (install the `[windows]` extra on the instrument PC for pythonnet) |
13
+ | **Instruments** | Orbitrap Tribrid (Fusion, Fusion Lumos, Eclipse, Ascend), Orbitrap Exploris 240/480, Q Exactive family. Not the Orbitrap Astral: Thermo states the Astral line does not support IAPI (as of fall 2025). Not the Exploris 120, which Thermo's examples say doesn't support the API. |
14
+ | **Interfaces** | .NET API on the Windows instrument PC (through [pythonnet](https://pythonnet.github.io/)) |
15
+ | **Protocol** | [Thermo Fisher Instrument API (IAPI)](https://github.com/thermofisherlsms/iapi): interface definitions in `lib/*.xml`, examples in `examples/` |
16
+ | **Status** | ๐Ÿงช **simulated**: tested against a simulated Orbitrap (FakeOrbitrap), not yet verified on hardware. [Report a hardware test](https://github.com/K-Dense-AI/lab-instrument-mcps/issues/new?template=hardware-verification.yml) |
17
+
18
+ ## Try it without hardware
19
+
20
+ ```bash
21
+ uvx labmcp-thermo-iapi --simulate --check
22
+ ```
23
+
24
+ The simulator is an Orbitrap Exploris 480 by default (`--option sim_model=eclipse` or `qexactive-hf` for the others). It runs a synthetic tryptic digest: MS1 survey scans in On mode, a data-dependent top-10 method during an acquisition, custom and repeating scans that come back with their access id, realistic transient and injection times, and a status log with vacuum readings every ~5 s.
25
+
26
+ ## Connect your instrument
27
+
28
+ On the **Windows instrument PC**, with Tune installed and your IAPI licence applied:
29
+
30
+ 1. **Get the IAPI assemblies** that come with your licence (for a Tribrid: `API-2.0.dll`, `Spectrum-1.0.dll`, `Thermo.TNG.Factory.dll` and `Fusion.API-2.0.dll` for Tune 4.3 or `Fusion.API-1.0.dll` for Tune 4.2 and earlier). Put them in a folder, e.g. `C:\IAPI`.
31
+ 2. **Install** Python 3.10+ and the server with pythonnet:
32
+ ```powershell
33
+ pip install "labmcp-thermo-iapi[windows]"
34
+ ```
35
+ 3. **Test the connection** (the instrument family picks the connection recipe from the IAPI examples):
36
+ ```powershell
37
+ labmcp-thermo-iapi --option instrument=tribrid --option assembly_dir=C:\IAPI --check # Fusion/Lumos/Eclipse/Ascend
38
+ labmcp-thermo-iapi --option instrument=exploris --option assembly_dir=C:\IAPI --check # Exploris 240/480
39
+ labmcp-thermo-iapi --option instrument=exactive --option assembly_dir=C:\IAPI --check # Q Exactive family
40
+ ```
41
+
42
+ | Family | How the server connects (from the IAPI repository) | Assemblies expected in `assembly_dir` |
43
+ |---|---|---|
44
+ | `tribrid` | `Factory<IFusionInstrumentAccessContainer>.Create()`, `StartOnlineAccess()`, `Get(1)` | `API-2.0.dll`, `Spectrum-1.0.dll`, `Thermo.TNG.Factory.dll`, `Fusion.API-2.0.dll` or `Fusion.API-1.0.dll` |
45
+ | `exploris` | `HKLM\SOFTWARE\Thermo Exploris` โ†’ `DataSystem.xml` (`ApiFileName`, `ApiClassName`) | `Thermo.API.NetStd-1.0.dll`, `Thermo.API.Exploris.NetStd-1.0.dll`, `Thermo.API.Spectrum.NetStd-1.0.dll` (4.3+) or the `Thermo.API-2.0` / `Thermo.API.Exploris-1.0` / `Thermo.API.Spectrum-1.x` set |
46
+ | `exactive` | `HKLM\SOFTWARE\Finnigan\Xcalibur\Devices\Thermo Exactive` (`ApiFileName_Clr2_32_V1`, `ApiClassName_Clr2_32_V1`) | `API-2.0.dll` (or 1.x), `Spectrum-1.0.dll`, `ESAPI-1.1.dll` (or 1.0) |
47
+
48
+ The server gives a specific message if it is not running on Windows, pythonnet is missing, the folder or an assembly is missing, the IAPI service does not connect (Tune not running), or IAPI refuses a command for lack of a licence.
49
+
50
+ Other options: `readbacks=Name1;Name2` (instrument values to show in `get_instrument_status`; the tool lists the names your instrument exposes), `exclusive_scans=true` (exclusive rather than cooperative `IScans` access), `runtime=coreclr`, `connect_timeout_s`, `buffer_size` (scans kept in memory, default 500).
51
+
52
+ ## Add to your MCP client
53
+
54
+ ```bash
55
+ claude mcp add orbitrap -- labmcp-thermo-iapi --option instrument=tribrid --option assembly_dir=C:\IAPI
56
+ ```
57
+
58
+ ```json
59
+ {
60
+ "mcpServers": {
61
+ "orbitrap": {
62
+ "command": "labmcp-thermo-iapi",
63
+ "args": ["--option", "instrument=exploris", "--option", "assembly_dir=C:\\IAPI"]
64
+ }
65
+ }
66
+ }
67
+ ```
68
+
69
+ Add `--read-only` to let the agent watch scans and status but not place scans or start acquisitions. The stop and cancel tools stay available. To reach the server from another computer, run it with `--transport http --host 0.0.0.0 --port 8000` on the instrument PC and protect that port.
70
+
71
+ ## Tools
72
+
73
+ <!-- TOOLS:START -->
74
+ | Tool | Kind | Description |
75
+ |---|---|---|
76
+ | `cancel_custom_scans` | ๐Ÿ›‘ safety | Cancel any pending custom scan and its processing delay (IAPI CancelCustomScan). |
77
+ | `cancel_repeating_scan` | ๐Ÿ›‘ safety | Cancel the repeating scan set with set_repeating_scan (IAPI CancelRepetition). |
78
+ | `get_command_log` | ๐Ÿ‘ read | Return the most recent raw commands sent to / replies received from the instrument (newest last). Useful for debugging and for recording what was done. |
79
+ | `get_connection_info` | ๐Ÿ‘ read | Report which instrument is connected (identity, address, simulated or real), whether the server is read-only, and the active safety limits. Call this first. |
80
+ | `get_instrument_status` | ๐Ÿ‘ read | Report the instrument model, IAPI service/instrument connection, system mode and state (On/Standby/Off; Running/ReadyToDownload/...), whether an acquisition can be paused or resumed, the IAPI licence where the API exposes it, requested readbacks, the latest scan status log (vacuum, source) and how many scans have arrived. |
81
+ | `get_possible_scan_parameters` | ๐Ÿ‘ read | List the scan parameters this instrument accepts for custom and repeating scans (IScans.PossibleParameters): name, allowed range or choices, default and help. The set depends on the model, licence and Tune version. |
82
+ | `get_recent_scans` | ๐Ÿ‘ read | Return the most recent scans received from the instrument (oldest first), optionally only one MS order or one custom scan's access id: scan number, MS order, precursor m/z, AGC target, injection time and the most intense centroids. Scans only arrive in On mode. |
83
+ | `pause_acquisition` | ๐Ÿ›‘ safety | Pause the running acquisition (IAPI Pause). Fails if the instrument reports it cannot pause. |
84
+ | `reconnect` | ๐Ÿ›‘ safety | Close and re-open the connection to the instrument (e.g. after it was power cycled or a cable was re-plugged). |
85
+ | `resume_acquisition` | โš ๏ธ hazard | Resume a paused acquisition (IAPI Resume). Sample consumption continues. |
86
+ | `set_repeating_scan` | โš ๏ธ hazard | Define or replace the scan the instrument repeats when no method or custom scan is running (IAPI CreateRepeatingScan/SetRepetitionScan). Values are validated like submit_custom_scan. Cancel with cancel_repeating_scan. |
87
+ | `start_acquisition` | โš ๏ธ hazard | Start an acquisition with the instrument's current settings (IAPI StartAcquisition), recording to a raw file. This consumes sample. The instrument must be On; an acquisition must not already be running. Stop it with stop_acquisition. scan_count and until_stopped acquisitions are cancelled automatically after max_acquisition_duration_s. |
88
+ | `stop_acquisition` | ๐Ÿ›‘ safety | Stop the running acquisition (IAPI CancelAcquisition), by default also cancelling custom and repeating scans, and optionally switch the instrument to Standby (switch back to On in Tune). Every step is attempted even if an earlier one fails; failures are reported. |
89
+ | `submit_custom_scan` | โš ๏ธ hazard | Place one custom scan to run next (IAPI CreateCustomScan/SetCustomScan); unset values fall back to the instrument's defaults. Every value is checked against PossibleParameters and the safety limits, and calls are rate-limited, before anything is sent. Fetch the result with wait_for_scan(access_id=running_number). |
90
+ | `wait_for_scan` | ๐Ÿ‘ read | Wait for the next scan that arrives after this call (optionally of one MS order, or the result of a custom scan by its access id) and return it. For a custom scan placed with submit_custom_scan, a result that arrived since it was placed is returned at once. Returns found=false after timeout_s if nothing matching arrived (e.g. the instrument is in Standby). |
91
+ <!-- TOOLS:END -->
92
+
93
+ `get_connection_info`, `get_command_log` and `reconnect` are built into every LabMCP server. Every IAPI control call (with the exact scan values sent) is recorded in the command log.
94
+
95
+ ## Safety limits
96
+
97
+ | Limit | Default | Meaning |
98
+ |---|---|---|
99
+ | `max_custom_scans_per_minute` | 60 scans/min | Custom scans an agent may place in any 60 s window (server-side rate limit; `reconnect` does not reset it) |
100
+ | `max_injection_time_ms` | 1000 ms | Largest maximum injection time (`MaxIT`) in a custom or repeating scan (every element of a multi-valued `MaxIT`) |
101
+ | `max_acquisition_duration_s` | 7200 s | Longest acquisition an agent may start: a `duration` above it is refused, and `scan_count` / `until_stopped` acquisitions are cancelled automatically when it runs out (wall-clock, pauses included) |
102
+
103
+ Override at launch: `--limit max_custom_scans_per_minute=600`.
104
+
105
+ On top of these limits, every custom and repeating scan value is checked against the instrument's own `IScans.PossibleParameters` before anything is sent: the parameter name must exist, numbers must lie inside the instrument's range (for example the m/z range for `FirstMass`/`LastMass`), and choice parameters such as `OrbitrapResolution` must be one of the allowed values. IAPI itself silently ignores illegal values, which is why the server checks first, and why accepted values are sent in the instrument's own spelling (`hcd` goes out as `HCD`, `2.0` for an integer parameter as `2`).
106
+
107
+ `stop_acquisition` attempts every step (cancel the acquisition, the custom scans, the repeating scan, Standby) even if one fails, and reports what failed.
108
+
109
+ ## Example prompts
110
+
111
+ - "Is the Orbitrap in On mode and what are the vacuum readings? How many scans came in during the last minute?"
112
+ - "Show me the last 5 MS2 scans with their precursor m/z, injection times and top 10 fragments."
113
+ - "Place a 120k SIM scan on m/z 524.26 with a 10 m/z window and tell me the most intense peaks you see."
114
+ - "Start a 30-minute acquisition to D:\Data\HeLa_test.raw with sample name HeLa 200 ng, then check every few minutes that MS2 scans are still arriving."
115
+
116
+ ## Notes
117
+
118
+ - **Instrument mode:** scans only arrive in **On** mode, and custom scans and acquisitions need it too. `stop_acquisition(standby=true)` switches to Standby. This server has no tool to switch back to On (do that in Tune).
119
+ - **Custom scans:** values you leave out come from the instrument's defaults, as Thermo documents for `IScanDefinition.Values`. `running_number` comes back as the scan's `access_id` (trailer item `Access Id:`). The server numbers scans automatically if you don't. A custom scan usually finishes before the agent's next tool call, so `wait_for_scan(access_id=...)` also returns a result that arrived after the scan was placed but before the wait started. IAPI leaves the result undefined when several custom scans are placed before the instrument has processed the earlier ones; the rate limit keeps this under control.
120
+ - **Parameter names differ by model and Tune version** (e.g. `Analyzer` on Tribrids). Use `get_possible_scan_parameters` and pass anything that has no named argument through `extra_parameters`.
121
+ - **Scan headers:** `scan_number`, `ms_order`, `scan_mode` and `precursor_mz` come from header keys used in Thermo's examples (`Scan`, `MSOrder`, `ScanMode`, `PrecursorMass[0]`). `master_scan_number`, `agc_target` and `injection_time_ms` are read from the trailer names Thermo raw files use (`Master Scan Number:`, `AGC Target:`, `Ion Injection Time (ms):`). The IAPI repository doesn't document these, so they may be `null` on your instrument. Use `include_header_trailer=true` to see exactly what it sends.
122
+ - **Readbacks:** IAPI has no fixed list of readback names (vacuum gauges, voltages). `get_instrument_status` shows the names from `IInstrumentValues.ValueNames` and the latest scan `StatusLog`, where the vacuum readings usually appear.
123
+ - **Licence check:** on Exploris instruments the server reports whether an API licence is present (`IExplorisInstrumentAccess.Licenses`). Tribrid and Exactive instruments enforce the licence in the instrument service, and a refused command reports it.
124
+ - **Verified API surface:** every IAPI member the pythonnet backend touches is listed with its source file in [`iapi_members.py`](src/labmcp_thermo_iapi/iapi_members.py) (checked against [thermofisherlsms/iapi@c246dcc](https://github.com/thermofisherlsms/iapi/tree/c246dcc8772d03c9c32e9b2fde486e97572c8fbf)). A test fails if the backend uses a name that isn't in that list.
125
+ - **Scan data:** each scan's .NET object is copied and disposed at once, as Thermo's examples require (otherwise the instrument's shared memory stays blocked). Up to 5 000 centroids per scan are kept. `max_centroids` limits what a tool returns, and `get_recent_scans(save_path=...)` writes all kept centroids to a new CSV file (the path must end in `.csv` and must not exist yet: existing files are never overwritten).
126
+
127
+ ## Hardware verification
128
+
129
+ | Model | Firmware | Interface | Verified by | Date |
130
+ |---|---|---|---|---|
131
+ | *none yet: [be the first](https://github.com/K-Dense-AI/lab-instrument-mcps/issues/new?template=hardware-verification.yml)* | | | | |
@@ -0,0 +1,39 @@
1
+ [project]
2
+ name = "labmcp-thermo-iapi"
3
+ version = "0.1.0"
4
+ description = "MCP server adapter for Thermo Fisher Orbitrap mass spectrometers via the licensed Instrument API (IAPI): status, live scans, custom and repeating scans, acquisitions."
5
+ readme = "README.md"
6
+ license = "Apache-2.0"
7
+ requires-python = ">=3.10"
8
+ authors = [{ name = "K-Dense and LabMCP contributors" }]
9
+ keywords = ["mcp", "lab-instrument", "mass-spectrometry", "orbitrap", "thermo-fisher", "iapi", "proteomics"]
10
+ dependencies = ["labmcp>=0.1.2,<0.2"]
11
+
12
+ [project.optional-dependencies]
13
+ # The IAPI is a Windows .NET API; the IAPI assemblies themselves are licensed by Thermo Fisher
14
+ # and are NOT a dependency: users supply them with --option assembly_dir=...
15
+ windows = ["pythonnet>=3.0.3; sys_platform == 'win32'"]
16
+
17
+ [project.scripts]
18
+ labmcp-thermo-iapi = "labmcp_thermo_iapi.server:main"
19
+
20
+ [project.urls]
21
+ Homepage = "https://github.com/K-Dense-AI/lab-instrument-mcps/tree/main/servers/chemistry/thermo-iapi"
22
+
23
+ [tool.labmcp]
24
+ name = "Thermo Orbitrap (Instrument API)"
25
+ domain = "chemistry"
26
+ category = "Mass spectrometry"
27
+ vendor = "Thermo Fisher Scientific"
28
+ models = ["Orbitrap Fusion", "Orbitrap Fusion Lumos", "Orbitrap Eclipse", "Orbitrap Ascend", "Orbitrap Exploris 240", "Orbitrap Exploris 480", "Q Exactive family"]
29
+ interfaces = [".NET API (Windows)"]
30
+ protocol = "Thermo Fisher Instrument API (IAPI)"
31
+ summary = "Adapter for the licensed Thermo IAPI (bring your own assemblies): instrument status, live scan buffer with MS-order filters, validated and rate-limited custom and repeating scans, acquisitions to raw files, stop/cancel."
32
+ status = "simulated"
33
+
34
+ [build-system]
35
+ requires = ["hatchling"]
36
+ build-backend = "hatchling.build"
37
+
38
+ [tool.hatch.build.targets.wheel]
39
+ packages = ["src/labmcp_thermo_iapi"]
@@ -0,0 +1,46 @@
1
+ {
2
+ "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
3
+ "name": "io.github.K-Dense-AI/labmcp-thermo-iapi",
4
+ "title": "Thermo Orbitrap (Instrument API)",
5
+ "description": "MCP server adapter for Thermo Fisher Orbitrap mass spectrometers via the licensed Instrument API (IA",
6
+ "version": "0.1.0",
7
+ "repository": {
8
+ "url": "https://github.com/K-Dense-AI/lab-instrument-mcps",
9
+ "source": "github",
10
+ "subfolder": "servers/chemistry/thermo-iapi"
11
+ },
12
+ "websiteUrl": "https://github.com/K-Dense-AI/lab-instrument-mcps/tree/main/servers/chemistry/thermo-iapi",
13
+ "packages": [
14
+ {
15
+ "registryType": "pypi",
16
+ "registryBaseUrl": "https://pypi.org",
17
+ "identifier": "labmcp-thermo-iapi",
18
+ "version": "0.1.0",
19
+ "transport": {
20
+ "type": "stdio"
21
+ },
22
+ "environmentVariables": [
23
+ {
24
+ "name": "LABMCP_ADDRESS",
25
+ "description": "Instrument address, e.g. serial:///dev/ttyUSB0 or tcp://192.168.1.50:5025",
26
+ "isRequired": false
27
+ },
28
+ {
29
+ "name": "LABMCP_SIMULATE",
30
+ "description": "Set to 1 to use the built-in simulator (no hardware)",
31
+ "isRequired": false
32
+ },
33
+ {
34
+ "name": "LABMCP_READ_ONLY",
35
+ "description": "Set to 1 to disable all state-changing tools",
36
+ "isRequired": false
37
+ },
38
+ {
39
+ "name": "LABMCP_LIMITS",
40
+ "description": "Safety limit overrides, e.g. max_temperature_c=80",
41
+ "isRequired": false
42
+ }
43
+ ]
44
+ }
45
+ ]
46
+ }
@@ -0,0 +1 @@
1
+ """LabMCP server for Thermo Orbitrap (Instrument API)."""
@@ -0,0 +1,128 @@
1
+ """The backend interface the driver talks to, and the plain-Python records it exchanges.
2
+
3
+ Two implementations exist:
4
+
5
+ * :class:`labmcp_thermo_iapi.pythonnet_backend.PythonNetBackend` loads the scientist's own,
6
+ licensed Thermo Fisher Instrument API (IAPI) assemblies through pythonnet on the Windows
7
+ instrument PC.
8
+ * :class:`labmcp_thermo_iapi.simulator.FakeOrbitrap` emits synthetic scans for ``--simulate``
9
+ and CI.
10
+
11
+ Nothing in here imports .NET. Everything that crosses the backend boundary is a plain Python
12
+ value, so the driver, the tools and the tests are identical for both backends.
13
+ """
14
+
15
+ from __future__ import annotations
16
+
17
+ import abc
18
+ from collections.abc import Callable
19
+ from dataclasses import dataclass, field
20
+ from typing import Any, Literal
21
+
22
+ AcquisitionMode = Literal["duration", "scan_count", "until_stopped"]
23
+
24
+
25
+ @dataclass(frozen=True)
26
+ class ParameterDescription:
27
+ """One entry of ``IScans.PossibleParameters`` (``IParameterDescription``).
28
+
29
+ ``selection`` follows the grammar documented on ``IParameterDescription.Selection`` in
30
+ lib/API-2.0.xml: ``""`` (no argument), ``"string"`` (free text), ``"num1-num2"`` (integer
31
+ range, inclusive), ``"num1.frac-num2.frac"`` (float range, inclusive) or
32
+ ``"sel1,sel2,..."`` (one of the listed values).
33
+ """
34
+
35
+ name: str
36
+ selection: str
37
+ default_value: str = ""
38
+ help: str = ""
39
+
40
+
41
+ @dataclass
42
+ class Centroid:
43
+ mz: float
44
+ intensity: float
45
+ charge: int | None = None
46
+
47
+
48
+ @dataclass
49
+ class ScanRecord:
50
+ """A scan copied out of ``MsScanEventArgs.GetScan()`` before the .NET object is disposed."""
51
+
52
+ received_at: str # UTC ISO 8601, stamped by the backend when MsScanArrived fired
53
+ header: dict[str, str]
54
+ trailer: dict[str, str]
55
+ centroid_count: int
56
+ centroids: list[Centroid] # sorted by decreasing intensity, capped by the backend
57
+ status_log: dict[str, str] = field(default_factory=dict)
58
+ sequence: int = 0 # assigned by the driver: arrival order since connect
59
+
60
+
61
+ class OrbitrapBackend(abc.ABC):
62
+ """What the driver needs from an Orbitrap, expressed in IAPI terms.
63
+
64
+ Every method maps onto IAPI members listed in :mod:`labmcp_thermo_iapi.iapi_members`
65
+ (see :class:`~labmcp_thermo_iapi.pythonnet_backend.PythonNetBackend` for the mapping).
66
+ Control methods return what the IAPI returns: ``True`` when the command was sent to the
67
+ instrument, ``False`` otherwise.
68
+ """
69
+
70
+ #: "simulator" or "pythonnet"
71
+ kind: str = "abstract"
72
+
73
+ @abc.abstractmethod
74
+ def open(self, on_scan: Callable[[ScanRecord], None]) -> None:
75
+ """Connect, and call ``on_scan`` for every scan (from a background thread)."""
76
+
77
+ @abc.abstractmethod
78
+ def identify(self) -> dict[str, str]: ...
79
+
80
+ @abc.abstractmethod
81
+ def status(self) -> dict[str, Any]:
82
+ """Keys: service_connected, instrument_connected, instrument_name, instrument_id,
83
+ system_mode, system_state, can_pause, can_resume, api_license (True/False/None),
84
+ readbacks {name: {value, unit, status}}, readback_names [str]."""
85
+
86
+ @abc.abstractmethod
87
+ def possible_parameters(self) -> list[ParameterDescription]: ...
88
+
89
+ @abc.abstractmethod
90
+ def start_acquisition(
91
+ self,
92
+ mode: AcquisitionMode,
93
+ *,
94
+ duration_s: float | None,
95
+ scan_count: int | None,
96
+ raw_file_path: str | None,
97
+ sample_name: str | None,
98
+ comment: str | None,
99
+ ) -> None: ...
100
+
101
+ @abc.abstractmethod
102
+ def pause_acquisition(self) -> None: ...
103
+
104
+ @abc.abstractmethod
105
+ def resume_acquisition(self) -> None: ...
106
+
107
+ @abc.abstractmethod
108
+ def cancel_acquisition(self) -> None: ...
109
+
110
+ @abc.abstractmethod
111
+ def set_standby(self) -> None: ...
112
+
113
+ @abc.abstractmethod
114
+ def set_custom_scan(
115
+ self, values: dict[str, str], *, running_number: int, single_processing_delay_s: float
116
+ ) -> bool: ...
117
+
118
+ @abc.abstractmethod
119
+ def cancel_custom_scan(self) -> bool: ...
120
+
121
+ @abc.abstractmethod
122
+ def set_repeating_scan(self, values: dict[str, str], *, running_number: int) -> bool: ...
123
+
124
+ @abc.abstractmethod
125
+ def cancel_repeating_scan(self) -> bool: ...
126
+
127
+ @abc.abstractmethod
128
+ def close(self) -> None: ...