search_pubmed
Retrieve PMIDs and titles from PubMed by searching with keyword, MeSH term, or author. Control the number of results returned.
Instructions
Search PubMed by keyword, MeSH term, or author. Returns PMIDs and titles.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | ||
| max_results | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- server.py:9-26 (handler)The main handler for the 'search_pubmed' tool. Searches PubMed via E-utilities (esearch + esummary), returns PMIDs and titles.
async def search_pubmed(query: str, max_results: int = 10) -> str: """Search PubMed by keyword, MeSH term, or author. Returns PMIDs and titles.""" async with httpx.AsyncClient() as client: r = await client.get(f"{PUBMED_BASE}/esearch.fcgi", params={ "db": "pubmed", "term": query, "retmax": max_results, "retmode": "json" }) data = r.json() ids = data["esearchresult"]["idlist"] r2 = await client.get(f"{PUBMED_BASE}/esummary.fcgi", params={ "db": "pubmed", "id": ",".join(ids), "retmode": "json" }) summaries = r2.json()["result"] results = [] for pmid in ids: title = summaries[pmid]["title"] results.append(f"PMID {pmid}: {title}") return "\n".join(results) - server.py:8-8 (registration)Registration of 'search_pubmed' as an MCP tool via @mcp.tool() decorator.
@mcp.tool() - server.py:60-64 (helper)The 'find_reviews' tool reuses search_pubmed by appending a systematic review / meta-analysis filter to the query.
async def find_reviews(query: str, max_results: int = 10) -> str: """Search PubMed for systematic reviews and meta-analyses only.""" return await search_pubmed( f"{query} AND (systematic review[pt] OR meta-analysis[pt])", max_results )