dicom-agent-mcp 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,24 @@
1
+ # Python environments and generated artifacts
2
+ .venv/
3
+ venv/
4
+ __pycache__/
5
+ *.py[cod]
6
+ .pytest_cache/
7
+ .coverage
8
+ .coverage.*
9
+ htmlcov/
10
+ dist/
11
+ build/
12
+ *.egg-info/
13
+
14
+ # Local medical data
15
+ dicom-cache/
16
+ inbox/
17
+ *.dcm
18
+
19
+ # Local configuration and secrets
20
+ .env
21
+ .env.*
22
+ !.env.example
23
+ dicom-agent-mcp.yaml
24
+ config.yaml
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,334 @@
1
+ Metadata-Version: 2.5
2
+ Name: dicom-agent-mcp
3
+ Version: 0.1.0
4
+ Summary: MCP server that gives AI agents protocol-neutral DICOM tools (DIMSE and DICOMweb).
5
+ Project-URL: Homepage, https://github.com/arunmk-ms/dicom-agent-mcp
6
+ Project-URL: Repository, https://github.com/arunmk-ms/dicom-agent-mcp
7
+ Project-URL: Issues, https://github.com/arunmk-ms/dicom-agent-mcp/issues
8
+ Author: arunmk-ms
9
+ License-Expression: Apache-2.0
10
+ License-File: LICENSE
11
+ Keywords: ai-agents,dicom,dicomweb,mcp,medical-imaging,model-context-protocol,pacs
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Healthcare Industry
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3 :: Only
19
+ Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
20
+ Requires-Python: >=3.10
21
+ Requires-Dist: httpx>=0.27
22
+ Requires-Dist: mcp<2,>=1.9
23
+ Requires-Dist: numpy>=1.24
24
+ Requires-Dist: pillow>=10
25
+ Requires-Dist: pydantic>=2
26
+ Requires-Dist: pydicom>=3.0
27
+ Requires-Dist: pynetdicom>=2.1
28
+ Requires-Dist: pyyaml>=6
29
+ Provides-Extra: codecs
30
+ Requires-Dist: pylibjpeg-libjpeg>=2; extra == 'codecs'
31
+ Requires-Dist: pylibjpeg-openjpeg>=2; extra == 'codecs'
32
+ Requires-Dist: pylibjpeg-rle>=2; extra == 'codecs'
33
+ Requires-Dist: pylibjpeg>=2; extra == 'codecs'
34
+ Provides-Extra: dev
35
+ Requires-Dist: pytest>=8; extra == 'dev'
36
+ Description-Content-Type: text/markdown
37
+
38
+ # dicom-agent-mcp
39
+
40
+ <!-- mcp-name: io.github.arunmk-ms/dicom-agent-mcp -->
41
+
42
+ An MCP (Model Context Protocol) server that gives AI agents one set of tools for both **DIMSE** archives (C-ECHO, C-FIND, C-GET, C-MOVE, C-STORE) and **DICOMweb** archives (QIDO-RS, WADO-RS, STOW-RS).
43
+
44
+ It also includes pixel and geometry tools that work on local files: rendering, statistics, measurement, geometry checks, multiplanar reconstruction (MPR) and de-identification. This is the tool layer for Topic 3 (Validated Tool Execution). The verification loop comes later; see [ROADMAP.md](ROADMAP.md).
45
+
46
+ > **Not for clinical use.** This is a research scaffold. Use only with test or de-identified data.
47
+
48
+ ## Tools
49
+
50
+ | Tool | DIMSE node | DICOMweb node | Notes |
51
+ |---|---|---|---|
52
+ | `list_nodes` | – | – | Lists configured nodes; secrets are never returned |
53
+ | `echo` | C-ECHO | `GET /studies?limit=1` | Connectivity check |
54
+ | `search` | C-FIND | QIDO-RS | Levels: patient, study, series, instance. Supports wildcards and date ranges. Paging uses `offset`/`limit`. QIDO has no patient level |
55
+ | `get_metadata` | C-FIND (indexed attributes only) | WADO-RS `/metadata` | Returns keyword-based JSON; bulk data is summarised |
56
+ | `retrieve` | C-GET | WADO-RS | Saves files to `storage_dir/<study>/<series>/<sop>.dcm` |
57
+ | `move` | C-MOVE | – | Destination is a node name or an AE title |
58
+ | `store` | C-STORE | STOW-RS | Accepts files or directories inside the sandbox |
59
+ | `transfer` | retrieve + store | retrieve + store | Works across protocols (e.g. PACS → DICOMweb) |
60
+ | `list_local_files` | – | – | Lists cached or allowed DICOM files |
61
+ | `read_local_metadata` | – | – | Reads a local file header without pixel data |
62
+
63
+ ### Pixel and geometry tools (local files)
64
+
65
+ | Tool | What it does |
66
+ |---|---|
67
+ | `render_image` | Renders one frame to a PNG and returns it alongside JSON. Windowing comes from explicit centre/width values, a preset (`lung`, `mediastinum`, `soft_tissue`, `abdomen`, `liver`, `bone`, `brain`, `subdural`, `stroke`), the file's window, or 0.5–99.5 percentiles. Corrects for non-square pixels and MONOCHROME1, and labels the edges with patient directions (for example R/L, A/P) |
68
+ | `pixel_statistics` | Reports min, max, mean, standard deviation, percentiles and a voxel count for a frame or a rectangular/elliptical ROI. ROIs can be given in pixels or mm. Values are in modality units (HU for CT) and the ROI area is reported in mm² |
69
+ | `measure_distance` | Measures the in-plane distance in mm between two pixels and returns both points in patient (LPS) coordinates |
70
+ | `check_geometry` | Groups files into series and checks whether each one can be treated as a volume. Issues are reported with codes such as `MISSING_SLICES`, `NON_UNIFORM_SPACING`, `DUPLICATE_POSITIONS`, `MIXED_ORIENTATION`, `OBLIQUE`, `SHEARED_STACK` and `INSTANCE_ORDER_MISMATCH` |
71
+ | `render_mpr` | Renders an axial, coronal or sagittal slice reformatted from a series that passes `check_geometry`. The PNG uses true mm aspect and radiological orientation |
72
+ | `deidentify` | Writes de-identified copies under `storage_dir/deidentified` using a subset of the Basic Profile. See [De-identification](#de-identification) |
73
+
74
+ Every pixel result includes an `input_fingerprint`: a SHA-256 hash of the decoded pixels and geometry. It does not change with the transfer syntax, and the planned verification loop will use it to bind results to their inputs.
75
+
76
+ Each tool carries MCP annotations (`readOnlyHint`, `destructiveHint`, `idempotentHint`) so a harness can decide which tools need approval.
77
+
78
+ ## Install
79
+
80
+ ```powershell
81
+ python -m venv .venv
82
+ .venv\Scripts\python -m pip install -e ".[dev]"
83
+ # Optional: decoders for JPEG, JPEG-LS, JPEG 2000 and RLE compressed pixel data
84
+ .venv\Scripts\python -m pip install -e ".[codecs]"
85
+ ```
86
+
87
+ ## Configure
88
+
89
+ No config file is needed. Pass nodes and paths as arguments in the harness config; add a YAML file only for advanced settings.
90
+
91
+ ### Arguments
92
+
93
+ | Argument | Meaning |
94
+ |---|---|
95
+ | `--node SPEC` | Adds a node. Repeatable. See the node spec below |
96
+ | `--storage-dir DIR` | Local cache for retrieved files and renders. Default `~/.dicom-agent-mcp/cache` |
97
+ | `--allow-path DIR` | Extra directory that the local-file and pixel tools may read. Repeatable |
98
+ | `--calling-ae AE` | AE title this server uses for DIMSE. Default `DICOM_MCP`; register it on your PACS |
99
+ | `--config FILE` | Optional YAML file (see below) |
100
+ | `--print-config` | Prints the resolved settings and exits. Useful for checking a harness setup |
101
+
102
+ **Node spec:** `name=URL[;option;option…]`
103
+
104
+ | URL | Node type |
105
+ |---|---|
106
+ | `dimse://AE_TITLE@host:port` | DIMSE (C-FIND, C-GET, C-MOVE, C-STORE) |
107
+ | `http://…` or `https://…` | DICOMweb base URL (QIDO-RS, WADO-RS, STOW-RS) |
108
+
109
+ | Option | Meaning |
110
+ |---|---|
111
+ | `read-only` | `store`, `move` and `transfer` refuse to write to this node |
112
+ | `token-env=VAR` | DICOMweb bearer token read from environment variable `VAR` |
113
+ | `user=NAME;password-env=VAR` | DICOMweb basic auth; the password is read from `VAR` |
114
+ | `no-verify-tls` | Skip TLS certificate checks (test servers only) |
115
+ | `transfer-syntax=UID` | Transfer syntax requested from WADO-RS. Empty means the server default; the default `*` keeps the stored encoding |
116
+
117
+ Examples:
118
+
119
+ ```text
120
+ --node orthanc=dimse://ORTHANC@localhost:4242
121
+ --node orthanc-web=http://localhost:8042/dicom-web
122
+ --node "azure=https://<workspace>-<service>.dicom.azurehealthcareapis.com/v2;token-env=AZURE_DICOM_TOKEN;read-only"
123
+ ```
124
+
125
+ **Secrets never go in arguments.** Arguments are visible in process lists and are often committed in `mcp.json`. Put tokens and passwords in environment variables and pass only the variable name.
126
+
127
+ With no `--node`, the server still starts: the local-file and pixel tools work on files under the allowed paths.
128
+
129
+ ### Environment variables
130
+
131
+ Every argument has an environment-variable equivalent, which suits Docker and CI:
132
+
133
+ | Variable | Equivalent |
134
+ |---|---|
135
+ | `DICOM_AGENT_MCP_NODES` | `--node`; several specs separated by spaces |
136
+ | `DICOM_AGENT_MCP_STORAGE_DIR` | `--storage-dir` |
137
+ | `DICOM_AGENT_MCP_ALLOWED_PATHS` | `--allow-path`; several paths separated by `;` on Windows or `:` elsewhere |
138
+ | `DICOM_AGENT_MCP_CALLING_AE` | `--calling-ae` |
139
+ | `DICOM_AGENT_MCP_CONFIG` | `--config` |
140
+
141
+ ### Optional YAML file (advanced)
142
+
143
+ Use a file for settings that have no argument: timeouts, `max_results`, `max_volume_voxels`, `deid_key_env` and node descriptions. See `config.example.yaml`. If `./dicom-agent-mcp.yaml` exists in the working directory, it is loaded automatically. Relative paths in a file resolve against the file's directory; relative paths in arguments and environment variables resolve against the working directory.
144
+
145
+ **Precedence:** config file, then environment variables, then arguments. Later sources override single values, nodes are merged by name (a `--node` with the same name replaces the file's node), and allowed paths are combined.
146
+
147
+ ## Run
148
+
149
+ ```powershell
150
+ dicom-agent-mcp --node orthanc=dimse://ORTHANC@localhost:4242 # stdio
151
+ dicom-agent-mcp --node orthanc=dimse://ORTHANC@localhost:4242 --transport streamable-http --port 8000
152
+ dicom-agent-mcp --node orthanc=dimse://ORTHANC@localhost:4242 --print-config # check settings
153
+ ```
154
+
155
+ ### VS Code (`.vscode/mcp.json`)
156
+
157
+ ```json
158
+ {
159
+ "inputs": [
160
+ { "id": "azureToken", "type": "promptString", "description": "Azure DICOM access token", "password": true }
161
+ ],
162
+ "servers": {
163
+ "dicom": {
164
+ "type": "stdio",
165
+ "command": "${workspaceFolder}/.venv/Scripts/dicom-agent-mcp",
166
+ "args": [
167
+ "--node", "orthanc=dimse://ORTHANC@localhost:4242",
168
+ "--node", "orthanc-web=http://localhost:8042/dicom-web",
169
+ "--node", "azure=https://<workspace>-<service>.dicom.azurehealthcareapis.com/v2;token-env=AZURE_DICOM_TOKEN;read-only",
170
+ "--storage-dir", "${workspaceFolder}/dicom-cache",
171
+ "--allow-path", "${workspaceFolder}/inbox"
172
+ ],
173
+ "env": { "AZURE_DICOM_TOKEN": "${input:azureToken}" }
174
+ }
175
+ }
176
+ }
177
+ ```
178
+
179
+ ### Claude Desktop / Copilot CLI / other harnesses
180
+
181
+ ```json
182
+ {
183
+ "mcpServers": {
184
+ "dicom": {
185
+ "command": "dicom-agent-mcp",
186
+ "args": [
187
+ "--node", "orthanc=dimse://ORTHANC@localhost:4242",
188
+ "--allow-path", "C:/data/dicom-inbox"
189
+ ]
190
+ }
191
+ }
192
+ }
193
+ ```
194
+
195
+ Use absolute paths here: these harnesses may start the server in any working directory. To use a file instead, pass `"args": ["--config", "C:/path/to/dicom-agent-mcp.yaml"]`.
196
+ ### Local Orthanc for testing
197
+
198
+ ```powershell
199
+ docker-compose up -d # DIMSE on 4242, DICOMweb on http://localhost:8042/dicom-web (compose file not yet tested)
200
+ ```
201
+
202
+ ## Sample prompts
203
+
204
+ These prompts assume three nodes: `orthanc` (DIMSE), `orthanc-web` (DICOMweb) and `azure-dicom`, for example:
205
+
206
+ ```text
207
+ --node orthanc=dimse://ORTHANC@localhost:4242 --node orthanc-web=http://localhost:8042/dicom-web
208
+ --node "azure-dicom=https://<workspace>-<service>.dicom.azurehealthcareapis.com/v2;token-env=AZURE_DICOM_TOKEN"
209
+ ```
210
+
211
+ The tool the agent is expected to call is shown after each prompt.
212
+
213
+ ### Nodes and connectivity
214
+
215
+ | Prompt | Tool |
216
+ |---|---|
217
+ | "Which DICOM nodes are configured, and which ones are read-only?" | `list_nodes` |
218
+ | "Check whether `orthanc` and `azure-dicom` are reachable." | `echo` |
219
+
220
+ ### Search and metadata
221
+
222
+ | Prompt | Tool |
223
+ |---|---|
224
+ | "Find all CT studies on `orthanc` from the last 30 days." | `search` (C-FIND) |
225
+ | "List the series in study `1.2.840…` on `orthanc-web`, with modality and number of images." | `search` (QIDO-RS) |
226
+ | "Find patients whose name starts with `DOE^`." | `search` at patient level (DIMSE nodes only) |
227
+ | "Show the acquisition parameters for series `1.2.840…`: slice thickness, kVp and pixel spacing." | `get_metadata` |
228
+
229
+ ### Moving data
230
+
231
+ | Prompt | Tool |
232
+ |---|---|
233
+ | "Download the chest CT series from `orthanc` into the local cache." | `retrieve` |
234
+ | "Send study `1.2.840…` from `orthanc` to the AE title `WORKSTATION1`." | `move` (C-MOVE) |
235
+ | "Upload the files in `./inbox/case42` to `orthanc-web`." | `store` (STOW-RS) |
236
+ | "Copy series `1.2.840…` from `orthanc` to `azure-dicom`." | `transfer` (works across protocols) |
237
+
238
+ ### Local files
239
+
240
+ | Prompt | Tool |
241
+ |---|---|
242
+ | "What DICOM files do I have locally?" | `list_local_files` |
243
+ | "Read the header of `./dicom-cache/…/x.dcm`. Is it compressed? What is the photometric interpretation?" | `read_local_metadata` |
244
+
245
+ ### Pixels and geometry
246
+
247
+ | Prompt | Tool |
248
+ |---|---|
249
+ | "Show me slice 40 of that series in a lung window." | `render_image` (preset) |
250
+ | "Render it again with centre 40 and width 400." | `render_image` (explicit window) |
251
+ | "What is the mean HU in a 10 mm circle centred at row 256, column 300?" | `pixel_statistics` (ellipse in mm) |
252
+ | "Give me the minimum, maximum and 95th percentile for the whole frame." | `pixel_statistics` |
253
+ | "How far apart in mm are pixel (120, 200) and pixel (180, 260)?" | `measure_distance` |
254
+ | "Can this series be used as a 3D volume? Report any missing slices or uneven spacing." | `check_geometry` |
255
+ | "Show the middle coronal slice in a bone window." | `render_mpr` |
256
+ | "Show sagittal slice 100." | `render_mpr` |
257
+
258
+ ### De-identification
259
+
260
+ | Prompt | Tool |
261
+ |---|---|
262
+ | "De-identify the downloaded study, shift the dates and drop private tags." | `deidentify` |
263
+ | "De-identify it but keep the original dates and the series descriptions." | `deidentify` (`date_mode=keep`, `keep_descriptions`) |
264
+
265
+ ### Multi-step workflows
266
+
267
+ - "Find the latest CT for patient MRN123 on `orthanc`, download it, check its geometry, and show me an axial and a coronal view in a soft-tissue window."
268
+ - "Measure the mean HU of the liver at slice 60 (a 15 mm circle at row 300, column 180) and report the input fingerprint."
269
+ - "Download study X from `orthanc`, de-identify it, and upload the de-identified copy to `azure-dicom`."
270
+
271
+ ### Prompts the server should refuse
272
+
273
+ | Prompt | Expected result |
274
+ |---|---|
275
+ | "Store these files to `<a node marked read_only>`." | Refused because the node is read-only |
276
+ | "Read `C:\Windows\System32\config`." | Refused because the path is outside the sandbox |
277
+ | "Render a coronal MPR of a series that has missing slices." | Refused, with the geometry issues listed |
278
+
279
+ ## Safety
280
+
281
+ - **Path sandbox.** `store`, `list_local_files`, `read_local_metadata` and the pixel tools only accept paths under `storage_dir` or `allowed_paths`.
282
+ - **UID validation.** UIDs are checked before they are used in file paths or URLs.
283
+ - **`read_only` nodes.** `store`, `move` and `transfer` refuse to write to them.
284
+ - **Result caps.** `max_results` limits results; truncation is reported with `truncated: true`.
285
+ - **Pixels in context only by request.** Raw pixel arrays are never returned. `render_image` and `render_mpr` do send a downsampled PNG to the model; a copy is saved under `storage_dir/renders`.
286
+ - **Volume cap.** `render_mpr` refuses series larger than `max_volume_voxels`, and refuses series that fail `check_geometry`.
287
+
288
+ ### De-identification
289
+
290
+ `deidentify` does the following:
291
+
292
+ - removes or empties identifying attributes;
293
+ - drops private tags and overlay or curve groups;
294
+ - replaces PatientName and PatientID with pseudonyms;
295
+ - remaps instance UIDs consistently;
296
+ - by default, shifts dates by a per-patient offset of 1 to 730 days.
297
+
298
+ It records what it did in `DeidentificationMethodCodeSequence`.
299
+
300
+ To get the same pseudonyms and UIDs across runs, set a secret key in the environment variable named by `deid_key_env` (default `DICOM_AGENT_MCP_DEID_KEY`). Without a key, each call uses a random key and the result reports `linkable: false`.
301
+
302
+ It does **not** remove text burned into the pixels; affected modalities produce a warning. It is a research aid, not a certified de-identification tool.
303
+
304
+ ## Architecture
305
+
306
+ ```
307
+ server.py (FastMCP tools) → service.py (routing, sandbox, paging)
308
+ ├── dimse.py (pynetdicom SCU)
309
+ ├── dicomweb.py (httpx QIDO/WADO/STOW)
310
+ ├── imaging.py (windowing, geometry, ROI stats, MPR, fingerprints)
311
+ └── deid.py (Basic Profile subset)
312
+ ```
313
+
314
+ ## Tests
315
+
316
+ ```powershell
317
+ .venv\Scripts\python -m pytest -q
318
+ ```
319
+
320
+ The tests run end to end against an in-process pynetdicom PACS (two AEs so C-MOVE can be tested) and a mocked DICOMweb server. They need no network. The pixel tests use a synthetic CT series with known HU values, spacing and positions.
321
+
322
+ ## Limitations
323
+
324
+ - STOW-RS builds the whole request in memory, and WADO-RS reads the whole response into memory.
325
+ - DIMSE `get_metadata` only returns attributes that the archive indexes for C-FIND.
326
+ - `retrieve` uses C-GET. Archives that only support C-MOVE need `move` to a storage SCP.
327
+ - No TLS for DIMSE yet.
328
+ - Pixel tools have been tested on synthetic CT and pydicom sample files only. Compressed transfer syntaxes, enhanced multi-frame objects and real-world data are not yet tested.
329
+ - MPR uses nearest-slice sampling and does not resample to isotropic voxels.
330
+ - Pixel tools work on local files; use `retrieve` first.
331
+
332
+ ## Roadmap
333
+
334
+ See [ROADMAP.md](ROADMAP.md).