Skip to main content

DICOM Tools MCP

Python Version MCP License

基于 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 .

配置

  1. 复制 .env.example.env(如果存在)
  2. 配置必要的环境变量

📖 使用方法

作为 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!

  1. Fork 本仓库
  2. 创建特性分支 (git checkout -b feature/AmazingFeature)
  3. 提交更改 (git commit -m 'Add some AmazingFeature')
  4. 推送到分支 (git push origin feature/AmazingFeature)
  5. 开启 Pull Request

📄 许可证

本项目采用 MIT 许可证 - 详见 LICENSE 文件

🔗 相关资源

📧 联系方式

如有问题或建议,请通过以下方式联系:

🙏 致谢

感谢所有为本项目做出贡献的开发者!


注意: 本工具仅供研究和学习使用,处理医疗数据时请遵守相关法律法规和隐私保护要求。

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dicom_tools_mcp-1.0.1.tar.gz (29.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dicom_tools_mcp-1.0.1-py3-none-any.whl (35.6 kB view details)

Uploaded Python 3

File details

Details for the file dicom_tools_mcp-1.0.1.tar.gz.

File metadata

  • Download URL: dicom_tools_mcp-1.0.1.tar.gz
  • Upload date:
  • Size: 29.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.9

File hashes

Hashes for dicom_tools_mcp-1.0.1.tar.gz
Algorithm Hash digest
SHA256 300fb015ed47af2b627f726668b8556df5be63009f8f4429da608d4ecff3184d
MD5 eec4911f1f1b45a4390a071423a72ec9
BLAKE2b-256 6a17b84dade93f06dde6c8ae581e26da3c396da7cde06b94fae0eaf410ae2da3

See more details on using hashes here.

File details

Details for the file dicom_tools_mcp-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for dicom_tools_mcp-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b3001a0f14182876586fab77f8aa02e8f4277817144ab735135f933dd8b204ef
MD5 50fd951c89a4aa497ad8ac8f5e1cad59
BLAKE2b-256 8519dfda08e7605c54755c716209b7e96e5efad8a2901a921a4da74390f47854

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 files

1.0.0

2 files

0.3.5

2 files

0.3.0

2 files

0.2.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page