临床试验语义智能服务器

为AI代理提供临床试验数据的语义智能访问层,支持自然语言查询、患者匹配和竞争情报分析。

  • by SuyashEkhande
  • Python
  • 本地部署
  • 11 星标
  • 更新于
在 GitHub 查看 SuyashEkhande/Clinical-Trial-Gov-MCP

使用说明

🏥 ClinicalTrials.gov MCP Server

A semantic intelligence layer for clinical trial data
Transform how AI agents interact with 400,000+ clinical trials

Built with ❤️ by Suyash Ekhande for the clinical trials research community

Features • Quick Start • Tools • Examples • Architecture


https://github.com/user-attachments/assets/87839f47-84fd-44ac-b1e5-4438cea40f92

🎯 这是什么?

这是一个 模型上下文协议(MCP) 为AI代理提供智能语义访问的服务器 ClinicalTrials.gov --世界上最大的临床研究数据库。

与简单的API包装器不同,此服务器提供 10个高级语义工具 了解临床研究工作流程:

而不是。.. 你明白了。..
原始API调用 自然语言查询,如 “肺癌免疫疗法3期试验”
手动分页 自动聚合数千个结果
原始JSON响应 计算指标:试验成熟度、注册速度、完成可能性
构建查询 自动转换为复杂的Essie查询语法

✨ 特性

🔍 智能搜索

  • 自然语言查询支持
  • 自动翻译为Essie语法
  • 20+滤波器参数
  • 基于邻近度的位置搜索

🎯 患者匹配

  • 资格评分(0-100)
  • 年龄/性别/状况匹配
  • 详细说明
  • 下一步指导

📊 计算指标

  • 试验成熟度评估
  • 入学速度分析
  • 完成可能性
  • 市场饱和度得分

🏢 竞争情报

  • 类似的试验发现
  • 赞助商渠道分析
  • 治疗区域测绘
  • 合作网络

📈 分析

  • 招生能力分析
  • 地理分布
  • 疾病景观趋势
  • 字段值统计

📤 导出和格式化

  • JSON、CSV、Markdown输出
  • 分组策略
  • 汇总统计
  • 批处理

🚀 快速开始

先决条件

  • Python 3.11+
  • pip或任何Python包管理器

安装

选项1:pip(建议用于开发)

# Clone the repository
git clone https://github.com/yourusername/clinicaltrials-mcp.git
cd clinicaltrials-mcp

# Create and activate virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt
pip install -e .

选项2:Docker

# Clone the repository
git clone https://github.com/yourusername/clinicaltrials-mcp.git
cd clinicaltrials-mcp

# Build the image
docker build -t clinicaltrials-mcp .

# Run the container
docker run -p 8000:8000 clinicaltrials-mcp

运行服务器

# Start the MCP server (HTTP transport on port 8000)
python server.py
╭──────────────────────────────╮
│     FastMCP 2.14.1           │
│                              │
│  🖥  Server: clinicaltrials  │
│  📦 Transport: HTTP          │
│  🔗 URL: http://0.0.0.0:8000 │
╰──────────────────────────────╯

与任何代理IDE/CLI连接

{
  "mcpServers": {
    "clinicaltrials": {
      "url": "http://localhost:8000/mcp"
    }
  }
}

🛠 工具

核心工具

工具 说明
search_clinical_trials 具有全面过滤功能的自然语言试用发现。支持以下查询 “加利福尼亚州糖尿病和二甲双胍三期招募”
analyze_trial_details 通过资格解析、手臂/干预映射、结果和计算指标进行深入分析
match_patient_to_trials 以患者为中心的匹配,包括资格评分、解释和可操作的后续步骤
get_trial_metadata_schema 自文档化API内省-发现可用字段、枚举和查询语法

分析工具

工具 说明
find_similar_trials 竞争格局分析,包括条件、干预措施和阶段的相似性评分
analyze_trial_outcomes 提取并比较各试验的主要/次要结局指标
get_enrollment_intelligence 市场容量分析,包括注册模式、饱和分数和速度洞察

情报工具

工具 说明
analyze_sponsor_network 组织投资组合分析,包括治疗重点、管道阶段分布和合作
export_and_format_trials 以JSON、CSV或Markdown格式批量导出,并进行分组和汇总统计
query_trial_statistics 综合分析:地理分布、疾病格局、登记模式

💬 例子

患者试验匹配

“我是加利福尼亚州一名55岁的男性2型糖尿病患者。我可以参加哪些临床试验?”

result = await match_patient_to_trials(
    age=55,
    gender="MALE",
    primary_condition="Type 2 Diabetes",
    location_state="California",
    must_be_recruiting=True
)
# Returns: Matched trials with eligibility scores and explanations

竞争情报

“查找所有使用检查点抑制剂的3期NSCLC试验,并分析竞争格局”

# Search for trials
trials = await search_clinical_trials(
    query="NSCLC AND checkpoint inhibitor",
    trial_phase=["PHASE3"],
    enrollment_status=["RECRUITING"]
)

# Analyze similar trials for a reference
similar = await find_similar_trials(
    reference_nct_id="NCT04000165",
    similarity_dimensions=["CONDITION", "INTERVENTION", "PHASE"]
)

赞助商分析

“分析辉瑞的肿瘤学管道——他们的活跃试验和治疗重点领域是什么?”

result = await analyze_sponsor_network(
    sponsor_name="Pfizer",
    analyze_therapeutic_areas=True,
    analyze_stage_distribution=True,
    analyze_collaboration_patterns=True
)
# Returns: Portfolio breakdown, phase distribution, top conditions, collaborators

市场分析

“美国黑色素瘤试验的注册情况如何?”

