PubMed MCP Server
A comprehensive Model Context Protocol server that enables advanced PubMed literature search, citation formatting, and research analysis through natural language interactions.
README
PubMed MCP Server
A comprehensive Model Context Protocol (MCP) server for PubMed literature search and management. This server provides advanced search capabilities, citation formatting, and research analysis tools through the MCP protocol.
Features
- Advanced PubMed Search: Search with complex filters including date ranges, article types, authors, journals, and MeSH terms
- Article Details: Retrieve detailed information for specific PMIDs including abstracts, authors, and metadata
- Citation Export: Export citations in multiple formats (BibTeX, APA, MLA, Chicago, Vancouver, EndNote, RIS)
- Author Search: Find articles by specific authors with co-author information
- Related Articles: Discover articles related to a specific PMID
- MeSH Term Search: Search and explore Medical Subject Headings
- Journal Analysis: Get metrics and recent articles from specific journals
- Research Trends: Analyze publication trends over time
- Article Comparison: Compare multiple articles side by side
- Caching: Built-in caching for improved performance
- Rate Limiting: Respectful API usage with configurable rate limits
Installation
Prerequisites
- Python 3.8 or higher
- NCBI API key (free registration required)
- Valid email address for NCBI API identification
Quick Start
-
Clone the repository:
git clone https://github.com/your-org/pubmed-mcp.git cd pubmed-mcp -
Install dependencies:
pip install -r requirements.txt -
Set up environment variables:
cp env.example .env # Edit .env with your NCBI API key and email -
Run the server:
python -m src.main
Development Installation
For development with additional tools:
make install-dev
Or manually:
pip install -r requirements.txt
pip install -e .
pip install black isort mypy flake8
Configuration
Create a .env file in the project root with the following variables:
# Required
PUBMED_API_KEY=your_ncbi_api_key_here
PUBMED_EMAIL=your.email@example.com
# Optional
CACHE_TTL=300
CACHE_MAX_SIZE=1000
RATE_LIMIT=3.0
LOG_LEVEL=info
Getting an NCBI API Key
- Visit NCBI Account Settings
- Sign in or create an account
- Navigate to "API Key Management"
- Create a new API key
- Copy the key to your
.envfile
Usage
Available Tools
The server provides the following MCP tools:
1. search_pubmed
Search PubMed with advanced filtering options.
{
"query": "machine learning healthcare",
"max_results": 20,
"date_range": "5y",
"article_types": ["Journal Article", "Review"],
"has_abstract": true
}
2. get_article_details
Get detailed information for specific PMIDs.
{
"pmids": ["12345678", "87654321"],
"include_abstracts": true,
"include_citations": false
}
3. search_by_author
Search for articles by a specific author.
{
"author_name": "Smith J",
"max_results": 10,
"include_coauthors": true
}
4. export_citations
Export citations in various formats.
{
"pmids": ["12345678"],
"format": "bibtex",
"include_abstracts": false
}
5. find_related_articles
Find articles related to a specific PMID.
{
"pmid": "12345678",
"max_results": 10
}
6. search_mesh_terms
Search using MeSH terms.
{
"term": "Machine Learning",
"max_results": 20
}
7. analyze_research_trends
Analyze publication trends over time.
{
"topic": "artificial intelligence",
"years_back": 5,
"include_subtopics": false
}
Example Usage with MCP Client
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:
# Initialize the session
await session.initialize()
# Search PubMed
result = await session.call_tool(
"search_pubmed",
{
"query": "COVID-19 vaccines",
"max_results": 5,
"date_range": "1y"
}
)
print(result.content[0].text)
if __name__ == "__main__":
asyncio.run(main())
Development
Running Tests
# Run all tests
make test
# Run with coverage
make test-coverage
# Run specific test types
python run_tests.py unit
python run_tests.py integration
python run_tests.py coverage
Code Quality
# Format code
make format
# Run linting
make lint
# Type checking
mypy src/
Project Structure
pubmed-mcp/
├── src/
│ ├── __init__.py
│ ├── main.py # Entry point
│ ├── server.py # MCP server implementation
│ ├── models.py # Pydantic models
│ ├── pubmed_client.py # PubMed API client
│ ├── tool_handler.py # Tool request handlers
│ ├── citation_formatter.py # Citation formatting
│ ├── tools.py # Tool definitions
│ └── utils.py # Utility functions
├── tests/ # Test suite
├── requirements.txt # Dependencies
├── setup.py # Package setup
├── pyproject.toml # Modern Python config
├── Makefile # Development commands
├── Dockerfile # Container setup
└── README.md # This file
Docker
Build and Run
# Build Docker image
make docker-build
# Run with environment variables
make docker-run PUBMED_API_KEY=your_key PUBMED_EMAIL=your_email
Docker Compose
version: '3.8'
services:
pubmed-mcp:
build: .
environment:
- PUBMED_API_KEY=your_key
- PUBMED_EMAIL=your_email
- LOG_LEVEL=info
volumes:
- ./data:/app/data
API Reference
Search Parameters
query: Search query using PubMed syntaxmax_results: Maximum number of results (1-200)sort_order: Sort order (relevance, pub_date, author, journal, title)date_from/date_to: Date range filtersdate_range: Predefined ranges (1y, 5y, 10y, all)article_types: Filter by publication typesauthors: Filter by author namesjournals: Filter by journal namesmesh_terms: Filter by MeSH termslanguage: Language filter (e.g., 'eng', 'fre')has_abstract: Only articles with abstractshas_full_text: Only articles with full texthumans_only: Only human studies
Citation Formats
bibtex: BibTeX formatapa: APA stylemla: MLA stylechicago: Chicago stylevancouver: Vancouver styleendnote: EndNote formatris: RIS format
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Run the test suite
- Submit a pull request
Development Guidelines
- Follow PEP 8 style guidelines
- Add type hints to all functions
- Write comprehensive tests
- Update documentation for new features
- Use conventional commit messages
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
- Issues: GitHub Issues
- Documentation: Project Wiki
- Discussions: GitHub Discussions
Acknowledgments
- NCBI E-utilities for PubMed API access
- Model Context Protocol for the MCP specification
- Anthropic for MCP development and support
Changelog
See CHANGELOG.md for a detailed history of changes.
Note: This server requires a valid NCBI API key and follows NCBI's usage guidelines. Please be respectful of API rate limits and terms of service.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。