Skip to main content
Glama

get_article

Retrieve complete metadata for PubMed articles using PMIDs to access titles, authors, abstracts, and publication details for biomedical research.

Instructions

Get complete details of a PubMed article by its PMID.

Args: pmid: The PubMed ID (numeric string), e.g. "33982811".

Returns: Full article metadata: title, all authors, journal, date, DOI, PMC link, publication types, full abstract, keywords, MeSH terms. Returns an error message if the PMID is invalid or not found.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pmidYes

Implementation Reference

  • main.py:374-442 (handler)
    Implementation of the `get_article` tool handler using the FastMCP decorator. It takes a PMID as input, queries the NCBI E-utilities API, and formats the response.
    @mcp.tool()
    async def get_article(pmid: str) -> str:
        """Get complete details of a PubMed article by its PMID.
    
        Args:
            pmid: The PubMed ID (numeric string), e.g. "33982811".
    
        Returns:
            Full article metadata: title, all authors, journal, date, DOI,
            PMC link, publication types, full abstract, keywords, MeSH terms.
            Returns an error message if the PMID is invalid or not found.
        """
        pmid = pmid.strip()
        if not pmid.isdigit():
            return _err(f"Invalid PMID: {pmid!r}. A PMID must be a numeric string.")
    
        try:
            fetch_resp = await _get(
                "efetch.fcgi",
                {"db": "pubmed", "id": pmid, "retmode": "xml", "rettype": "abstract"},
            )
            root = _require_xml(fetch_resp, f"efetch PMID {pmid}")
            article_xml = root.find(".//PubmedArticle")
    
            if article_xml is None:
                return _err(f"No article found for PMID {pmid}. It may not exist or may have been retracted.")
    
            art = _parse_article(article_xml)
    
            lines = [f"=== PubMed Article — PMID {pmid} ==="]
            lines.append(f"Title    : {art.get('title', 'N/A')}")
    
            authors = art.get("authors", [])
            if authors:
                lines.append(f"Authors  : {', '.join(authors)}")
    
            lines.append(f"Journal  : {art.get('journal', 'N/A')}")
            lines.append(f"Published: {art.get('pub_date', 'N/A')}")
    
            if "doi" in art:
                lines.append(f"DOI      : {art['doi']}")
                lines.append(f"DOI URL  : https://doi.org/{art['doi']}")
    
            if "pmc_id" in art:
                pmc_id = art["pmc_id"]
                lines.append(f"PMC ID   : {pmc_id}")
                lines.append(f"PMC URL  : https://www.ncbi.nlm.nih.gov/pmc/articles/{pmc_id}/")
    
            lines.append(f"PubMed   : https://pubmed.ncbi.nlm.nih.gov/{pmid}/")
    
            if "publication_types" in art:
                lines.append(f"Type(s)  : {', '.join(art['publication_types'])}")
    
            if "abstract" in art:
                lines.append(f"\nAbstract:\n{art['abstract']}")
            else:
                lines.append("\nAbstract: Not available.")
    
            if "keywords" in art:
                lines.append(f"\nKeywords : {', '.join(art['keywords'])}")
    
            if "mesh_terms" in art:
                lines.append(f"\nMeSH     : {', '.join(art['mesh_terms'])}")
    
            return "\n".join(lines)
    
        except PubMedError as exc:
            return _err(str(exc))

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/benoitleq/mcp-pubmed'

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