result = await get_enrollment_intelligence(
    condition="melanoma",
    location_country="United States",
    include_capacity_analysis=True,
    include_competitor_summary=True
)
# Returns: Market saturation, enrollment targets, top sponsors, recommendations

🏗️ 建筑

┌─────────────────────────────────────────────────────────────────┐
│                        MCP Clients                               │
│              (Claude Desktop, AI Agents, etc.)                   │
└─────────────────────────────────────────────────────────────────┘
                              │
                              │ Streamable HTTP (port 8000)
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│                     FastMCP Server                               │
│  ┌─────────────────────────────────────────────────────────┐   │
│  │                    10 Semantic Tools                      │   │
│  │  search | analyze | match | metadata | similar | outcomes │   │
│  │  enrollment | sponsor | export | statistics               │   │
│  └─────────────────────────────────────────────────────────┘   │
│                              │                                   │
│  ┌─────────────┐  ┌─────────────────┐  ┌─────────────────┐     │
│  │   Essie     │  │   Pagination    │  │    Metrics      │     │
│  │ Translator  │  │    Handler      │  │   Calculator    │     │
│  └─────────────┘  └─────────────────┘  └─────────────────┘     │
│                              │                                   │
│  ┌─────────────────────────────────────────────────────────┐   │
│  │              Async HTTP Client (aiohttp)                  │   │
│  │         TTL Caching | Retry Logic | Error Handling        │   │
│  └─────────────────────────────────────────────────────────┘   │
└─────────────────────────────────────────────────────────────────┘
                              │
                              │ HTTPS
                              ▼
┌─────────────────────────────────────────────────────────────────┐
│                ClinicalTrials.gov API v2                         │
│                    400,000+ Studies                              │
└─────────────────────────────────────────────────────────────────┘

项目结构

clinicaltrials-gov-mcp/
├── server.py              # FastMCP server with 10 tools
├── config.py              # API settings, cache TTLs, field lists
├── core/
│   ├── api_client.py      # Async HTTP client with caching & retry
│   ├── models.py          # Pydantic schemas (28 enums, 15 models)
│   ├── pagination.py      # Token-based pagination handler
│   └── essie_translator.py # Natural language → Essie query syntax
├── tools/
│   ├── search.py          # Trial search with NL support
│   ├── analyze.py         # Trial analysis & similarity
│   ├── patient_match.py   # Patient eligibility matching
│   ├── metadata.py        # API schema introspection
│   ├── enrollment.py      # Enrollment intelligence
│   ├── sponsor.py         # Sponsor network analysis
│   ├── export.py          # Multi-format export
│   └── statistics.py      # Aggregate analytics
└── utils/
    ├── metrics.py         # Computed metrics (maturity, pace, etc.)
    └── formatting.py      # Output formatting (Markdown, CSV)

🔧 技术细节

关键设计决策

方面 决策 基本原理
HTTP客户端 aiohttp httpx从ClinicalTrials.gov返回了403个结果;aiohttp工作可靠
缓存 TTLCache(cachetools) 元数据(24小时)、统计(6小时)、研究(1小时)、搜索(15分钟)的单独缓存
查询翻译 基于规则的Essie翻译器 将自然语言转换为ClinicalTrials.gov的复杂查询语法
分页 基于令牌的流媒体 通过可选流媒体高效处理大型结果集
运输 流式HTTP 用于生产部署的现代MCP传输

Essie查询语法

服务器自动翻译自然语言查询:

Input:  "lung cancer AND pembrolizumab in phase 3"
Output: AREA[Condition]"lung cancer" AND AREA[InterventionName]pembrolizumab AND AREA[Phase]PHASE3

Input:  "recruiting diabetes trials in California"
Output: AREA[Condition]diabetes AND AREA[OverallStatus]RECRUITING AND AREA[LocationState]"California"

计算指标

度量 计算
试用期 基于阶段、状态和自开始以来的时间(早/中/晚)
入学速度 基于阶段基准的预期与实际时间表
完成可能性 基于阶段和赞助商类别的统计似然性
相似性得分 跨条件、干预措施、阶段和赞助商的加权匹配

🧪 测试

# Run the test suite
python test_tools.py

这将针对实时API测试所有10个工具:

1️⃣  search_clinical_trials     ✅ SUCCESS
2️⃣  analyze_trial_details      ✅ SUCCESS
3️⃣  match_patient_to_trials    ✅ SUCCESS
4️⃣  get_trial_metadata_schema  ✅ SUCCESS
5️⃣  find_similar_trials        ✅ SUCCESS
6️⃣  analyze_trial_outcomes     ✅ SUCCESS
7️⃣  get_enrollment_intelligence ✅ SUCCESS
8️⃣  analyze_sponsor_network    ✅ SUCCESS
9️⃣  export_and_format_trials   ✅ SUCCESS
🔟 query_trial_statistics      ✅ SUCCESS

📚 api参考

此服务器与 ClinicalTrials.gov REST API v2.

使用的端点

  • GET /studies --搜索和筛选研究
  • GET /studies/{nctId} --检索单个研究详细信息
  • GET /studies/metadata --数据模型模式
  • GET /studies/enums --枚举值
  • GET /studies/search-areas --可搜索字段
  • GET /stats/* --汇总统计数据
  • GET /version -API版本

🤝 贡献

欢迎投稿!请随时提交拉取请求。

  1. 克隆该仓库
  2. 创建功能分支(git checkout -b feature/AmazingFeature)
  3. 提交您的更改(git commit -m 'Add some AmazingFeature')
  4. 推到分支(git push origin feature/AmazingFeature)
  5. 打开拉取请求

致谢


Built with ❤️ by Suyash Ekhande for the clinical trials research community