Source code for tooluniverse.pmc_tool

#!/usr/bin/env python3
"""
PMC (PubMed Central) Tool for searching full-text biomedical literature.

PMC is the free full-text archive of biomedical and life sciences journal
literature at the U.S. National Institutes of Health's National Library of
Medicine. This tool provides access to millions of full-text articles.
"""

import requests
from typing import Dict, List, Any, Optional
from .base_tool import BaseTool
from .tool_registry import register_tool


[docs] @register_tool("PMCTool") class PMCTool(BaseTool): """Tool for searching PMC full-text biomedical literature."""
[docs] def __init__(self, tool_config=None): super().__init__(tool_config) self.base_url = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils" self.session = requests.Session() self.session.headers.update( {"User-Agent": "ToolUniverse/1.0", "Accept": "application/json"} )
[docs] def _extract_authors(self, authors: List[Dict]) -> List[str]: """Extract author names from PMC API response.""" if not authors: return [] author_names = [] for author in authors: name = author.get("name", "") if name: author_names.append(name) return author_names
[docs] def _extract_year(self, pubdate: str) -> str: """Extract year from publication date.""" if not pubdate: return "Unknown" try: # PMC API returns dates in various formats # Extract year from the beginning of the string return pubdate[:4] except Exception: return "Unknown"
[docs] def run(self, tool_arguments) -> List[Dict[str, Any]]: """ Execute the PMC search. Args: tool_arguments: Dictionary containing search parameters Returns: List of paper dictionaries """ query = tool_arguments.get("query", "") if not query: return [{"error": "Query parameter is required"}] limit = tool_arguments.get("limit", 10) date_from = tool_arguments.get("date_from") date_to = tool_arguments.get("date_to") article_type = tool_arguments.get("article_type") return self._search( query=query, limit=limit, date_from=date_from, date_to=date_to, article_type=article_type, )