Labsco
aeghnnsw logo

PubMed MCP Server

โ˜… 1

from aeghnnsw

Search and download scientific articles from PubMed's E-utilities API.

๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅโœ“ VerifiedAccount requiredNeeds API keys

PubMed MCP Server

A Model Context Protocol (MCP) server that provides access to PubMed's E-utilities API for searching and downloading scientific articles. This server enables LLM applications to search PubMed's vast database of biomedical literature and retrieve article metadata, abstracts, and full content.

Features

  • Article Search: Search PubMed database with flexible query terms
  • Article Download: Retrieve full article metadata, abstracts, and available content
  • Batch Operations: Download multiple articles in a single request
  • Article Summaries: Get document summaries with metadata
  • Multiple Formats: Support for XML, JSON, and text output formats
  • Rate Limiting: Automatic rate limiting to respect PubMed API limits
  • Error Handling: Robust error handling for API failures

Search Query Examples

Basic Searches

  • "COVID-19" - Search for COVID-19 articles
  • "machine learning" - Search for machine learning articles
  • "breast cancer" - Search for breast cancer articles

Advanced Searches

  • "COVID-19 AND vaccine" - Articles about COVID-19 vaccines
  • "machine learning AND healthcare" - ML in healthcare
  • "CRISPR[Title]" - CRISPR in article titles only
  • "Nature[Journal]" - Articles from Nature journal
  • "2023[PDAT]" - Articles published in 2023
  • "Smith J[Author]" - Articles by author "Smith J"

Field-Specific Searches

  • [Title] - Search in title only
  • [Author] - Search by author
  • [Journal] - Search by journal name
  • [PDAT] - Search by publication date
  • [MeSH] - Search MeSH terms

Integration with Claude Desktop

If you configured your API key in the .env file during installation:

{
  "mcpServers": {
    "pubmed": {
      "command": "/path/to/pubmed-mcp/venv/bin/python",
      "args": ["/path/to/pubmed-mcp/server.py"]
    }
  }
}

Option 2: Configure in Claude Desktop

Alternatively, you can specify the API key directly in the Claude Desktop configuration:

{
  "mcpServers": {
    "pubmed": {
      "command": "/path/to/pubmed-mcp/venv/bin/python",
      "args": ["/path/to/pubmed-mcp/server.py"],
      "env": {
        "NCBI_API_KEY": "your_api_key_here",
        "NCBI_EMAIL": "your_email@example.com"
      }
    }
  }
}

Recommendation: Use Option 1 (.env file) for better security and easier management.

Note: Make sure to use the full path to the Python executable in the virtual environment (venv/bin/python) to ensure the correct dependencies are available.

Rate Limits

  • Without API key: 3 requests per second
  • With API key: 10 requests per second
  • Batch size limit: 50 articles per batch request

Error Handling

The server provides comprehensive error handling:

  • Invalid PMIDs are automatically cleaned (non-numeric characters removed)
  • Empty queries return descriptive errors
  • API failures are caught and reported
  • Rate limiting prevents API abuse

Development

Project Structure

pubmed-mcp/
โ”œโ”€โ”€ server.py              # Main MCP server implementation
โ”œโ”€โ”€ pubmed_client.py       # PubMed API client wrapper
โ”œโ”€โ”€ requirements.txt       # Python dependencies
โ”œโ”€โ”€ setup.sh              # Automated setup script
โ”œโ”€โ”€ .gitignore            # Git ignore file
โ”œโ”€โ”€ README.md             # This file
โ”œโ”€โ”€ .env.example          # Environment variables template
โ””โ”€โ”€ venv/                 # Virtual environment (created by setup)

Dependencies

  • mcp[cli] - MCP Python SDK
  • requests - HTTP client for PubMed API
  • python-dotenv - Environment variables
  • typing-extensions - Type hints support

Support

For issues with this MCP server, please check:

  1. Your API key and email configuration
  2. Network connectivity to NCBI servers
  3. Rate limiting compliance
  4. Valid PMID formats

For PubMed API documentation, visit: https://www.ncbi.nlm.nih.gov/books/NBK25500/