bc_get_europepmc_articles
Search biomedical literature in Europe PMC by query, title, abstract, or author using logical operators to find relevant scientific articles with metadata.
Instructions
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.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | No | General search query | |
| title | No | Search in article titles | |
| abstract | No | Search in abstracts | |
| author | No | Author name (e.g., 'lastname,firstname') | |
| search_type | No | 'and' or 'or' (default: 'or') | or |
| sort_by | No | 'recent' or 'cited' (default: none) | |
| page_size | No | Results per page (1-1000) |
Implementation Reference
- The main handler function that implements the logic to search and retrieve articles from Europe PMC using their REST API. Decorated with @core_mcp.tool() to register it as an MCP tool named 'get_europepmc_articles'.@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/app.py:35-40 (registration)Registers the core_mcp server (containing the get_europepmc_articles tool) into the main MCP app with a prefix 'bc' (slugify('BC')), making the tool available as 'bc_get_europepmc_articles'.for mcp in [core_mcp, *(await get_openapi_mcps())]: await mcp_app.import_server( mcp, slugify(mcp.name), ) logger.info("MCP server setup complete.")
- src/biocontext_kb/core/__init__.py:9-9 (registration)Imports all tools from the europepmc module, which triggers the execution of decorators and registers get_europepmc_articles on core_mcp.from .europepmc import *
- Pydantic schema defined via Annotated type hints and Field descriptions for input parameters and return type.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:
- src/biocontext_kb/core/europepmc/__init__.py:3-3 (registration)Imports the get_europepmc_articles function into the europepmc package namespace.from ._get_europepmc_articles import get_europepmc_articles