MCP Simple PubMed

repository·master·Indexed 41 days ago

https://github.com/andybrandt/mcp-simple-pubmed

An MCP (Model Context Protocol) server version 0.1.16 that provides AI assistants with access to PubMed articles via the Entrez API. It enables literature searches, abstract retrieval, and full-text access for open access articles in PubMed Central. The server includes specialized tools for keyword and field-specific searches, as well as prompts for Systematic Review, PICO, and Author searches.

Tokens
4.2K
Snippets
20
Records
25
Agent score
50%

What's inside MCP Simple PubMed

  1. Configure MCP Simple PubMed for Claude Desktop

    master

    To use the server with Claude Desktop, add the following configuration to your claude_desktop_config.json file. Replace the placeholders with your actual email and API key.

    // macOS Configuration
    {
      "mcpServers": {
        "simple-pubmed": {
          "command": "python",
          "args": ["-m", "mcp_simple_pubmed"],
          "env": {
            "PUBMED_EMAIL": "your-email@example.com",
            "PUBMED_API_KEY": "your-api-key" 
          }
        }
      }
    }
  2. Configure MCP Simple PubMed for Claude Desktop (Windows)

    master

    On Windows, you must provide the full path to your Python executable in the command field of your claude_desktop_config.json.

    {
      "mcpServers": {
        "simple-pubmed": {
          "command": "C:\\Users\\YOUR_USERNAME\\AppData\\Local\\Programs\\Python\\Python311\\python.exe",
          "args": [
            "-m",
            "mcp_simple_pubmed"
          ],
          "env": {
            "PUBMED_EMAIL": "your-email@example.com",
            "PUBMED_API_KEY": "your-api-key" 
          }
        }
      }
    }
  3. Configure MCP Simple PubMed environment variables

    master

    The server requires specific environment variables to interact with the NCBI Entrez API.

    • PUBMED_EMAIL: Required. Your email address (required by NCBI).
    • PUBMED_API_KEY: Optional. An API key to increase rate limits from 3 requests/second to 10 requests/second.
  4. Fix macOS SSL Certificate errors

    master

    If you encounter [SSL: CERTIFICATE_VERIFY_FAILED] errors on macOS, you must install the Python certificate bundle. Run the following command in your terminal, replacing 3.13 with your specific Python version:

    /Applications/Python\ 3.13/Install\ Certificates.command

    Note: You must restart Claude Desktop for this change to take effect.

    /Applications/Python\ 3.13/Install\ Certificates.command
  5. Configure PubMed and FullText clients

    master

    The server requires specific environment variables to initialize the PubMedClient and FullTextClient.

    Required Environment Variables:

    • PUBMED_EMAIL: Your email address (required for PubMed API usage).

    Optional Environment Variables:

    • PUBMED_TOOL: The name of the tool (defaults to mcp-simple-pubmed).
    • PUBMED_API_KEY: Your PubMed API key.
  6. Available Tools in MCP Simple PubMed

    master

    The server provides the following tools for interacting with PubMed:

    • Search PubMed: Search using keywords, MeSH terms, author names, date ranges, and Boolean operators.
    • Get Full Text: Downloads full text for open access articles in PubMed Central. Note that the returned full text is an XML-ized version, which provides structural information useful for AI models.
    • Access Abstracts: Retrieves article abstracts and metadata via resource URIs.
  7. Available Prompts in MCP Simple PubMed

    master

    As of v0.1.14, the server includes prompts to help construct optimized PubMed queries:

    • Systematic Review Search: Generates comprehensive strategies using MeSH terms, synonyms, and date filters.
    • PICO Search: Builds clinical question searches using the Population, Intervention, Comparison, Outcome framework.
    • Author Search: Finds all publications by a specific author with proper name formatting.
  8. Use PubMedFetch to retrieve full text articles

    master

    The PubMedFetch class provides a client for retrieving the full text content of PubMed articles by leveraging PubMed Central (PMC).

    To use it, call the asynchronous get_full_text(pmid) method with a valid PubMed ID (PMID). The method follows this logic:

    1. It attempts to find a linked PMC ID via the PubMed database.
    2. If a PMC ID is found, it fetches the article XML from PMC and parses it into a structured text format (Title, Abstract, and Main Text).
    3. If no PMC ID is found but a DOI is present, it returns a message indicating the DOI for publisher access.
    4. If neither is available, it returns a message stating the text is unavailable.

    Note: The method returns the full text as a string on success, or an error message string if the text cannot be retrieved.

    from mcp_simple_pubmed.pubmed_fetch import PubMedFetch
    
    # Note: get_full_text is an async method
    async def fetch_article():
        fetcher = PubMedFetch()
        content = await fetcher.get_full_text("12345678")
        print(content)
  9. Search PubMed articles with `search_pubmed`

    master

    Search PubMed for medical and life sciences research articles using keyword or field-specific queries.

    Search Features:

    • Simple keyword search: "covid vaccine"
    • Field-specific search:
      • Title: [Title]
      • Author: [Author]
      • MeSH terms: [MeSH Terms]
      • Journal: [Journal]
    • Date ranges: Use "2020:2024"[Date - Publication]
    • Boolean operators: Combine terms with AND, OR, NOT
    • Exact phrases: Use quotation marks for multi-word terms.

    Returns: A JSON string containing paper titles, authors, publication details, abstract previews, links to full text, DOIs, and keywords/MeSH terms.

    Constraints: max_results is constrained between 1 and 50.

    # Example usage via tool call
    await search_pubmed(query='"breast cancer"[Title] AND "2023"[Date - Publication]', max_results=10)