bach-openfda
v1.0.1
Published
MCP server for OpenFDA Drug Label API - enables AI agents to query FDA drug information
Maintainers
Readme
OpenFDA Drug Label MCP Server
一个用于查询 FDA 药物标签信息的 MCP(Model Context Protocol)服务器,专为药物不良反应智能体设计。
🚀 使用 npx 快速启动(推荐)
无需安装,直接在 Cursor / Cherry Studio 的 MCP 配置中使用:
{
"mcpServers": {
"openfda": {
"command": "npx",
"args": ["-y", "bach-openfda"]
}
}
}保存配置后重启,npx 会自动从 npm 下载并运行最新版本的 bach-openfda。
包地址: https://www.npmjs.com/package/bach-openfda
功能特性
- 药物标签搜索: 通过药物名称、活性成分、制造商等搜索 FDA 药物标签
- 不良反应查询: 获取特定药物的不良反应信息
- 警告信息: 查询药物的警告和注意事项
- 适应症信息: 获取药物的适应症和用法信息
可用工具
1. search_drug_labels
搜索 FDA 药物标签,支持复杂查询语法。
参数:
search(string): 搜索查询,如 "aspirin", "openfda.brand_name:tylenol"count(string): 按字段统计结果skip(number): 跳过记录数(分页)limit(number): 返回记录数限制 (1-1000)
2. get_drug_adverse_reactions
获取特定药物的不良反应信息。
参数:
drug_name(string, 必需): 药物名称limit(number): 返回记录数限制 (1-100)
3. get_drug_warnings
获取药物的警告和注意事项。
参数:
drug_name(string, 必需): 药物名称limit(number): 返回记录数限制 (1-100)
4. get_drug_indications
获取药物的适应症和用法信息。
参数:
drug_name(string, 必需): 药物名称limit(number): 返回记录数限制 (1-100)
安装和运行
本地开发
# 安装依赖
npm install
# 开发模式运行
npm run dev
# 构建
npm run build
# 生产模式运行
npm startUbuntu 服务器部署
1. 环境准备
# 更新系统
sudo apt update && sudo apt upgrade -y
# 安装Node.js 18+
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt-get install -y nodejs
# 验证安装
node --version
npm --version2. 部署 MCP 服务器
# 创建项目目录
mkdir -p ~/mcp-servers/openfda
cd ~/mcp-servers/openfda
# 上传项目文件(使用scp或git clone)
# 方法1: 使用git
git clone <your-repo-url> .
# 方法2: 使用scp从本地上传
# scp -r /path/to/mcp-openfda/* user@your-server:~/mcp-servers/openfda/
# 安装依赖
npm install
# 构建项目
npm run build
# 测试运行
npm start3. 使用 PM2 管理进程(推荐)
# 全局安装PM2
sudo npm install -g pm2
# 创建PM2配置文件
cat > ecosystem.config.js << 'EOF'
module.exports = {
apps: [{
name: 'mcp-openfda',
script: 'dist/index.js',
cwd: '/home/ubuntu/mcp-servers/openfda',
instances: 1,
autorestart: true,
watch: false,
max_memory_restart: '1G',
env: {
NODE_ENV: 'production'
}
}]
}
EOF
# 启动服务
pm2 start ecosystem.config.js
# 设置开机自启
pm2 startup
pm2 save
# 查看状态
pm2 status
pm2 logs mcp-openfda4. 配置防火墙(如果需要网络访问)
# 如果需要通过网络访问,可以配置nginx反向代理
sudo apt install nginx
# 创建nginx配置
sudo tee /etc/nginx/sites-available/mcp-openfda << 'EOF'
server {
listen 80;
server_name your-domain.com; # 替换为你的域名或IP
location / {
proxy_pass http://localhost:3000; # 如果MCP服务器监听3000端口
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_cache_bypass $http_upgrade;
}
}
EOF
# 启用站点
sudo ln -s /etc/nginx/sites-available/mcp-openfda /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx远程调用配置
方法 1: 通过 SSH 隧道
在客户端机器上创建 SSH 隧道:
# 创建SSH隧道,将本地端口转发到服务器
ssh -L 3000:localhost:3000 user@your-server-ip
# 然后在MCP客户端配置中使用 localhost:3000方法 2: 网络 MCP 服务器
如果需要通过网络直接访问,需要修改 MCP 服务器以支持网络传输:
// 在src/index.ts中添加网络传输支持
import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
// 替换stdio传输为网络传输
const transport = new SSEServerTransport("/message", response);方法 3: 使用 Docker 部署
# 创建Dockerfile
cat > Dockerfile << 'EOF'
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY dist/ ./dist/
COPY src/ ./src/
EXPOSE 3000
CMD ["npm", "start"]
EOF
# 构建和运行
docker build -t mcp-openfda .
docker run -d -p 3000:3000 --name mcp-openfda-server mcp-openfda使用示例
在 Claude Desktop 中配置
在 Claude Desktop 的配置文件中添加:
{
"mcpServers": {
"openfda": {
"command": "node",
"args": ["/path/to/mcp-openfda/dist/index.js"],
"env": {}
}
}
}远程服务器配置
{
"mcpServers": {
"openfda": {
"command": "ssh",
"args": [
"user@your-server-ip",
"cd ~/mcp-servers/openfda && node dist/index.js"
],
"env": {}
}
}
}API 使用示例
// 搜索阿司匹林的信息
await searchDrugLabels({
search: "aspirin",
limit: 5,
});
// 获取布洛芬的不良反应
await getDrugAdverseReactions("ibuprofen", 3);
// 查询泰诺的警告信息
await getDrugWarnings("tylenol", 2);注意事项
- API 限制: OpenFDA API 有速率限制,建议合理控制请求频率
- 数据准确性: 返回的数据仅供参考,不应作为医疗建议
- 网络安全: 如果部署在公网,请确保适当的安全措施
- 日志监控: 建议配置日志监控以跟踪 API 使用情况
故障排除
常见问题
- 连接失败: 检查网络连接和防火墙设置
- 权限错误: 确保 Node.js 进程有适当的文件权限
- 端口冲突: 检查端口是否被其他服务占用
日志查看
# PM2日志
pm2 logs mcp-openfda
# 系统日志
sudo journalctl -u nginx -f许可证
MIT License
