Skip to main content
Glama

pubmed_articles

Search PubMed's biomedical literature database, retrieve article metadata, and download PDFs for research and analysis.

Instructions

Unified tool for PubMed operations: search biomedical literature, retrieve article metadata, and download PDFs. Access over 35 million citations from the world's largest biomedical database. Use the method parameter to specify the operation type: search with keywords, advanced filtered search, get detailed metadata, or download full-text PDFs when available.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
methodYesThe operation to perform: search_keywords (search with keywords), search_advanced (search with filters), get_article_metadata (get detailed metadata), or get_article_pdf (download full-text PDF)
keywordsNoFor search_keywords: Search query string with keywords, medical terms, drug names, diseases, or any biomedical research terms. Can include multiple terms separated by spaces (implicit AND logic) or use PubMed search operators like OR, AND, NOT.
num_resultsNoFor search methods: Maximum number of results to return (default: 10). Note: PubMed API may have its own limits and may return fewer results than requested.
pmidNoFor get_article_metadata and get_article_pdf: PubMed ID (PMID) of the article - the unique identifier for PubMed articles (e.g., "12345678" or 12345678)
termNoFor search_advanced: General search term for title, abstract, and keywords
titleNoFor search_advanced: Search specifically in article titles
authorNoFor search_advanced: Author name(s) to search for (e.g., "Smith J", "John Smith")
journalNoFor search_advanced: Journal name or abbreviation (e.g., "Nature", "N Engl J Med", "Science")
start_dateNoFor search_advanced: Start date for publication date range in format YYYY/MM/DD (e.g., "2020/01/01")
end_dateNoFor search_advanced: End date for publication date range in format YYYY/MM/DD (e.g., "2024/12/31")

