PubMed MCP server

Integrates with NCBI PubMed to provide literature search, article retrieval, author-based searches, citation formatting in multiple styles, and research trend analysis for academic and bibliographic research workflows.
Back to servers
Setup instructions
Provider
Chris Mannina
Release date
Jun 04, 2025
Language
Python
Stats
6 stars

The PubMed MCP server provides advanced capabilities for PubMed literature search and management through the Model Context Protocol. It offers comprehensive search functionality, citation formatting, and research analysis tools to streamline your scientific literature workflow.

Installation

Prerequisites

  • Python 3.8 or higher
  • NCBI API key (free registration required)
  • Valid email address for NCBI API identification

Quick Start

  1. Clone the repository:

    git clone https://github.com/your-org/pubmed-mcp.git
    cd pubmed-mcp
    
  2. Install dependencies:

    pip install -r requirements.txt
    
  3. Set up environment variables:

    cp env.example .env
    # Edit .env with your NCBI API key and email
    
  4. Run the server:

    python -m src.main
    

Configuration

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

Getting an NCBI API Key

  1. Visit NCBI Account Settings
  2. Sign in or create an account
  3. Navigate to "API Key Management"
  4. Create a new API key
  5. Copy the key to your .env file

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())

Docker Usage

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

Search Parameters

  • query: Search query using PubMed syntax
  • max_results: Maximum number of results (1-200)
  • sort_order: Sort order (relevance, pub_date, author, journal, title)
  • date_from/date_to: Date range filters
  • date_range: Predefined ranges (1y, 5y, 10y, all)
  • article_types: Filter by publication types
  • authors: Filter by author names
  • journals: Filter by journal names
  • mesh_terms: Filter by MeSH terms
  • language: Language filter (e.g., 'eng', 'fre')
  • has_abstract: Only articles with abstracts
  • has_full_text: Only articles with full text
  • humans_only: Only human studies

Citation Formats

  • bibtex: BibTeX format
  • apa: APA style
  • mla: MLA style
  • chicago: Chicago style
  • vancouver: Vancouver style
  • endnote: EndNote format
  • ris: RIS format

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "pubmed" '{"command":"python","args":["-m","src.main"]}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "pubmed": {
            "command": "python",
            "args": [
                "-m",
                "src.main"
            ]
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "pubmed": {
            "command": "python",
            "args": [
                "-m",
                "src.main"
            ]
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later