Skip to main content
Glama
chrismannina

PubMed MCP Server

by chrismannina

find_related_articles

Discover research articles related to a specific PubMed article by entering its PMID. This tool helps researchers expand their literature review and identify relevant studies.

Instructions

Find articles related to a specific PMID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pmidYesPMID of the reference article
max_resultsNoMaximum number of related articles

Implementation Reference

  • Tool schema definition with input validation for 'pmid' and optional 'max_results'.
    {
        "name": "find_related_articles",
        "description": "Find articles related to a specific PMID",
        "inputSchema": {
            "type": "object",
            "properties": {
                "pmid": {"type": "string", "description": "PMID of the reference article"},
                "max_results": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 50,
                    "default": 10,
                    "description": "Maximum number of related articles",
                },
            },
            "required": ["pmid"],
        },
    },
  • Tool registration in handler_map dictionary mapping 'find_related_articles' to its handler method.
    handler_map = {
        "search_pubmed": self._handle_search_pubmed,
        "get_article_details": self._handle_get_article_details,
        "search_by_author": self._handle_search_by_author,
        "find_related_articles": self._handle_find_related_articles,
        "export_citations": self._handle_export_citations,
        "search_mesh_terms": self._handle_search_mesh_terms,
        "search_by_journal": self._handle_search_by_journal,
        "get_trending_topics": self._handle_get_trending_topics,
        "analyze_research_trends": self._handle_analyze_research_trends,
        "compare_articles": self._handle_compare_articles,
        "get_journal_metrics": self._handle_get_journal_metrics,
        "advanced_search": self._handle_advanced_search,
    }
  • MCP tool handler method that validates input, calls PubMed client, formats response as MCPResponse.
    async def _handle_find_related_articles(self, arguments: Dict[str, Any]) -> MCPResponse:
        """Handle finding related articles."""
        try:
            pmid = arguments.get("pmid", "")
            if not pmid:
                return MCPResponse(
                    content=[{"type": "text", "text": "PMID is required"}], is_error=True
                )
    
            max_results = arguments.get("max_results", 10)
    
            search_result = await self.pubmed_client.find_related_articles(
                pmid=pmid, max_results=max_results, cache=self.cache
            )
    
            content = []
            content.append(
                {
                    "type": "text",
                    "text": f"**Articles Related to PMID: {pmid}**\n\n"
                    f"Found: {search_result.returned_results} related articles\n",
                }
            )
    
            for i, article_data in enumerate(search_result.articles, 1):
                article_text = self._format_article_summary(article_data, i)
                content.append({"type": "text", "text": article_text})
    
            return MCPResponse(content=content)
    
        except Exception as e:
            logger.error(f"Error in find_related_articles: {e}")
            return MCPResponse(
                content=[{"type": "text", "text": f"Error: {str(e)}"}], is_error=True
            )
  • Core implementation using PubMed ELink API to fetch related articles by PMID, with caching and parsing.
    async def find_related_articles(
        self, pmid: str, max_results: int = 10, cache: Optional[CacheManager] = None
    ) -> SearchResult:
        """Find articles related to a specific PMID."""
        start_time = time.time()
    
        if not validate_pmid(pmid):
            raise ValueError(f"Invalid PMID: {pmid}")
    
        if cache:
            cache_key = cache.generate_key("related", pmid=pmid, max_results=max_results)
            cached_result = cache.get(cache_key)
            if cached_result:
                # Convert cached article dicts back to Article objects
                cached_articles = [
                    Article(**article_data) for article_data in cached_result["articles"]
                ]
                cached_result["articles"] = cached_articles
                return SearchResult(**cached_result)
    
        # Use elink to find related articles
        link_params = self._build_params(
            dbfrom="pubmed",
            db="pubmed",
            id=pmid,
            linkname="pubmed_pubmed",
            retmode="json",
        )
    
        link_response = await self._make_request("elink.fcgi", link_params)
        link_data = link_response.json()
    
        related_pmids = []
        linksets = link_data.get("linksets", [])
        if linksets and "linksetdbs" in linksets[0]:
            for linksetdb in linksets[0]["linksetdbs"]:
                if linksetdb.get("linkname") == "pubmed_pubmed":
                    related_pmids = linksetdb.get("links", [])[:max_results]
                    break
    
        articles = []
        if related_pmids:
            articles = await self._fetch_article_details(related_pmids, include_full_details=True)
    
        result_data = {
            "query": f"Related to PMID: {pmid}",
            "total_results": len(related_pmids),
            "returned_results": len(articles),
            "articles": articles,  # Store Article objects directly
            "search_time": time.time() - start_time,
            "suggestions": [],
        }
    
        if cache:
            cache_data = {**result_data, "articles": [article.model_dump() for article in articles]}
            cache.set(cache_key, cache_data)
    
        return SearchResult(**result_data)
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. It states what the tool does but lacks details on permissions, rate limits, return format (e.g., list structure, fields), or error handling. This is inadequate for a tool with no annotation coverage.

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

Conciseness5/5

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

The description is a single, direct sentence with zero waste. It is appropriately sized and front-loaded, efficiently conveying the core purpose without unnecessary elaboration.

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 no annotations and no output schema, the description is incomplete. It does not explain what the tool returns (e.g., article details, relevance scores) or behavioral aspects like performance or limitations. For a tool with this complexity, more context is needed.

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?

The input schema has 100% description coverage, clearly documenting both parameters. The description mentions 'PMID' and implies 'related articles' but adds no additional meaning beyond the schema, such as how relatedness is determined. Baseline 3 is appropriate as 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 verb 'find' and the resource 'articles related to a specific PMID', making the purpose unambiguous. However, it does not explicitly differentiate this tool from sibling tools like 'advanced_search' or 'search_pubmed', which might also retrieve articles, so it misses the highest score for sibling distinction.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. With siblings such as 'advanced_search' and 'search_pubmed' available, it fails to specify scenarios where 'find_related_articles' is preferred, leaving the agent without usage context.

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

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