一个全面的PubMed文献搜索和管理系统Model Context Protocol (MCP)服务器。此服务器通过MCP协议提供高级搜索功能、引用格式化以及研究分析工具。
<a href="https://glama.ai/mcp/servers/@chrismannina/pubmed-mcp"> <img width="380" height="200" src="https://gips1.baidu.com/it/u=2019236500,2306237655&fm=3081&app=3081&f=PNG?w=760&h=400" alt="PubMed Server MCP服务器" /> </a>克隆仓库:
git clone https://github.com/your-org/pubmed-mcp.git
cd pubmed-mcp
安装依赖项:
pip install -r requirements.txt
设置环境变量:
cp env.example .env
# 使用您的NCBI API密钥和电子邮件编辑.env文件
运行服务器:
python -m src.main
对于带有额外工具的开发:
make install-dev
或者手动:
pip install -r requirements.txt
pip install -e .
pip install black isort mypy flake8
在项目根目录创建一个.env文件,包含以下变量:
# 必需
PUBMED_API_KEY=your_ncbi_api_key_here
PUBMED_EMAIL=your.email@example.com
# 可选
CACHE_TTL=300
CACHE_MAX_SIZE=1000
RATE_LIMIT=3.0
LOG_LEVEL=info
.env文件中该服务器提供了以下MCP工具:
search_pubmed使用高级过滤选项搜索PubMed。
{
"query": "机器学习医疗保健",
"max_results": 20,
"date_range": "5y",
"article_types": ["期刊文章", "综述"],
"has_abstract": true
}
get_article_details获取特定PMID的详细信息。
{
"pmids": ["12345678", "87654321"],
"include_abstracts": true,
"include_citations": false
}
search_by_author按特定作者搜索文章。
{
"author_name": "史密斯J",
"max_results": 10,
"include_coauthors": true
}
export_citations以各种格式导出引用。
{
"pmids": ["12345678"],
"format": "bibtex",
"include_abstracts": false
}
find_related_articles查找与特定PMID相关的文章。
{
"pmid": "12345678",
"max_results": 10
}
search_mesh_terms使用MeSH术语进行搜索。
{
"term": "机器学习",
"max_results": 20
}
analyze_research_trends分析随时间变化的研究趋势。
{
"topic": "人工智能",
"years_back": 5,
"include_subtopics": false
}
import asyncio
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
async def main():
server_params = StdioServerParameters(
command="python",
args=["-m", "src.main"]
)
async with stdio_client(server_params) as (read, write):
async with ClientSession(read, write) as session:
# 初始化会话
await session.initialize()
# 搜索PubMed
result = await session.call_tool(
"search_pubmed",
{
"query": "COVID-19疫苗",
"max_results": 5,
"date_range": "1y"
}
)
print(result.content[0].text)
if __name__ == "__main__":
asyncio.run(main())
# 运行所有测试
make test
# 带覆盖率运行测试
make test-coverage
# 运行特定类型的测试
python run_tests.py unit
python run_tests.py integration
python run_tests.py coverage
# 格式化代码
make format
# 运行代码检查
make lint
# 类型检查
mypy src/
pubmed-mcp/
├── src/
│ ├── __init__.py
│ ├── main.py # 入口点
│ ├── server.py # MCP服务器实现
│ ├── models.py # Pydantic模型
│ ├── pubmed_client.py # PubMed API客户端
│ ├── tool_handler.py # 工具请求处理器
│ ├── citation_formatter.py # 引用格式化
│ ├── tools.py # 工具定义
│ └── utils.py # 实用函数
├── tests/ # 测试套件
├── requirements.txt # 依赖项
├── setup.py # 包设置
├── pyproject.toml # 现代Python配置
├── Makefile # 开发命令
├── Dockerfile # 容器设置
└── README.md # 本文件
# 构建Docker镜像
make docker-build
# 使用环境变量运行
make docker-run PUBMED_API_KEY=your_key PUBMED_EMAIL=your_email
version: '3.8'
services:
pubmed-mcp:
build: .
environment:
- PUBMED_API_KEY=your_key
- PUBMED_EMAIL=your_email
- LOG_LEVEL=info
volumes:
- ./data:/app/data
query: 使用PubMed语法的搜索查询max_results: 结果的最大数量(1-200)sort_order: 排序顺序(相关性、发表日期、作者、期刊、标题)date_from/date_to: 日期范围过滤器date_range: 预定义的范围(1年、5年、10年、全部)article_types: 按出版物类型过滤authors: 按作者姓名过滤journals: 按期刊名称过滤mesh_terms: 按MeSH术语过滤language: 语言过滤器(例如,'eng','fre')has_abstract: 仅具有摘要的文章has_full_text: 仅具有全文的文章humans_only: 仅人类研究bibtex: BibTeX格式apa: APA风格mla: MLA风格chicago: 芝加哥风格vancouver: Vancouver风格endnote: EndNote格式ris: RIS格式本项目根据MIT许可证发布 - 详情见LICENSE文件。
查看CHANGELOG.md以获取详细的更改历史记录。
注意:此服务器需要有效的NCBI API密钥,并遵循NCBI的使用指南。请尊重API速率限制和服务条款。