Implementation Reference

  • The main handler for the 'pubmed_articles' tool in the CallToolRequestSchema handler. It checks the tool name, parses arguments, and dispatches to specific helper functions based on the 'method' parameter (search_keywords, search_advanced, get_article_metadata, get_article_pdf).
    server.setRequestHandler(CallToolRequestSchema, async (request) => {
      const { name, arguments: args } = request.params;
    
      if (name !== 'pubmed_articles') {
        throw new Error(`Unknown tool: ${name}`);
      }
    
      try {
        const { method, ...params } = args;
    
        switch (method) {
          case 'search_keywords': {
            const { keywords, num_results = 10 } = params;
            if (!keywords) {
              throw new Error('keywords parameter is required for search_keywords');
            }
            
            const results = await searchKeywords(keywords, num_results);
            return {
              content: [
                {
                  type: 'text',
                  text: JSON.stringify(results, null, 2)
                }
              ]
            };
          }
    
          case 'search_advanced': {
            const { num_results = 10, ...searchParams } = params;
            const advancedParams = { 
              method,
              num_results,
              ...searchParams 
            };
            
            const results = await searchAdvanced(advancedParams);
            return {
              content: [
                {
                  type: 'text',
                  text: JSON.stringify(results, null, 2)
                }
              ]
            };
          }
    
          case 'get_article_metadata': {
            const { pmid } = params;
            if (!pmid) {
              throw new Error('pmid parameter is required for get_article_metadata');
            }
            
            const result = await getArticleMetadata(pmid);
            return {
              content: [
                {
                  type: 'text',
                  text: JSON.stringify(result, null, 2)
                }
              ]
            };
          }
    
          case 'get_article_pdf': {
            const { pmid } = params;
            if (!pmid) {
              throw new Error('pmid parameter is required for get_article_pdf');
            }
            
            const result = await downloadFullTextPdf(pmid);
            return {
              content: [
                {
                  type: 'text',
                  text: JSON.stringify(result, null, 2)
                }
              ]
            };
          }
    
          default:
            throw new Error(`Unknown method: ${method}`);
        }
      } catch (error) {
        const errorMessage = error instanceof Error ? error.message : String(error);
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify({ error: errorMessage }, null, 2)
            }
          ]
        };
      }
    });
  • Input schema definition for the 'pubmed_articles' tool, specifying parameters like method, keywords, pmid, etc., with descriptions and validation rules.
    inputSchema: {
      type: 'object',
      properties: {
        method: {
          type: 'string',
          enum: ['search_keywords', 'search_advanced', 'get_article_metadata', 'get_article_pdf'],
          description: 'The operation to perform: search_keywords (search with keywords), search_advanced (search with filters), get_article_metadata (get detailed metadata), or get_article_pdf (download full-text PDF)'
        },
        keywords: {
          type: 'string',
          description: 'For search_keywords: Search query string with keywords, medical terms, drug names, diseases, or any biomedical research terms. Can include multiple terms separated by spaces (implicit AND logic) or use PubMed search operators like OR, AND, NOT.'
        },
        num_results: {
          type: 'integer',
          default: 10,
          minimum: 1,
          description: 'For search methods: Maximum number of results to return (default: 10). Note: PubMed API may have its own limits and may return fewer results than requested.'
        },
        pmid: {
          oneOf: [
            { type: 'string' },
            { type: 'integer' }
          ],
          description: 'For get_article_metadata and get_article_pdf: PubMed ID (PMID) of the article - the unique identifier for PubMed articles (e.g., "12345678" or 12345678)'
        },
        term: {
          type: 'string',
          description: 'For search_advanced: General search term for title, abstract, and keywords'
        },
        title: {
          type: 'string', 
          description: 'For search_advanced: Search specifically in article titles'
        },
        author: {
          type: 'string',
          description: 'For search_advanced: Author name(s) to search for (e.g., "Smith J", "John Smith")'
        },
        journal: {
          type: 'string',
          description: 'For search_advanced: Journal name or abbreviation (e.g., "Nature", "N Engl J Med", "Science")'
        },
        start_date: {
          type: 'string',
          description: 'For search_advanced: Start date for publication date range in format YYYY/MM/DD (e.g., "2020/01/01")'
        },
        end_date: {
          type: 'string',
          description: 'For search_advanced: End date for publication date range in format YYYY/MM/DD (e.g., "2024/12/31")'
        }
      },
      required: ['method'],
      additionalProperties: false
    }
  • src/index.js:24-86 (registration)
    Registers the 'pubmed_articles' tool in the MCP server by returning it in the ListToolsRequestSchema handler.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: [
          {
            name: 'pubmed_articles',
            description: 'Unified tool for PubMed operations: search biomedical literature, retrieve article metadata, and download PDFs. Access over 35 million citations from the world\'s largest biomedical database. Use the method parameter to specify the operation type: search with keywords, advanced filtered search, get detailed metadata, or download full-text PDFs when available.',
            inputSchema: {
              type: 'object',
              properties: {
                method: {
                  type: 'string',
                  enum: ['search_keywords', 'search_advanced', 'get_article_metadata', 'get_article_pdf'],
                  description: 'The operation to perform: search_keywords (search with keywords), search_advanced (search with filters), get_article_metadata (get detailed metadata), or get_article_pdf (download full-text PDF)'
                },
                keywords: {
                  type: 'string',
                  description: 'For search_keywords: Search query string with keywords, medical terms, drug names, diseases, or any biomedical research terms. Can include multiple terms separated by spaces (implicit AND logic) or use PubMed search operators like OR, AND, NOT.'
                },
                num_results: {
                  type: 'integer',
                  default: 10,
                  minimum: 1,
                  description: 'For search methods: Maximum number of results to return (default: 10). Note: PubMed API may have its own limits and may return fewer results than requested.'
                },
                pmid: {
                  oneOf: [
                    { type: 'string' },
                    { type: 'integer' }
                  ],
                  description: 'For get_article_metadata and get_article_pdf: PubMed ID (PMID) of the article - the unique identifier for PubMed articles (e.g., "12345678" or 12345678)'
                },
                term: {
                  type: 'string',
                  description: 'For search_advanced: General search term for title, abstract, and keywords'
                },
                title: {
                  type: 'string', 
                  description: 'For search_advanced: Search specifically in article titles'
                },
                author: {
                  type: 'string',
                  description: 'For search_advanced: Author name(s) to search for (e.g., "Smith J", "John Smith")'
                },
                journal: {
                  type: 'string',
                  description: 'For search_advanced: Journal name or abbreviation (e.g., "Nature", "N Engl J Med", "Science")'
                },
                start_date: {
                  type: 'string',
                  description: 'For search_advanced: Start date for publication date range in format YYYY/MM/DD (e.g., "2020/01/01")'
                },
                end_date: {
                  type: 'string',
                  description: 'For search_advanced: End date for publication date range in format YYYY/MM/DD (e.g., "2024/12/31")'
                }
              },
              required: ['method'],
              additionalProperties: false
            }
          }
        ]
      };
    });
  • Helper function searchKeywords: performs keyword-based PubMed search, fetches PMIDs, retrieves metadata for each, and returns article list. Called by handler for 'search_keywords' method.
    async function searchKeywords(keywords, numResults = 10) {
      console.log(`Generated search URL for keywords: ${keywords}`);
      
      const searchUrl = generatePubMedSearchUrl(keywords, numResults);
      const pmids = await searchPubMed(searchUrl);
      
      const articles = [];
      for (const pmid of pmids) {
        const metadata = await getPubMedMetadata(pmid);
        if (metadata) {
          articles.push(metadata);
        }
      }
      
      return articles;
    }
  • Core helper getPubMedMetadata: fetches and parses PubMed article XML via EFetch API, extracts comprehensive metadata including title, authors, abstract, DOI, etc. Used by search functions and getArticleMetadata.
    async function getPubMedMetadata(pmid) {
      try {
        const url = `https://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=pubmed&id=${pmid}&retmode=xml`;
        
        const response = await axios.get(url, {
          timeout: 30000,
          headers: {
            'User-Agent': 'PubMed-MCP-Server/1.0.0 (uh-joan@github.com)'
          }
        });
    
        const result = await parseXML(response.data);
        const article = result?.PubmedArticleSet?.PubmedArticle?.[0];
    
        if (!article) return null;
    
        const medlineCitation = article.MedlineCitation?.[0];
        const pubmedData = article.PubmedData?.[0];
    
        if (!medlineCitation) return null;
    
        const title = medlineCitation.Article?.[0]?.ArticleTitle?.[0] || 'No title available';
        const journal = medlineCitation.Article?.[0]?.Journal?.[0]?.Title?.[0] || 'Unknown journal';
    
        const authors = [];
        const authorList = medlineCitation.Article?.[0]?.AuthorList?.[0]?.Author;
        if (authorList) {
          for (const author of authorList) {
            const lastName = author.LastName?.[0] || '';
            const foreName = author.ForeName?.[0] || '';
            if (lastName) {
              authors.push(`${lastName}, ${foreName}`.trim());
            }
          }
        }
    
        let publicationDate = 'Unknown date';
        const pubDate = medlineCitation.Article?.[0]?.Journal?.[0]?.JournalIssue?.[0]?.PubDate?.[0];
        if (pubDate) {
          const year = pubDate.Year?.[0] || '';
          const month = pubDate.Month?.[0] || '';
          const day = pubDate.Day?.[0] || '';
          publicationDate = [year, month, day].filter(Boolean).join('-');
        }
    
        const abstractTexts = medlineCitation.Article?.[0]?.Abstract?.[0]?.AbstractText;
        let abstract = '';
        if (abstractTexts) {
          abstract = abstractTexts.map(text => {
            if (typeof text === 'string') return text;
            if (text._) return text._;
            return '';
          }).join(' ');
        }
    
        let doi = '';
        const articleIds = pubmedData?.ArticleIdList?.[0]?.ArticleId;
        if (articleIds) {
          for (const id of articleIds) {
            if (id.$ && id.$.IdType === 'doi') {
              doi = id._;
              break;
            }
          }
        }
    
        let pmcid = '';
        if (articleIds) {
          for (const id of articleIds) {
            if (id.$ && id.$.IdType === 'pmc') {
              pmcid = id._;
              break;
            }
          }
        }
    
        const meshTerms = [];
        const meshHeadingList = medlineCitation.MeshHeadingList?.[0]?.MeshHeading;
        if (meshHeadingList) {
          for (const heading of meshHeadingList) {
            const descriptorName = heading.DescriptorName?.[0]?._;
            if (descriptorName) {
              meshTerms.push(descriptorName);
            }
          }
        }
    
        const keywords = [];
        const keywordList = medlineCitation.KeywordList?.[0]?.Keyword;
        if (keywordList) {
          for (const keyword of keywordList) {
            if (typeof keyword === 'string') {
              keywords.push(keyword);
            } else if (keyword._) {
              keywords.push(keyword._);
            }
          }
        }
    
        return {
          pmid,
          title,
          authors,
          journal,
          publication_date: publicationDate,
          abstract,
          doi,
          pmcid,
          keywords,
          mesh_terms: meshTerms,
          url: `https://pubmed.ncbi.nlm.nih.gov/${pmid}/`
        };
    
      } catch (error) {
        console.error(`Error fetching metadata for PMID ${pmid}:`, error.message);
        return null;
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. While it mentions accessing 'over 35 million citations' and downloading PDFs 'when available,' it lacks critical behavioral information such as rate limits, authentication requirements, error conditions, response formats, or whether operations are read-only or mutative. For a tool with 10 parameters and no annotations, this is a significant gap.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized with three sentences that are front-loaded: it starts with the unified purpose, adds context about the database, and ends with usage instructions. There's minimal waste, though the second sentence about '35 million citations' could be considered slightly extraneous. Overall, it's efficient and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (10 parameters, multiple operations) and lack of both annotations and an output schema, the description is incomplete. It doesn't explain what the tool returns (e.g., search results format, metadata structure, PDF handling), behavioral constraints, or error scenarios. For a multi-function tool with no structured output documentation, the description should provide more operational context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds some value by mentioning the 'method parameter' and listing the four operation types, but it doesn't provide additional semantic context beyond what's in the schema descriptions. The baseline of 3 is appropriate when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose as a 'unified tool for PubMed operations' that can 'search biomedical literature, retrieve article metadata, and download PDFs.' It specifies the resource ('PubMed articles') and multiple verbs, but since there are no sibling tools, it doesn't need to differentiate from alternatives. The description goes beyond a tautology by explaining the scope and database size.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides implied usage guidance by stating 'Use the method parameter to specify the operation type' and listing the four available methods. However, it doesn't explicitly state when to choose one method over another (e.g., when to use search_keywords vs search_advanced) or mention any prerequisites or constraints. With no sibling tools, alternative guidance isn't needed.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/openpharma-org/pubmed-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server