tooluniverse.europe_pmc_tool module¶

tooluniverse.europe_pmc_tool._normalize_pmcid(pmcid)[source]¶

Return (pmcid_norm, pmcid_digits).

pmcid_norm: “PMC123” form (or None) pmcid_digits: “123” digits only (or None)

tooluniverse.europe_pmc_tool._build_ncbi_pmc_oai_url(pmcid_digits)[source]¶
tooluniverse.europe_pmc_tool._build_ncbi_pmc_efetch_url(pmcid_digits)[source]¶
tooluniverse.europe_pmc_tool._build_ncbi_pmc_html_url(pmcid_norm)[source]¶
tooluniverse.europe_pmc_tool._extract_text_from_html(html_text)[source]¶

Best-effort HTML -> text extraction.

For PMC pages, try to restrict to the main content region to avoid nav/JS/CSS noise.

tooluniverse.europe_pmc_tool._extract_abstract_from_pmc_html(html_text)[source]¶
tooluniverse.europe_pmc_tool._detect_ncbi_oai_error(xml_text)[source]¶
NCBI PMC OAI-PMH often returns HTTP 200 even for logical errors, e.g.:

<error code=”cannotDisseminateFormat”>…</error>

Returns a small structured dict when an error is detected, else None.

tooluniverse.europe_pmc_tool._fetch_fulltext_with_trace(session, *, europe_fulltext_xml_url, pmcid, timeout=20)[source]¶

Fetch full text content with a trace of attempts.

Returns:

{

ok: bool, url: str|None, source: str|None, format: “xml”|”html”|None, content_type: str|None, status_code: int|None, content: str|None, trace: list[dict],

}

Return type:

dict

class tooluniverse.europe_pmc_tool.EuropePMCTool[source]¶

Bases: BaseTool

Tool to search for articles on Europe PMC including abstracts.

__init__(tool_config, base_url='https://www.ebi.ac.uk/europepmc/webservices/rest/search')[source]¶
run(arguments)[source]¶

Execute the tool.

The default BaseTool implementation accepts an optional arguments mapping to align with most concrete tool implementations which expect a dictionary of inputs.

Parameters:
  • arguments (dict, optional) – Tool-specific arguments

  • stream_callback (callable, optional) – Callback for streaming responses

  • use_cache (bool, optional) – Whether result caching is enabled

  • validate (bool, optional) – Whether parameter validation was performed

Note

These additional parameters (stream_callback, use_cache, validate) are passed from run_one_function() to provide context about the execution. Tools can use these for optimization or special handling.

For backward compatibility, tools that don’t accept these parameters will still work - they will only receive the arguments parameter.

_local_name(tag)[source]¶
_extract_abstract_from_fulltext_xml(xml_text)[source]¶
_build_fulltext_xml_url(*, source_db, article_id, pmcid)[source]¶
_build_pmc_oai_url(pmcid)[source]¶

Build an NCBI PMC OAI-PMH URL to retrieve JATS XML for a PMC article.

Europe PMC fullTextXML is not always available even when an article is in PMC. The OAI endpoint provides a robust fallback for extracting full text/abstract.

_fetch_fulltext_with_trace(*, fulltext_url, pmcid, timeout=20)[source]¶
class tooluniverse.europe_pmc_tool.EuropePMCFullTextSnippetsTool[source]¶

Bases: BaseTool

Fetch Europe PMC fullTextXML (open access) and return bounded text snippets around user-provided terms. This helps answer questions where the crucial detail is present in the full text (e.g., methods/section titles) but not necessarily in the abstract.

__init__(tool_config)[source]¶
_build_pmc_html_url(pmcid)[source]¶
_build_pmc_oai_url(pmcid)[source]¶
_build_fulltext_xml_url(arguments)[source]¶
_extract_text(xml_text)[source]¶
_extract_text_from_html(html_text)[source]¶
run(arguments)[source]¶

Execute the tool.

The default BaseTool implementation accepts an optional arguments mapping to align with most concrete tool implementations which expect a dictionary of inputs.

Parameters:
  • arguments (dict, optional) – Tool-specific arguments

  • stream_callback (callable, optional) – Callback for streaming responses

  • use_cache (bool, optional) – Whether result caching is enabled

  • validate (bool, optional) – Whether parameter validation was performed

Note

These additional parameters (stream_callback, use_cache, validate) are passed from run_one_function() to provide context about the execution. Tools can use these for optimization or special handling.

For backward compatibility, tools that don’t accept these parameters will still work - they will only receive the arguments parameter.

class tooluniverse.europe_pmc_tool.EuropePMCFullTextFetchTool[source]¶

Bases: BaseTool

Fetch full text content for a PMC article with deterministic fallbacks and machine-readable provenance (retrieval_trace).

This tool is intended for machine consumption: it always returns a structured status payload and, when successful, includes source/format/content_type.

__init__(tool_config)[source]¶
_build_fulltext_xml_url(arguments)[source]¶
run(arguments)[source]¶

Execute the tool.

The default BaseTool implementation accepts an optional arguments mapping to align with most concrete tool implementations which expect a dictionary of inputs.

Parameters:
  • arguments (dict, optional) – Tool-specific arguments

  • stream_callback (callable, optional) – Callback for streaming responses

  • use_cache (bool, optional) – Whether result caching is enabled

  • validate (bool, optional) – Whether parameter validation was performed

Note

These additional parameters (stream_callback, use_cache, validate) are passed from run_one_function() to provide context about the execution. Tools can use these for optimization or special handling.

For backward compatibility, tools that don’t accept these parameters will still work - they will only receive the arguments parameter.

class tooluniverse.europe_pmc_tool.EuropePMCRESTTool[source]¶

Bases: BaseTool

Generic REST tool for Europe PMC API endpoints. Supports citations, references, and other article-related endpoints.

__init__(tool_config)[source]¶
_build_url(arguments)[source]¶

Build URL from endpoint template and arguments.

run(arguments)[source]¶

Execute the Europe PMC REST API request.