PubMed MCP Server

PubMed MCP Server

Enables searching PubMed's biomedical literature database and retrieving article metadata, abstracts, and full content through the E-utilities API. Supports advanced queries, batch operations, and multiple output formats with automatic rate limiting.

Category
访问服务器

README

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

Installation

Quick Setup (Recommended)

  1. Clone or download this repository
  2. Run the setup script:
    ./setup.sh
    
    This will create a virtual environment, install dependencies, and provide next steps.

Manual Setup

  1. Clone or download this repository
  2. Create and activate virtual environment:
    python3 -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
    
  3. Install dependencies:
    pip install -r requirements.txt
    
  4. Configure environment (optional but recommended):
    cp .env.example .env
    # Edit .env file with your NCBI API key and email
    

Configuration

Environment Variables

Create a .env file with the following optional configuration:

  • NCBI_API_KEY: Your NCBI API key (increases rate limit from 3 to 10 requests/second)
  • NCBI_EMAIL: Your email address (recommended by NCBI for API usage tracking)

Get your free NCBI API key at: https://www.ncbi.nlm.nih.gov/account/settings/

Usage

Running the Server

  1. Activate the virtual environment (if not already active):

    source venv/bin/activate  # On Windows: venv\Scripts\activate
    
  2. Run the server:

    python server.py
    

The server will start and listen for MCP connections via stdio.

  1. To deactivate the virtual environment when done:
    deactivate
    

Available Tools

1. search_articles

Search PubMed for articles matching a query.

Parameters:

  • query (string, required): Search query (e.g., "COVID-19 vaccines", "machine learning AND healthcare")
  • max_results (int, optional): Maximum results to return (default: 20, max: 200)
  • sort (string, optional): Sort order - "relevance", "pub_date", or "first_author" (default: "relevance")

Returns:

  • pmids: List of PubMed IDs
  • total_count: Total number of matching articles
  • query_used: The search query executed
  • results_returned: Number of results returned
  • sort_order: Sort order used

Example:

{
  "query": "CRISPR gene editing",
  "max_results": 10,
  "sort": "pub_date"
}

2. download_article

Download article details by PubMed ID.

Parameters:

  • pmid (string, required): PubMed ID (e.g., "33073741")
  • format_type (string, optional): Content format - "abstract", "medline", or "full" (default: "abstract")
  • return_mode (string, optional): Return format - "xml", "text", or "json" (default: "xml")

Returns:

  • pmid: The PubMed ID
  • content: Article content in requested format
  • format_type: Format type used
  • return_mode: Return mode used
  • content_length: Length of content

3. download_articles_batch

Download multiple articles in a single request.

Parameters:

  • pmids (list, required): List of PubMed IDs
  • format_type (string, optional): Content format (default: "abstract")
  • return_mode (string, optional): Return format (default: "xml")

Returns:

  • pmids: List of requested PMIDs
  • content: Combined article content
  • article_count: Number of articles requested
  • content_length: Length of content

4. get_article_summaries

Get document summaries for articles (metadata without full content).

Parameters:

  • pmids (list, required): List of PubMed IDs

Returns:

  • pmids: List of requested PMIDs
  • summaries: XML summary data
  • article_count: Number of articles requested

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

Option 1: Using .env file (Recommended)

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

License

This project is open source. Please check PubMed's terms of service for API usage guidelines.

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/

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
mcp-server-qdrant

mcp-server-qdrant

这个仓库展示了如何为向量搜索引擎 Qdrant 创建一个 MCP (Managed Control Plane) 服务器的示例。

官方
精选
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选