DicomMcp 是一个遵循 Model Context Protocol (MCP) 规范的 DICOM 服务端实现,可用于与模型建立上下文连接。它基于 pynetdicom 开发,还支持 PDF 文本提取功能,为相关应用场景提供了便利。
在 Python 脚本中初始化 DicomMcp 服务:
from dicom_mcp import DicomMcpServer
# 创建配置文件
config = {
"port": 11112,
"title": "DicomMcp Server",
"description": "A DICOM server following the Model Context Protocol"
}
# 初始化服务
server = DicomMcpServer(config)
# 启动服务
server.start()
通过命令行运行:
python -m dicom_mcp.run --config config.json
通过 pip 安装:
pip install dicom-mcp
创建一个配置文件 config.json,内容如下:
{
"port": 11112,
"title": "DicomMcp Server",
"description": "A DICOM server following the Model Context Protocol"
}
server.py:实现 MCP 服务器逻辑。dicom_client.py:处理 DICOM 请求和响应。attributes.py:定义 DICOM 属性预设。config.py:管理配置文件。在 tests/ 文件夹中提供多个测试脚本,包括:
pytest tests/test_dicom_mcp.py # 运行所有测试
pytest tests/test_dicom_pdf.py # 测试 PDF 解析功能
git clone https://github.com/yourusername/dicom-mcp.git
cd dicom-mcp
python -m venv .venv
source .venv/bin/activate # 在 Windows 上使用:.venv\Scripts\activate
pip install -e .
cd tests
docker-compose up -d
pytest tests/test_dicom_mcp.py
pytest tests/test_dicom_pdf.py
DicomMcp 项目在 MIT 协议下开源,具体细节请参见 LICENSE 文件。