Metadata-Version: 2.4
Name: dicomtoolsformcp
Version: 1.3.0
Summary: 基于 MCP (Model Context Protocol) 的 DICOM 医学影像文件分析工具
Project-URL: Homepage, https://github.com/yourusername/dicom-tools-mcp
Project-URL: Repository, https://github.com/yourusername/dicom-tools-mcp
Project-URL: Issues, https://github.com/yourusername/dicom-tools-mcp/issues
Author-email: jiancong Zhang <1316795665@qq.com>
License: MIT
Keywords: dicom,mcp,medical-imaging,model-context-protocol,orthanc
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Healthcare Industry
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
Requires-Python: >=3.10
Requires-Dist: mcp>=0.9.0
Requires-Dist: pydantic>=2.0.0
Requires-Dist: pydicom>=2.4.0
Requires-Dist: pyorthanc
Requires-Dist: requests>=2.31.0
Requires-Dist: sympy
Requires-Dist: tqdm>=4.66.0
Description-Content-Type: text/markdown

# DicomToolsForMCP

`DicomToolsForMCP` 是一个基于 MCP (Model Context Protocol) 的 DICOM 医学影像文件分析与上传工具。它提供了一整套命令行工具，用于处理、分析 DICOM 文件，并将其安全地上传到兼容 MCP 的服务器。

## 功能特性

- **DICOM 文件扫描与解析**: 递归扫描指定目录，解析 DICOM 文件，并提取元数据。
- **数据映射与预处理**: 根据预定义的规则，将 DICOM 标签映射为 MCP 模型所需的数据结构。
- **安全上传**: 通过 Cookie 认证，将处理后的序列安全上传到服务器。
- **批量上传**: 支持批量上传多个 DICOM 序列，后台执行不阻塞。
- **状态查询**: 实时查询已上传序列的处理状态。
- **日志记录**: 自动记录每次上传的详细信息（如 `study_uid` 和目录路径），方便后续追踪。

## 安装

您可以通过 pip 从 PyPI 安装此工具：

```bash
pip install dicomtoolsformcp
```

## 配置 MCP Server

该工具可以作为 MCP Server 运行，通过 stdio 协议与 MCP 客户端通信。

### Claude Desktop 配置

在 Claude Desktop 的配置文件中（macOS: `~/Library/Application Support/Claude/claude_desktop_config.json`），添加以下配置：

```json
{
  "mcpServers": {
    "dicom-tools": {
      "timeout": 600,
      "type": "stdio",
      "command": "uvx",
      "args": [
        "dicomtoolsformcp"
      ],
      "env": {
        "base_url": "https://tavi.fit",
        "name": "tavimercy",
        "password": "!Az123",
        "tel": ""
      }
    }
  }
}
```

**配置说明：**
- `timeout`: 超时时间（秒），建议设置为 600 秒以支持长时间运行的批量上传任务
- `type`: 通信协议类型，使用 `stdio`
- `command`: 使用 `uvx` 命令（uv 包管理器的工具，可直接运行 PyPI 包）
- `args`: 包名 `dicomtoolsformcp`

**前置要求：**
确保已安装 `uv` 工具：
```bash
curl -LsSf https://astral.sh/uv/install.sh | sh
```

或使用 pip 安装：
```bash
pip install uv
```

### 其他 MCP 客户端配置

对于 Cursor 或其他支持 MCP 的客户端，可以使用相同的配置格式。如果 `uvx` 不可用，也可以尝试使用 Python 模块方式：

```json
{
  "mcpServers": {
    "dicom-tools": {
      "timeout": 600,
      "type": "stdio",
      "command": "python3",
      "args": ["-m", "dicomtoolsformcp"],
      "env": {
        "base_url": "https://tavi.fit",
        "name": "tavimercy",
        "password": "!Az123",
        "tel": ""
      }
    }
  }
}
```

### 环境变量说明

配置中的环境变量用于自动登录和认证：

- `base_url`: 服务器基础 URL（必需）
- `name`: 登录用户名（必需）
- `password`: 登录密码（必需）
- `tel`: 电话号码（可选，可为空字符串）

## 使用方法

### 可用工具

1. **scan-dicom-directory**: 扫描指定目录下所有可读的 .dcm 文件
2. **parse-dicom-file**: 解析单个 DICOM 文件，提取元数据
3. **Analysis_dicom_directory**: 上传单个 DICOM 序列进行分析
4. **batch_upload_dicom_directory**: 批量上传目录中的所有 DICOM 序列（后台执行，不阻塞）
5. **fileforsep**: 按患者和序列拆分目录下的 DICOM 文件
6. **get_result_tool**: 根据 study_uid 查询分析结果

### 命令行使用

也可以通过命令行直接运行：

```bash
dicomtoolsformcp
```

## 使用示例

### 批量上传 DICOM 序列

批量上传功能支持在后台执行，不会阻塞 MCP 通信：

```json
{
  "name": "batch_upload_dicom_directory",
  "arguments": {
    "directory_path": "/path/to/dicom/folder",
    "series_type": "1"
  }
}
```

**series_type 说明:**
- `1`: 主动脉分析
- `9`: 二尖瓣分析

### 查询分析结果

```json
{
  "name": "get_result_tool",
  "arguments": {
    "study_uid": "1.3.12.2.1107.5.1.4.76315.30000021042706150001900118311"
  }
}
```

## 依赖项

本项目依赖于以下 Python 包：

- `mcp>=0.9.0`
- `pydicom>=2.4.0`
- `requests>=2.31.0`
- `pydantic>=2.0.0`
- `tqdm>=4.66.0`
- `pyorthanc`
- `sympy`

所有依赖项将在安装 `dicomtoolsformcp` 时自动安装。

## 许可证

本项目采用 MIT 许可证。详情请参阅 `LICENSE` 文件。

