与医疗数据MCP服务器的AI聊天
学习通过模型上下文协议(MCP)服务器使用真实世界的医疗和制药数据与人工智能助手进行交互。
](https://codespaces.new/datons/CC)
你将学到什么
- 在VSCode中与AI聊天互动 -使用带有专用MCP服务器的GitHub Copilot Chat
- 查询PubMed -使用自然语言搜索和分析医学文献
- 访问FDA数据 -查询药品信息、不良事件、召回和医疗器械数据
快速开始
1.在代码空间中启动
点击上面的“在GitHub代码空间中打开”按钮或:
- 分叉此存储库
- 点击绿色的“代码”按钮
- 选择“在main上创建代码空间”
环境将自动设置为:
- Python 3.11
- Node.js 20
- GitHub Copilot扩展
- MCP服务器(PubMed和OpenFDA)
2.添加MCP服务器
Codespace启动后,通过VS Code添加MCP服务器:
- 打开命令选项板: 按
Ctrl+Shift+P(Windows/Linux)或Cmd+Shift+P(macOS)
- 运行添加MCP服务器: 类型
MCP: Add MCP Server并选择命令
- 选择连接类型: 选择
stdio
- 添加PubMed服务器:
- 命令: bash - Args: -c "source /workspaces/CC/mcp-servers/pubmearch/.venv/bin/activate && python -m pubmearch.server" - 目标: 工作区
- 添加OpenFDA服务器:
- 命令: bash - Args: -c "node /workspaces/CC/mcp-servers/OpenFDA-MCP-Server/build/index.js" - 目标: 工作区
3.配置API密钥
创建一个 .env 模板中的文件:
cp .env.example .env编辑 .env 并添加您的API密钥:
# PubMed API (Required)
export NCBI_USER_EMAIL="your_email@example.com"
export NCBI_USER_API_KEY="your_api_key"
# FDA API (Optional - increases rate limit)
export FDA_API_KEY="your_fda_key"获取API密钥
PubMed API密钥 (必填):
- 首选 NCBI帐户设置
- 登录或创建帐户
- 滚动至“API密钥”部分
- 单击“创建API密钥”
FDA API密钥 (可选-将速率限制从每小时1000个请求增加到120000个请求):
- 访问 openFDA认证
- 注册API密钥
4.开始使用AI聊天
打开GitHub Copilot Chat(Ctrl+Shift+I或Cmd+Shift+I)并尝试这些示例提示。
提示: 使用 #pubmed 或 #openfda 在消息开头告诉AI要使用哪个MCP服务器。
PubMed研究实例
#pubmed Find recent studies about diabetes treatment#pubmed What are the latest papers on Alzheimer's disease?#pubmed Show me research trends for COVID-19 vaccines#pubmed Search for studies about heart disease prevention published in the last year#pubmed Find papers about cancer immunotherapy from 2024#pubmed What's the latest research on obesity and mental health?#pubmed Search for studies comparing different diabetes medications#pubmed Find research about sleep disorders and their treatments美国食品药品监督管理局药品和器械示例
#openfda Find side effects reported for ibuprofen#openfda What adverse events have been reported for insulin?#openfda Show me recent drug recalls#openfda Find all FDA-approved medications for high blood pressure#openfda What drugs were recalled due to contamination?#openfda Search for adverse events related to pacemakers#openfda Find information about diabetes medications made by Novo Nordisk#openfda What are the reported side effects of aspirin?#openfda Show me drug shortages for antibiotics#openfda Find recalls of medical devices in the last 6 months包括MCP服务器
1.PubMed MCP服务器
查询和分析PubMed的医学文献。
特征:
- 使用高级语法进行文献检索
- 研究热点分析
- 随时间变化的趋势跟踪
- 出版物计数统计
- 综合报告
可用工具:
search_pubmed-搜索PubMed数据库analyze_research_keywords-确定研究热点analyze_publication_count-跟踪出版物趋势generate_comprehensive_analysis-完整的分析报告
2.OpenFDA MCP服务器
访问美国食品药品监督管理局的药品和医疗器械数据库。
特征:
- 药物不良事件报告(FAERS)
- 药品标签信息
- 药品召回和短缺
- 美国食品药品监督管理局批准的药物数据库
- 医疗器械数据(510k,分类,不良事件)
可用工具:
search_drug_adverse_events-FAERS数据search_drug_labels-产品标签search_drug_ndc-国家药品代码目录search_drug_recalls-召回执行search_drugs_fda-美国食品药品监督管理局批准的药物search_drug_shortages-当前短缺search_device_510k-设备间隙search_device_adverse_events-器械不良事件
项目结构
.
├── .devcontainer/ # Codespaces configuration
│ ├── devcontainer.json # Container settings
│ └── post-create.sh # Setup script
├── .vscode/
│ └── mcp.json # MCP server configuration
├── .env.example # API keys template
├── .env # Your API keys (create from template)
├── mcp-servers/ # MCP server installations (auto-generated)
│ ├── pubmearch/ # PubMed MCP server
│ └── OpenFDA-MCP-Server/ # FDA MCP server
└── README.md # This file高级用法
使用PubMed高级搜索语法
PubMed支持高级搜索查询:
# Search in specific fields
diabetes[Title/Abstract]
# Combine terms
(prostat*[Title/Abstract]) AND (cancer[Title/Abstract]) AND (immuno*[Title/Abstract])
# Date ranges
cancer[Title] AND ("2023/01/01"[PDAT] : "2023/12/31"[PDAT])过滤FDA查询
FDA查询支持详细过滤:
Find drug adverse events for:
- Drug: aspirin
- Country: United States
- Date range: 2023-01-01 to 2023-12-31
- Serious events only: true生成报告
两台MCP服务器都可以生成全面的分析报告:
Generate a comprehensive analysis of COVID-19 vaccine research from the past 6 months故障排除
API关键问题
问题: “身份验证失败”或“超出速率限制”
解决方案:
- 验证
.env文件存在并且包含正确的API密钥 - 对于PubMed,确保两者
NCBI_USER_EMAIL和NCBI_USER_API_KEY已设置 - 保存文件-更改立即生效
MCP服务器没有响应
问题: 聊天无法识别PubMed/FDA查询
解决方案:
- 检查
.env文件与您的API密钥一起存在 - 验证MCP服务器是否已安装:
ls -la mcp-servers/- 尝试使用
#pubmed或#openfda邮件中的前缀
学习资源
鸣谢
- PubMed MCP服务器: 深色烘焙机/pubmearch
- OpenFDA MCP服务器: 增强自然/OpenFDA MCP服务器
许可证
本教育项目按原样提供,用于学习目的。
______________________________________________________________________
注: 该工具提供对公共医疗数据集的访问。始终咨询医疗保健专业人员以获取医疗决策和药物信息。
