bc_get_europepmc_articles
Retrieve scientific articles from Europe PMC by querying titles, abstracts, authors, or general terms. Use 'recent' for current research or 'cited' for established topics. Supports 'and' or 'or' search types for precise results.
Instructions
Query the Europe PMC database for scientific articles.
Use 'recent' sort for current research queries and 'cited' sort for comprehensive career overviews or well-established topics (e.g., "what has author X published on in their career").
Provide at least one of the following search parameters:
query: General search query string
title: Search term for article titles
abstract: Search term for article abstracts.
author: Author name (e.g., "last_name,first_name"). Should not contain spaces. These will be combined with the specified search type ("and" or "or"). For a broad search, prefer the "query" parameter and "or" search type. Only use the "and" search type if you want to ensure all terms must match.
Args: query (str, optional): General search query string. title (str, optional): Search term for article titles. abstract (str, optional): Search term for article abstracts. author (str, optional): Author name (e.g., "last_name,first_name"). Should not contain spaces. search_type (str): Search type - "and" or "or" (default: "or"). sort_by (str): Sort by - "recent" for most recent, "cited" for most cited or None for no specific sorting (default: None). page_size (int): Number of results to return (default: 25, max: 1000).
Returns: dict: Article search results or error message
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| abstract | No | Search term for article abstracts | |
| author | No | Author name (e.g., 'kuehl,malte') | |
| page_size | No | Number of results to return | |
| query | No | Search query string, not specific to any field | |
| search_type | No | Search type: 'and' or 'or' | or |
| sort_by | No | Sort by: 'recent' for most recent, 'cited' for most cited or None for no specific sorting | |
| title | No | Search term for article titles |
Implementation Reference
- The core handler function for the EuropePMC articles tool. It defines the input schema via Annotated Fields and implements the search logic by constructing a query for the Europe PMC REST API, fetching results, and handling errors.@core_mcp.tool() def get_europepmc_articles( query: Annotated[Optional[str], Field(description="General search query")] = None, title: Annotated[Optional[str], Field(description="Search in article titles")] = None, abstract: Annotated[Optional[str], Field(description="Search in abstracts")] = None, author: Annotated[Optional[str], Field(description="Author name (e.g., 'lastname,firstname')")] = None, search_type: Annotated[str, Field(description="'and' or 'or' (default: 'or')")] = "or", sort_by: Annotated[ Optional[str], Field(description="'recent' or 'cited' (default: none)"), ] = None, page_size: Annotated[int, Field(description="Results per page (1-1000)", ge=1, le=1000)] = 25, ) -> dict: """Search Europe PMC articles by query, title, abstract, or author. Combine search terms with 'and'/'or' logic. Returns: dict: Search results with resultList containing articles (title, authors, abstract, journal, PMC/DOI IDs) or error message. """ # Ensure at least one search parameter was provided if not any([query, title, abstract, author]): return {"error": "At least one of query, title, abstract, or author must be provided"} # Build query components query_parts = [] if query: query_parts.append(query) if title: query_parts.append(f"title:{title}") if abstract: query_parts.append(f"abstract:{abstract}") if author: query_parts.append(f"auth:{author}") # Join query parts based on search type query = " AND ".join(query_parts) if search_type.lower() == "and" else " OR ".join(query_parts) # If multiple parts and not explicitly AND, wrap in parentheses for OR if len(query_parts) > 1 and search_type.lower() == "or": query = f"({query})" # Add sort parameter if sort_by is not None: if sort_by.lower() == "cited": query += " sort_cited:y" else: # default to recent query += " sort_date:y" # URL encode the query encoded_query = quote(query) url = f"https://www.ebi.ac.uk/europepmc/webservices/rest/search?query={encoded_query}&format=json&resultType=core&pageSize={page_size}" try: response = requests.get(url) response.raise_for_status() return response.json() except requests.exceptions.RequestException as e: return {"error": f"Failed to fetch Europe PMC articles: {e!s}"}
- src/biocontext_kb/core/_server.py:1-7 (registration)Creation of the FastMCP server instance named "BC" (likely prefixing tools as bc_get_*) to which all tools are registered via decorators.from fastmcp import FastMCP core_mcp = FastMCP( # type: ignore "BC", instructions="Provides access to biomedical knowledge bases.", )
- src/biocontext_kb/core/__init__.py:9-9 (registration)Import of europepmc tools module, which triggers registration of get_europepmc_articles on the core_mcp server due to the @core_mcp.tool() decorator.from .europepmc import *
- Module __init__.py that re-exports the get_europepmc_articles function for easy import and registration."""Europe PMC API utilities.""" from ._get_europepmc_articles import get_europepmc_articles from ._get_europepmc_fulltext import get_europepmc_fulltext __all__ = ["get_europepmc_articles", "get_europepmc_fulltext"]