get_related_articles
Find related biomedical articles in PubMed using NCBI's co-citation and text similarity algorithm. Input a PubMed ID to discover relevant research articles with brief metadata.
Instructions
Find PubMed articles related to a given article.
Uses NCBI's "similar articles" algorithm (co-citation and text similarity).
Args: pmid: The PubMed ID of the reference article. max_results: Number of related articles to return (1-50, default 10).
Returns: A ranked list of related articles with brief metadata. Returns an error message if the PMID is invalid or not found.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pmid | Yes | ||
| max_results | No |
Implementation Reference
- main.py:542-585 (handler)The get_related_articles tool handler implementation. It uses NCBI's elink API to fetch similar articles.
@mcp.tool() async def get_related_articles(pmid: str, max_results: int = 10) -> str: """Find PubMed articles related to a given article. Uses NCBI's "similar articles" algorithm (co-citation and text similarity). Args: pmid: The PubMed ID of the reference article. max_results: Number of related articles to return (1-50, default 10). Returns: A ranked list of related articles with brief metadata. 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.") max_results = max(1, min(max_results, 50)) try: link_resp = await _get( "elink.fcgi", { "dbfrom": "pubmed", "db": "pubmed", "id": pmid, "cmd": "neighbor_score", "retmode": "json", }, ) link_data = link_resp.json() related_pmids: list[str] = [] try: for linkset in link_data.get("linksets", []): for lsdb in linkset.get("linksetdbs", []): if lsdb.get("linkname") == "pubmed_pubmed": related_pmids = [ str(lid) for lid in lsdb.get("links", []) if str(lid) != pmid ][:max_results]