rt-imaging-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.
- rt_imaging_mcp-0.1.0/.github/ISSUE_TEMPLATE/bug_report.md +22 -0
- rt_imaging_mcp-0.1.0/.github/ISSUE_TEMPLATE/config.yml +5 -0
- rt_imaging_mcp-0.1.0/.github/ISSUE_TEMPLATE/feature_request.md +12 -0
- rt_imaging_mcp-0.1.0/.github/dependabot.yml +6 -0
- rt_imaging_mcp-0.1.0/.github/pull_request_template.md +11 -0
- rt_imaging_mcp-0.1.0/.github/workflows/ci.yml +56 -0
- rt_imaging_mcp-0.1.0/.github/workflows/release-testpypi.yml +47 -0
- rt_imaging_mcp-0.1.0/.github/workflows/release.yml +69 -0
- rt_imaging_mcp-0.1.0/.gitignore +42 -0
- rt_imaging_mcp-0.1.0/.pre-commit-config.yaml +9 -0
- rt_imaging_mcp-0.1.0/CHANGELOG.md +47 -0
- rt_imaging_mcp-0.1.0/CONTRIBUTING.md +62 -0
- rt_imaging_mcp-0.1.0/LICENSE +201 -0
- rt_imaging_mcp-0.1.0/NOTICE +4 -0
- rt_imaging_mcp-0.1.0/PKG-INFO +167 -0
- rt_imaging_mcp-0.1.0/README.md +141 -0
- rt_imaging_mcp-0.1.0/SECURITY.md +38 -0
- rt_imaging_mcp-0.1.0/docs/releasing.md +46 -0
- rt_imaging_mcp-0.1.0/docs/threat-model.md +240 -0
- rt_imaging_mcp-0.1.0/docs/validation.md +207 -0
- rt_imaging_mcp-0.1.0/pyproject.toml +75 -0
- rt_imaging_mcp-0.1.0/scripts/check_no_medical_images.py +68 -0
- rt_imaging_mcp-0.1.0/scripts/compare_dvh.py +156 -0
- rt_imaging_mcp-0.1.0/scripts/dvh_reference_dicompyler.py +76 -0
- rt_imaging_mcp-0.1.0/scripts/make_dvh_phantoms.py +80 -0
- rt_imaging_mcp-0.1.0/scripts/validate_collection.py +395 -0
- rt_imaging_mcp-0.1.0/src/rt_imaging_mcp/__init__.py +3 -0
- rt_imaging_mcp-0.1.0/src/rt_imaging_mcp/__main__.py +3 -0
- rt_imaging_mcp-0.1.0/src/rt_imaging_mcp/config.py +54 -0
- rt_imaging_mcp-0.1.0/src/rt_imaging_mcp/dvh.py +136 -0
- rt_imaging_mcp-0.1.0/src/rt_imaging_mcp/geometry.py +158 -0
- rt_imaging_mcp-0.1.0/src/rt_imaging_mcp/security/__init__.py +1 -0
- rt_imaging_mcp-0.1.0/src/rt_imaging_mcp/security/allowlist.py +174 -0
- rt_imaging_mcp-0.1.0/src/rt_imaging_mcp/security/errors.py +89 -0
- rt_imaging_mcp-0.1.0/src/rt_imaging_mcp/security/paths.py +116 -0
- rt_imaging_mcp-0.1.0/src/rt_imaging_mcp/security/roi_names.py +156 -0
- rt_imaging_mcp-0.1.0/src/rt_imaging_mcp/server.py +247 -0
- rt_imaging_mcp-0.1.0/src/rt_imaging_mcp/tools/__init__.py +5 -0
- rt_imaging_mcp-0.1.0/src/rt_imaging_mcp/tools/dicom.py +171 -0
- rt_imaging_mcp-0.1.0/src/rt_imaging_mcp/tools/nifti.py +59 -0
- rt_imaging_mcp-0.1.0/src/rt_imaging_mcp/tools/rt.py +169 -0
- rt_imaging_mcp-0.1.0/src/rt_imaging_mcp/tools/rt_common.py +81 -0
- rt_imaging_mcp-0.1.0/src/rt_imaging_mcp/tools/rt_dose.py +109 -0
- rt_imaging_mcp-0.1.0/src/rt_imaging_mcp/tools/rt_dvh.py +313 -0
- rt_imaging_mcp-0.1.0/src/rt_imaging_mcp/tools/rt_plan.py +146 -0
- rt_imaging_mcp-0.1.0/tests/__init__.py +0 -0
- rt_imaging_mcp-0.1.0/tests/conftest.py +22 -0
- rt_imaging_mcp-0.1.0/tests/synthetic.py +384 -0
- rt_imaging_mcp-0.1.0/tests/test_config.py +61 -0
- rt_imaging_mcp-0.1.0/tests/test_dicom_tools.py +208 -0
- rt_imaging_mcp-0.1.0/tests/test_dvh.py +235 -0
- rt_imaging_mcp-0.1.0/tests/test_geometry.py +226 -0
- rt_imaging_mcp-0.1.0/tests/test_nifti_tools.py +88 -0
- rt_imaging_mcp-0.1.0/tests/test_precommit_guard.py +118 -0
- rt_imaging_mcp-0.1.0/tests/test_release_files.py +90 -0
- rt_imaging_mcp-0.1.0/tests/test_roi_names.py +116 -0
- rt_imaging_mcp-0.1.0/tests/test_rt_dose_plan.py +281 -0
- rt_imaging_mcp-0.1.0/tests/test_rt_dvh_tool.py +638 -0
- rt_imaging_mcp-0.1.0/tests/test_rt_tools.py +166 -0
- rt_imaging_mcp-0.1.0/tests/test_scripts.py +60 -0
- rt_imaging_mcp-0.1.0/tests/test_security_allowlist.py +171 -0
- rt_imaging_mcp-0.1.0/tests/test_security_paths.py +163 -0
- rt_imaging_mcp-0.1.0/tests/test_server.py +254 -0
- rt_imaging_mcp-0.1.0/tests/test_static_rules.py +111 -0
- rt_imaging_mcp-0.1.0/tests/test_stdio_integration.py +66 -0
- rt_imaging_mcp-0.1.0/tests/test_synthetic.py +90 -0
- rt_imaging_mcp-0.1.0/tests/test_validate_collection.py +363 -0
- rt_imaging_mcp-0.1.0/uv.lock +1486 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Bug report
|
|
3
|
+
about: Something does not work as documented
|
|
4
|
+
labels: bug
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
> **Do not paste patient data**: no names, IDs, tag values, file names from real studies, or screenshots of real
|
|
8
|
+
> images. Describe the structure of the file instead, or reproduce with synthetic data.
|
|
9
|
+
> For security problems use **Security → Report a vulnerability**, not a public issue.
|
|
10
|
+
|
|
11
|
+
**What happened**
|
|
12
|
+
|
|
13
|
+
**What you expected**
|
|
14
|
+
|
|
15
|
+
**Steps to reproduce** (tool name, arguments with any names removed, file type)
|
|
16
|
+
|
|
17
|
+
**Environment**
|
|
18
|
+
|
|
19
|
+
- rt-imaging-mcp version:
|
|
20
|
+
- Python version:
|
|
21
|
+
- OS:
|
|
22
|
+
- MCP client (Claude Code, Claude Desktop, Inspector, ...):
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Feature request
|
|
3
|
+
about: Suggest an addition
|
|
4
|
+
labels: enhancement
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
**What problem would this solve**
|
|
8
|
+
|
|
9
|
+
**What would the tool return** (remember: output goes into a language model's context, so prefer numbers and
|
|
10
|
+
allowlisted codes over free text)
|
|
11
|
+
|
|
12
|
+
**Alternatives you considered**
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
## What and why
|
|
2
|
+
|
|
3
|
+
<!-- A short description of the change. Link the issue if there is one. -->
|
|
4
|
+
|
|
5
|
+
## Checklist
|
|
6
|
+
|
|
7
|
+
- [ ] No real patient data anywhere (code, tests, description, screenshots)
|
|
8
|
+
- [ ] Tests added or updated; I checked that a test fails when the rule or behaviour is broken
|
|
9
|
+
- [ ] If tool output changed: the threat model, its test mapping and `README.md` are updated
|
|
10
|
+
- [ ] `uv run ruff check .`, `uv run ruff format --check .`, `uv run mypy` and `uv run pytest` pass
|
|
11
|
+
- [ ] `CHANGELOG.md` is updated
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
|
|
11
|
+
concurrency:
|
|
12
|
+
group: ci-${{ github.ref }}
|
|
13
|
+
cancel-in-progress: true
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
lint:
|
|
17
|
+
name: Lint, types and data guard
|
|
18
|
+
runs-on: ubuntu-latest
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@v4
|
|
21
|
+
- uses: actions/setup-python@v5
|
|
22
|
+
with:
|
|
23
|
+
python-version: "3.12"
|
|
24
|
+
- name: Install uv
|
|
25
|
+
run: python -m pip install uv
|
|
26
|
+
- name: Install dependencies
|
|
27
|
+
run: uv sync --locked
|
|
28
|
+
- name: Ruff lint
|
|
29
|
+
run: uv run ruff check .
|
|
30
|
+
- name: Ruff format check
|
|
31
|
+
run: uv run ruff format --check .
|
|
32
|
+
- name: Mypy
|
|
33
|
+
run: uv run mypy
|
|
34
|
+
- name: No medical image files are tracked
|
|
35
|
+
# Backstop for commits made with --no-verify or without the pre-commit hook.
|
|
36
|
+
run: git ls-files -z | xargs -0 python scripts/check_no_medical_images.py
|
|
37
|
+
|
|
38
|
+
test:
|
|
39
|
+
name: Tests (${{ matrix.os }}, Python ${{ matrix.python-version }})
|
|
40
|
+
runs-on: ${{ matrix.os }}
|
|
41
|
+
strategy:
|
|
42
|
+
fail-fast: false
|
|
43
|
+
matrix:
|
|
44
|
+
os: [ubuntu-latest, windows-latest]
|
|
45
|
+
python-version: ["3.11", "3.12", "3.13"]
|
|
46
|
+
steps:
|
|
47
|
+
- uses: actions/checkout@v4
|
|
48
|
+
- uses: actions/setup-python@v5
|
|
49
|
+
with:
|
|
50
|
+
python-version: ${{ matrix.python-version }}
|
|
51
|
+
- name: Install uv
|
|
52
|
+
run: python -m pip install uv
|
|
53
|
+
- name: Install dependencies
|
|
54
|
+
run: uv sync --locked
|
|
55
|
+
- name: Pytest
|
|
56
|
+
run: uv run pytest --cov=rt_imaging_mcp --cov-report=term-missing
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
name: Release to TestPyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
|
|
6
|
+
permissions:
|
|
7
|
+
contents: read
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
build:
|
|
11
|
+
name: Build distributions
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
- uses: actions/setup-python@v5
|
|
16
|
+
with:
|
|
17
|
+
python-version: "3.12"
|
|
18
|
+
- name: Install uv
|
|
19
|
+
run: python -m pip install uv
|
|
20
|
+
- name: Install dependencies
|
|
21
|
+
run: uv sync --locked
|
|
22
|
+
- name: Tests
|
|
23
|
+
run: uv run pytest
|
|
24
|
+
- name: Build
|
|
25
|
+
run: uv build
|
|
26
|
+
- name: Check the distributions
|
|
27
|
+
run: uv run --with twine twine check dist/*
|
|
28
|
+
- uses: actions/upload-artifact@v4
|
|
29
|
+
with:
|
|
30
|
+
name: dist
|
|
31
|
+
path: dist/
|
|
32
|
+
|
|
33
|
+
publish-testpypi:
|
|
34
|
+
name: Publish to TestPyPI
|
|
35
|
+
needs: build
|
|
36
|
+
runs-on: ubuntu-latest
|
|
37
|
+
environment: testpypi
|
|
38
|
+
permissions:
|
|
39
|
+
id-token: write
|
|
40
|
+
steps:
|
|
41
|
+
- uses: actions/download-artifact@v4
|
|
42
|
+
with:
|
|
43
|
+
name: dist
|
|
44
|
+
path: dist/
|
|
45
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
46
|
+
with:
|
|
47
|
+
repository-url: https://test.pypi.org/legacy/
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags: ["v*"]
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
contents: read
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
build:
|
|
12
|
+
name: Build distributions
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
- uses: actions/setup-python@v5
|
|
17
|
+
with:
|
|
18
|
+
python-version: "3.12"
|
|
19
|
+
- name: Install uv
|
|
20
|
+
run: python -m pip install uv
|
|
21
|
+
- name: Install dependencies
|
|
22
|
+
run: uv sync --locked
|
|
23
|
+
- name: Tag must match the package version
|
|
24
|
+
run: |
|
|
25
|
+
version="$(uv run python -c 'import rt_imaging_mcp; print(rt_imaging_mcp.__version__)')"
|
|
26
|
+
if [ "v${version}" != "${GITHUB_REF_NAME}" ]; then
|
|
27
|
+
echo "Tag ${GITHUB_REF_NAME} does not match package version ${version}" >&2
|
|
28
|
+
exit 1
|
|
29
|
+
fi
|
|
30
|
+
- name: Tests
|
|
31
|
+
run: uv run pytest
|
|
32
|
+
- name: Build
|
|
33
|
+
run: uv build
|
|
34
|
+
- name: Check the distributions
|
|
35
|
+
run: uv run --with twine twine check dist/*
|
|
36
|
+
- uses: actions/upload-artifact@v4
|
|
37
|
+
with:
|
|
38
|
+
name: dist
|
|
39
|
+
path: dist/
|
|
40
|
+
|
|
41
|
+
publish-pypi:
|
|
42
|
+
name: Publish to PyPI
|
|
43
|
+
needs: build
|
|
44
|
+
runs-on: ubuntu-latest
|
|
45
|
+
environment: pypi
|
|
46
|
+
permissions:
|
|
47
|
+
id-token: write
|
|
48
|
+
steps:
|
|
49
|
+
- uses: actions/download-artifact@v4
|
|
50
|
+
with:
|
|
51
|
+
name: dist
|
|
52
|
+
path: dist/
|
|
53
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
54
|
+
|
|
55
|
+
github-release:
|
|
56
|
+
name: GitHub Release
|
|
57
|
+
needs: publish-pypi
|
|
58
|
+
runs-on: ubuntu-latest
|
|
59
|
+
permissions:
|
|
60
|
+
contents: write
|
|
61
|
+
steps:
|
|
62
|
+
- uses: actions/download-artifact@v4
|
|
63
|
+
with:
|
|
64
|
+
name: dist
|
|
65
|
+
path: dist/
|
|
66
|
+
- name: Create the release
|
|
67
|
+
env:
|
|
68
|
+
GH_TOKEN: ${{ github.token }}
|
|
69
|
+
run: gh release create "${GITHUB_REF_NAME}" dist/* --repo "${GITHUB_REPOSITORY}" --generate-notes
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# --- Medical imaging data: NEVER commit patient data ---
|
|
2
|
+
*.dcm
|
|
3
|
+
*.dicom
|
|
4
|
+
*.nii
|
|
5
|
+
*.nii.gz
|
|
6
|
+
*.mha
|
|
7
|
+
*.mhd
|
|
8
|
+
*.raw
|
|
9
|
+
*.nrrd
|
|
10
|
+
DICOMDIR
|
|
11
|
+
data/
|
|
12
|
+
private/
|
|
13
|
+
patient_data/
|
|
14
|
+
phantoms/
|
|
15
|
+
|
|
16
|
+
# --- Python ---
|
|
17
|
+
__pycache__/
|
|
18
|
+
*.py[cod]
|
|
19
|
+
*.egg-info/
|
|
20
|
+
.eggs/
|
|
21
|
+
build/
|
|
22
|
+
dist/
|
|
23
|
+
.venv/
|
|
24
|
+
venv/
|
|
25
|
+
.python-version
|
|
26
|
+
|
|
27
|
+
# --- Tooling caches ---
|
|
28
|
+
.pytest_cache/
|
|
29
|
+
.mypy_cache/
|
|
30
|
+
.ruff_cache/
|
|
31
|
+
.coverage
|
|
32
|
+
htmlcov/
|
|
33
|
+
|
|
34
|
+
# --- Editors / OS ---
|
|
35
|
+
.idea/
|
|
36
|
+
.vscode/
|
|
37
|
+
.DS_Store
|
|
38
|
+
Thumbs.db
|
|
39
|
+
|
|
40
|
+
# --- Secrets ---
|
|
41
|
+
.env
|
|
42
|
+
*.key
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
repos:
|
|
2
|
+
- repo: local
|
|
3
|
+
hooks:
|
|
4
|
+
- id: block-medical-images
|
|
5
|
+
name: Block medical image files
|
|
6
|
+
description: Reject staged files that look like DICOM or other medical image data.
|
|
7
|
+
entry: py scripts/check_no_medical_images.py
|
|
8
|
+
language: python
|
|
9
|
+
pass_filenames: true
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes are documented here. The format follows
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/) and the project uses
|
|
5
|
+
[Semantic Versioning](https://semver.org/). While the major version is 0, anything may change.
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
## [0.1.0] - 2026-11-19
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
- Read-only MCP server with stdio transport and a mandatory `--root` directory.
|
|
14
|
+
- DICOM tools: `dicom_scan_directory` (opaque series ids, no UIDs), `dicom_get_metadata` (tag allowlist) and
|
|
15
|
+
`dicom_list_allowed_tags`.
|
|
16
|
+
- `nifti_info`: structural header information only.
|
|
17
|
+
- Radiotherapy tools: `rt_structure_summary` (standardised structure names, planar volume estimate),
|
|
18
|
+
`rt_dose_summary`, `rt_plan_summary` (numbers and allowlisted codes only) and `rt_dvh_metrics` (approximate
|
|
19
|
+
D(p) and V(t) for one structure).
|
|
20
|
+
- Operator options `--enable-tag` and `--enable-roi-name`, and limits `--max-files`, `--max-depth`, `--max-file-mb`.
|
|
21
|
+
- Threat model (rules R1-R12), pre-commit guard against medical image files, CI on Linux and Windows for
|
|
22
|
+
Python 3.11-3.13.
|
|
23
|
+
- Scripts to compare dose-volume metrics with dicompyler-core on synthetic phantoms, and `validate_collection.py`
|
|
24
|
+
to run the comparison over a folder of RT cases and print anonymous aggregate numbers.
|
|
25
|
+
|
|
26
|
+
### Changed
|
|
27
|
+
|
|
28
|
+
- `rt_dvh_metrics` also returns `voxel_size_mm` and `contour_slice_spacing_mm`, so results can be read next to the
|
|
29
|
+
grid resolution. `validate_collection.py` prints the voxel size and contour spacing of every structure and
|
|
30
|
+
summarises by structure size.
|
|
31
|
+
- Voxel weights follow the overlap of each dose slice with the contour slabs: a dose plane exactly on the outer
|
|
32
|
+
boundary of a structure counts half instead of in full, and a plane exactly between two contour slices takes half
|
|
33
|
+
from each instead of belonging wholly to the lower one. This removes a bias of about one plane at the structure
|
|
34
|
+
ends and a bias that grew with the change of cross-section between slices (found with phantoms whose dose planes
|
|
35
|
+
are twice as dense as the contour planes), and makes the structure volume equal to the sum of its slabs.
|
|
36
|
+
|
|
37
|
+
### Fixed
|
|
38
|
+
|
|
39
|
+
- `rt_dvh_metrics` refused realistic structures with `computation exceeds the work limit`: the rasteriser cost
|
|
40
|
+
grew with cells times polygon edges and the cap was too low for dense manual contours on fine dose grids.
|
|
41
|
+
Rasterisation now uses a scanline method (cells plus edge crossings) that gives identical masks and is far
|
|
42
|
+
faster, and the work estimate reflects that.
|
|
43
|
+
|
|
44
|
+
### Known limits
|
|
45
|
+
|
|
46
|
+
- Dose-volume metrics are validated on synthetic phantoms and against dicompyler-core on those phantoms only,
|
|
47
|
+
not against a treatment planning system or real patient data. See [docs/validation.md](docs/validation.md).
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Contributing
|
|
2
|
+
|
|
3
|
+
Thanks for your interest. This project handles medical image files, so a few rules matter more than usual.
|
|
4
|
+
|
|
5
|
+
## The rules that matter
|
|
6
|
+
|
|
7
|
+
1. **Never use or attach real patient data.** Not in code, tests, issues, pull requests or screenshots. Tests
|
|
8
|
+
generate synthetic data at run time (`tests/synthetic.py`). A pre-commit hook and a CI check block medical image
|
|
9
|
+
files from the repository.
|
|
10
|
+
2. **Output is the security boundary.** Whatever a tool returns goes into a language model's context. Read
|
|
11
|
+
[docs/threat-model.md](docs/threat-model.md) before changing or adding a tool. New output fields must be numbers,
|
|
12
|
+
allowlisted codes or standardised names, never free text from a file.
|
|
13
|
+
3. **A rule without a test is not a rule.** Every change to what a tool returns needs a test that fails if the
|
|
14
|
+
rule is broken. Try it: temporarily break the rule and check that a test goes red.
|
|
15
|
+
4. **Say what is approximate.** Results that are not validated against a reference must say so in the tool output
|
|
16
|
+
and the docs.
|
|
17
|
+
|
|
18
|
+
## Development setup
|
|
19
|
+
|
|
20
|
+
Requires Python 3.11+ and [uv](https://docs.astral.sh/uv/).
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
git clone https://github.com/MLwithDyy/rt-imaging-mcp
|
|
24
|
+
cd rt-imaging-mcp
|
|
25
|
+
uv sync
|
|
26
|
+
uv tool install pre-commit # or: pip install pre-commit
|
|
27
|
+
pre-commit install
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Checks that CI also runs:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
uv run ruff check .
|
|
34
|
+
uv run ruff format --check .
|
|
35
|
+
uv run mypy
|
|
36
|
+
uv run pytest
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Making a change
|
|
40
|
+
|
|
41
|
+
1. Open an issue first for anything larger than a small fix.
|
|
42
|
+
2. Create a branch (`feat/...`, `fix/...`, `docs/...`) and keep the change focused.
|
|
43
|
+
3. Add or update tests, and update `README.md`, `CHANGELOG.md` and the threat model when behaviour changes.
|
|
44
|
+
4. Open a pull request. CI must be green on Linux and Windows for Python 3.11, 3.12 and 3.13.
|
|
45
|
+
|
|
46
|
+
Commit messages follow the conventional style (`feat:`, `fix:`, `docs:`, `test:`, `ci:`, `chore:`).
|
|
47
|
+
|
|
48
|
+
## Adding a tool
|
|
49
|
+
|
|
50
|
+
- Put the implementation in `src/rt_imaging_mcp/tools/`, take a `Config`, return JSON-safe data.
|
|
51
|
+
- Resolve every path with `security.paths.resolve_in_root` and return paths only through `to_relative`.
|
|
52
|
+
- Return DICOM attributes only through the allowlist, names only through `security/roi_names.py`, and code strings
|
|
53
|
+
only through an allowlist (`tools/rt_common.code`).
|
|
54
|
+
- Raise the static errors from `security/errors.py`. Never build an error message from file content.
|
|
55
|
+
- Register it in `server.py` with the read-only annotations and add it to the expected tool lists in
|
|
56
|
+
`tests/test_server.py` and `tests/test_stdio_integration.py`.
|
|
57
|
+
- Add security tests (identifiers absent, paths, limits, static errors) next to the functional tests, and a row in
|
|
58
|
+
the threat model's test mapping.
|
|
59
|
+
|
|
60
|
+
## Licence
|
|
61
|
+
|
|
62
|
+
By contributing you agree that your contribution is licensed under the Apache License 2.0.
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [2026] [Mahdy Firmansyah]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|