基于 MCP (Model Context Protocol) 的 DICOM 医学影像文件分析工具
Project description
DICOM Tools MCP
基于 MCP (Model Context Protocol) 的 DICOM 医学影像文件分析工具。提供扫描、解析、映射和上传等功能的 Python 实现。
✨ 功能特性
- 📁 目录扫描:快速扫描 DICOM 文件目录,生成统计摘要
- 📄 文件解析:提取 DICOM 文件的关键元数据信息
- 🗂️ 序列映射:生成患者-序列的详细映射关系
- 📤 自动上传:支持自动上传 DICOM 文件进行在线分析
- 🔍 序列分析:支持主动脉和二尖瓣等医学影像分析
- 📊 JSON 导出:导出完整的扫描结果为 JSON 格式
🚀 快速开始
环境要求
- Python 3.10 或更高版本
- Windows/Linux/macOS
安装
使用 uv (推荐)
# 安装 uv
pip install uv
# 安装项目依赖
uv sync
使用 pip
pip install -r requirements.txt
从源码安装
pip install -e .
配置
- 复制
.env.example为.env(如果存在) - 配置必要的环境变量
📖 使用方法
作为 MCP 服务器运行
python main.py
命令行工具
# 运行 DICOM 工具
dicom-tools-mcp
作为 Python 模块使用
from dicom_tools.scanner import scan_dicom_directory_tool
from dicom_tools.parser import parse_dicom_file_tool
# 扫描目录
result = await scan_dicom_directory_tool("/path/to/dicom/files")
# 解析单个文件
result = await parse_dicom_file_tool("/path/to/file.dcm")
🛠️ 可用工具
1. scan-dicom-directory
扫描指定目录下的所有 DICOM 文件,返回统计摘要。
输入参数:
directory_path(string): 要扫描的目录路径
返回信息:
- 总数据量
- 患者数量
- 序列数量
- 文件统计
2. parse-dicom-file
解析单个 DICOM 文件,提取关键元数据。
输入参数:
file_path(string): DICOM 文件的路径
返回信息:
- PatientID
- PatientName
- SeriesInstanceUID
- SeriesDescription
- 其他 DICOM 标签信息
3. get-dicom-series-mapping
生成患者-序列的详细映射关系。
输入参数:
directory_path(string): 要扫描的目录路径
返回信息:
- 患者映射
- 序列列表
- 文件列表
4. export-dicom-json
导出完整的 DICOM 扫描结果为 JSON 格式。
输入参数:
directory_path(string): 要扫描的目录路径
输出:
- 包含所有患者、序列和文件信息的 JSON 文件
5. Analysis_dicom_directory
扫描并自动上传 DICOM 文件进行在线分析。
输入参数:
directory_path(string): DICOM 文件夹路径series_type(string): 分析方法(1=主动脉,9=二尖瓣)
返回信息:
- 上传信息
- 分析 URL
6. separate-series-by-patient
按患者分离 DICOM 序列文件。
输入参数:
fileforsep(string): 要处理的文件路径
📁 项目结构
dicom-tools-mcp/
├── main.py # MCP 服务器主入口
├── upload.py # 上传和分析功能
├── getcookie.py # Cookie 管理
├── getcrpit.py # 加密工具
├── pyproject.toml # 项目配置
├── dicom_tools/ # DICOM 工具核心模块
│ ├── __init__.py
│ ├── scanner.py # 目录扫描
│ ├── parser.py # 文件解析
│ ├── mapping.py # 序列映射
│ ├── exporter.py # JSON 导出
│ ├── types.py # 数据类型定义
│ └── utils.py # 工具函数
└── src/ # 应用源码
├── api/ # API 接口
├── core/ # 核心处理逻辑
├── models/ # 数据模型
└── utils/ # 辅助工具
🔧 开发
运行测试
pytest
代码格式化
black .
类型检查
mypy .
📦 依赖项
主要依赖:
mcp>=0.9.0- Model Context Protocol 框架pydicom>=2.4.0- DICOM 文件处理requests>=2.31.0- HTTP 请求pydantic>=2.0.0- 数据验证tqdm>=4.66.0- 进度条显示pyorthanc- Orthanc PACS 集成
完整依赖列表请查看 pyproject.toml。
🤝 贡献
欢迎提交 Issue 和 Pull Request!
- Fork 本仓库
- 创建特性分支 (
git checkout -b feature/AmazingFeature) - 提交更改 (
git commit -m 'Add some AmazingFeature') - 推送到分支 (
git push origin feature/AmazingFeature) - 开启 Pull Request
📄 许可证
本项目采用 MIT 许可证 - 详见 LICENSE 文件
🔗 相关资源
📧 联系方式
如有问题或建议,请通过以下方式联系:
- 提交 Issue: GitHub Issues
- Email: your.email@example.com
🙏 致谢
感谢所有为本项目做出贡献的开发者!
注意: 本工具仅供研究和学习使用,处理医疗数据时请遵守相关法律法规和隐私保护要求。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dicom_tools_mcp_test-1.0.2.tar.gz.
File metadata
- Download URL: dicom_tools_mcp_test-1.0.2.tar.gz
- Upload date:
- Size: 94.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
605208345fe87d7925092392c52a7b2ca38dfb85f3783543a4b7e9dcd8c8e871
|
|
| MD5 |
b16358e891da8e0fff336fc44b9b881f
|
|
| BLAKE2b-256 |
53cb4f9322e6106eecd55f070b848ae2f60c42f0842fb21ff70ba47a38756b2a
|
File details
Details for the file dicom_tools_mcp_test-1.0.2-py3-none-any.whl.
File metadata
- Download URL: dicom_tools_mcp_test-1.0.2-py3-none-any.whl
- Upload date:
- Size: 41.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9166438ce088e93aba78016f5f30101f14a854f403357886e1deaf69a5de4201
|
|
| MD5 |
c3a33061cba131cf8442b458e7c74e3f
|
|
| BLAKE2b-256 |
50076bd2a00275e0e1f307f127059eb1cb2df22e13dfcd734b613eba943f4ec6
|