Skip to main content
Glama

search_pubmed

Retrieve relevant PubMed article abstracts by entering a search query and specifying the maximum number of results. Simplify biomedical research with structured, easy-to-read outputs.

Instructions

Search PubMed for articles matching the query. Args: query: The search term for PubMed. max_results: Maximum number of articles to retrieve. Returns: A string containing the abstracts of found articles, separated by two newlines.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
max_resultsNo
queryNoendocarditis

Implementation Reference

  • The main handler function for the 'search_pubmed' tool. It uses asyncio.to_thread to call the blocking fetch_pubmed_articles helper and formats the results as a string.
    @mcp.tool() async def search_pubmed(query: str = "endocarditis", max_results: int = 10) -> str: """ Search PubMed for articles matching the query. Args: query: The search term for PubMed. max_results: Maximum number of articles to retrieve. Returns: A string containing the abstracts of found articles, separated by two newlines. """ # Run the blocking function in a separate thread articles = await asyncio.to_thread(fetch_pubmed_articles, query, max_results) if articles: return "\n\n".join(articles) else: return "No articles found for the given query."
  • Helper function that performs the actual PubMed search using Bio.Entrez, fetching abstracts for the top results.
    def fetch_pubmed_articles(query: str = "endocarditis", max_results: int = 20) -> list[str]: """Fetch PubMed articles for the given query without saving to a file.""" handle = Entrez.esearch(db="pubmed", term=query, retmax=max_results) record = Entrez.read(handle) handle.close() ids = record.get('IdList', []) articles = [] for pmid in ids: time.sleep(0.5) # Delay to avoid overwhelming the API try: handle = Entrez.efetch(db="pubmed", id=pmid, rettype="abstract", retmode="text") abstract = handle.read() handle.close() if abstract: articles.append(abstract.strip()) except Exception: continue return articles
  • The @mcp.tool() decorator registers the search_pubmed function as an MCP tool.
    @mcp.tool()
  • Function signature and docstring define the input schema (query: str, max_results: int) and output (str).
    async def search_pubmed(query: str = "endocarditis", max_results: int = 10) -> str: """ Search PubMed for articles matching the query. Args: query: The search term for PubMed. max_results: Maximum number of articles to retrieve. Returns: A string containing the abstracts of found articles, separated by two newlines. """

Other Tools

Related 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/AIAnytime/Awesome-MCP-Server'

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