Skip to main content

基于 MCP (Model Context Protocol) 的 DICOM 医学影像文件分析工具

Project description

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 文件

🔗 相关资源

📧 联系方式

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

🙏 致谢

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


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

Project details


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_test-1.0.1.tar.gz (92.4 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_test-1.0.1-py3-none-any.whl (41.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dicom_tools_mcp_test-1.0.1.tar.gz
  • Upload date:
  • Size: 92.4 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_test-1.0.1.tar.gz
Algorithm Hash digest
SHA256 cd51696ef8835b0b91b16dda9ff380fef41ad860c978e7bce2b1fe54ca1b139a
MD5 e8d9336bb1355083bddb96bb6b3d2a83
BLAKE2b-256 aaa15498742c8d2dc6de44cb85602d1a62f4817627ba20b1df978d05779d020d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for dicom_tools_mcp_test-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b14559711ba409de0e418dce986654d1cd4cb10e3fb804567665a5eaedb16ebc
MD5 0b54b1542ecd63c1271cec9c80e68095
BLAKE2b-256 ffc301276ccb5e2ddc8e59167bf1894761014f79c13a672a1be8ef08e3822c75

See more details on using hashes here.

Supported by

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