
PubMed
STDIOAdvanced MCP server for PubMed literature search, citation management, and research analysis
Advanced MCP server for PubMed literature search, citation management, and research analysis
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.
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
For development with additional tools:
make install-dev
Or manually:
pip install -r requirements.txt pip install -e . pip install black isort mypy flake8
Create a .env
file in the project root with the following variables:
# Required PUBMED_API_KEY=your_ncbi_api_key_here [email protected] # Optional CACHE_TTL=300 CACHE_MAX_SIZE=1000 RATE_LIMIT=3.0 LOG_LEVEL=info
.env
fileThe server provides the following MCP tools:
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 }
get_article_details
Get detailed information for specific PMIDs.
{ "pmids": ["12345678", "87654321"], "include_abstracts": true, "include_citations": false }
search_by_author
Search for articles by a specific author.
{ "author_name": "Smith J", "max_results": 10, "include_coauthors": true }
export_citations
Export citations in various formats.
{ "pmids": ["12345678"], "format": "bibtex", "include_abstracts": false }
find_related_articles
Find articles related to a specific PMID.
{ "pmid": "12345678", "max_results": 10 }
search_mesh_terms
Search using MeSH terms.
{ "term": "Machine Learning", "max_results": 20 }
analyze_research_trends
Analyze publication trends over time.
{ "topic": "artificial intelligence", "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: # 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())
# 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
# Format code make format # Run linting make lint # Type checking mypy src/
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
# Build Docker image make docker-build # Run with environment variables 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
: 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 studiesbibtex
: BibTeX formatapa
: APA stylemla
: MLA stylechicago
: Chicago stylevancouver
: Vancouver styleendnote
: EndNote formatris
: RIS formatThis project is licensed under the MIT License - see the LICENSE file for details.
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.