tooluniverse packageΒΆ

class tooluniverse.ADMETAITool(**kwargs)[source]ΒΆ

Bases: BaseTool

Tool to predict ADMET properties for a given SMILES string using the admet-ai Python package.

__init__(**kwargs)[source]ΒΆ
_predict(smiles: str) dict[source]ΒΆ

Gets ADMET predictions for the given smiles

run(arguments: dict) dict[source]ΒΆ

Predicts ADMET properties for a given SMILES string.

Parameters:

smiles – The SMILES string(s) of the molecule(s).

Returns:

A dictionary mapping each SMILES string to a subdictionary of selected ADMET properties and their predicted values.

class tooluniverse.AgenticTool(tool_config: Dict[str, Any])[source]ΒΆ

Bases: BaseTool

Generic wrapper around LLM prompting supporting JSON-defined configs with prompts and input arguments.

__init__(tool_config: Dict[str, Any])[source]ΒΆ
_format_prompt(arguments: Dict[str, Any]) str[source]ΒΆ
_get_global_fallback_chain() List[Dict[str, str]][source]ΒΆ

Get the global fallback chain from environment or use default.

_try_api(api_type: str, model_id: str) bool[source]ΒΆ

Try to initialize a specific API and model.

_try_initialize_api()[source]ΒΆ

Try to initialize the primary API, fallback to secondary if configured.

_validate_arguments(arguments: Dict[str, Any])[source]ΒΆ
_validate_model_config()[source]ΒΆ
estimate_token_usage(arguments: Dict[str, Any]) Dict[str, int][source]ΒΆ
get_availability_status() Dict[str, Any][source]ΒΆ

Get detailed availability status of the tool.

get_input_arguments() List[str][source]ΒΆ
get_model_info() Dict[str, Any][source]ΒΆ
get_prompt_preview(arguments: Dict[str, Any]) str[source]ΒΆ
get_prompt_template() str[source]ΒΆ
static has_any_api_keys() bool[source]ΒΆ

Check if any API keys are available across all supported API types.

Returns:

True if at least one API type has all required keys, False otherwise

Return type:

bool

is_available() bool[source]ΒΆ

Check if the tool is available for use.

retry_initialization() bool[source]ΒΆ

Attempt to reinitialize the tool (useful if API keys were updated).

run(arguments: Dict[str, Any]) Dict[str, Any][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.

validate_configuration() Dict[str, Any][source]ΒΆ
class tooluniverse.AlphaFoldRESTTool(tool_config)[source]ΒΆ

Bases: BaseTool

AlphaFold Protein Structure Database API tool. Generic wrapper for AlphaFold API endpoints defined in alphafold_tools.json.

__init__(tool_config)[source]ΒΆ
_build_url(arguments: Dict[str, Any]) str | Dict[str, Any][source]ΒΆ
_make_request(url: str) Dict[str, Any][source]ΒΆ

Perform a GET request and handle common errors.

run(arguments: Dict[str, Any])[source]ΒΆ

Execute the tool with provided arguments.

class tooluniverse.BaseTool(tool_config)[source]ΒΆ

Bases: object

__init__(tool_config)[source]ΒΆ
_apply_defaults(tool_config)[source]ΒΆ

Apply default configuration to the tool config

check_function_call(function_call_json)[source]ΒΆ
classmethod get_default_config_file()[source]ΒΆ

Get the path to the default configuration file for this tool type.

This method uses a robust path resolution strategy that works across different installation scenarios:

  1. Installed packages: Uses importlib.resources for proper package resource access

  2. Development mode: Falls back to file-based path resolution

  3. Legacy Python: Handles importlib.resources and importlib_resources

Override this method in subclasses to specify a custom defaults file.

Returns:

Path or resource object pointing to the defaults file

get_required_parameters()[source]ΒΆ

Retrieve required parameters from the endpoint definition. Returns: list: List of required parameters for the given endpoint.

classmethod load_defaults_from_file()[source]ΒΆ

Load defaults from the configuration file

run(arguments=None)[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.

class tooluniverse.ChEMBLTool(tool_config, base_url='https://www.ebi.ac.uk/chembl/api/data')[source]ΒΆ

Bases: BaseTool

Tool to search for molecules similar to a given compound name or SMILES using the ChEMBL Web Services API.

__init__(tool_config, base_url='https://www.ebi.ac.uk/chembl/api/data')[source]ΒΆ
_search_similar_molecules(query, similarity_threshold, max_results)[source]ΒΆ
get_chembl_id_by_name(compound_name)[source]ΒΆ

Search ChEMBL for a compound by name and return the ChEMBL ID of the first match.

get_chembl_smiles_pref_name_id_by_name(compound_name)[source]ΒΆ

Search ChEMBL for a compound by name and return a list of dicts with ChEMBL ID, canonical SMILES, and preferred name for the top 5 matches.

get_smiles_pref_name_by_chembl_id(query)[source]ΒΆ

Given a ChEMBL ID, return a dict with canonical SMILES and preferred name.

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.

class tooluniverse.ClinicalTrialsDetailsTool(tool_config)[source]ΒΆ

Bases: ClinicalTrialsTool

__init__(tool_config)[source]ΒΆ
_extract_outcomes_from_output(study, outcome_measure)[source]ΒΆ
_extract_safety_from_output(study, organs, adverse_event_type)[source]ΒΆ
_remove_empty_values(obj)[source]ΒΆ
_simplify_output(study, query_type)[source]ΒΆ

Manually extract generally most useful information

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.

class tooluniverse.ClinicalTrialsSearchTool(tool_config)[source]ΒΆ

Bases: ClinicalTrialsTool

__init__(tool_config)[source]ΒΆ
_simplify_output(response)[source]ΒΆ
run(arguments)[source]ΒΆ

Executes the search query for clinical trials.

Parameters:

arguments (dict) – A dictionary containing parameters provided by the user/LLM

Returns:

The JSON response from the API as a dictionary,

or raw text for non-JSON responses, or an error dictionary.

Return type:

dict or str

class tooluniverse.ComposeTool(tool_config, tooluniverse=None)[source]ΒΆ

Bases: BaseTool

A flexible tool that can compose other tools using custom code logic. Supports both inline composition_code and external Python files. Features intelligent dependency management with automatic tool loading.

__init__(tool_config, tooluniverse=None)[source]ΒΆ
_call_tool(tool_name, arguments)[source]ΒΆ

Helper function to call other tools from within composition code.

Parameters:
  • tool_name (str) – Name of the tool to call

  • arguments (dict) – Arguments to pass to the tool

Returns:

Result from the tool execution

Return type:

Any

_discover_tool_dependencies()[source]ΒΆ

Automatically discover tool dependencies from composition code.

Returns:

Set of tool names that this composition calls

Return type:

set

_execute_from_file(arguments)[source]ΒΆ

Execute composition code from external file.

Parameters:

arguments (dict) – Input arguments

Returns:

Result from the composition execution

Return type:

Any

_execute_inline_code(arguments)[source]ΒΆ

Execute inline composition code (existing behavior).

Parameters:

arguments (dict) – Input arguments

Returns:

Result from the composition execution

Return type:

Any

_get_tool_category_mapping()[source]ΒΆ

Create a mapping from tool names to their categories.

Returns:

Mapping of tool names to category names

Return type:

dict

_load_code_from_file()[source]ΒΆ

Load composition code from external Python file.

Returns:

The composition code as a string

Return type:

str

_load_missing_dependencies(missing_tools: Set[str])[source]ΒΆ

Automatically load missing tool dependencies.

Parameters:

missing_tools (set) – Set of missing tool names

Returns:

(successfully_loaded, failed_to_load)

Return type:

tuple

run(arguments)[source]ΒΆ

Execute the composed tool with custom code logic.

Parameters:

arguments (dict) – Input arguments for the composition

Returns:

Result from the composition execution

Return type:

Any

class tooluniverse.DatasetTool(tool_config)[source]ΒΆ

Bases: BaseTool

Tool to search and filter the DrugBank vocabulary dataset. Provides functionality to search drugs by name, ID, synonyms and filter by various criteria.

__init__(tool_config)[source]ΒΆ
_drugbank_filter(arguments)[source]ΒΆ

Filter drugs based on specific criteria and field-based conditions.

This function is dedicated to criteria-based filtering using simple field-condition-value parameters. It supports filter types like contains, starts_with, ends_with, exact, not_empty.

Parameters:

arguments (dict) – Filter parameters including: - field (str): Field name to filter on - condition (str): Type of condition (contains, starts_with, ends_with, exact, not_empty) - value (str): Value to filter by (optional for not_empty condition) - limit (int): Maximum number of results

Returns:

Filtered results with matched records and applied filters

Return type:

dict

Search drugs by name, ID, synonyms, or other fields using text-based queries.

This function is dedicated to text-based searching across specified fields. It performs substring or exact matching based on user preferences.

Parameters:

arguments (dict) – Search parameters including: - query (str): Text to search for - search_fields (list): Fields to search in - case_sensitive (bool): Whether search is case sensitive - exact_match (bool): Whether to perform exact matching - limit (int): Maximum number of results

Returns:

Search results with matched records and metadata

Return type:

dict

_load_dataset()[source]ΒΆ

Load the drugbank vocabulary CSV dataset.

get_dataset_info()[source]ΒΆ

Get information about the loaded dataset.

run(arguments)[source]ΒΆ

Main entry point for the tool.

class tooluniverse.DiseaseTargetScoreTool(tool_config, datasource_id=None)[source]ΒΆ

Bases: GraphQLTool

Tool to extract disease-target association scores from specific data sources

__init__(tool_config, datasource_id=None)[source]ΒΆ
run(arguments)[source]ΒΆ

Extract disease-target scores for a specific datasource Arguments should contain: efoId, datasourceId (optional), pageSize (optional)

class tooluniverse.EFOTool(tool_config, base_url='https://www.ebi.ac.uk/ols4/api/search')[source]ΒΆ

Bases: BaseTool

Tool to lookup Experimental Factor Ontology (EFO) IDs for diseases via the EMBL-EBI OLS API.

__init__(tool_config, base_url='https://www.ebi.ac.uk/ols4/api/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.

class tooluniverse.EmbeddingDatabase(tool_config)[source]ΒΆ

Bases: BaseTool

Unified embedding database tool supporting multiple operations: - create_from_docs: Create new database from documents - add_docs: Add documents to existing database - search: Search for similar documents - load_database: Load existing database from path

__init__(tool_config)[source]ΒΆ
_add_documents(arguments)[source]ΒΆ

Add documents to existing database

_create_from_documents(arguments)[source]ΒΆ

Create new embedding database from documents

_database_exists(database_name: str) bool[source]ΒΆ

Check if database exists

_generate_embeddings(texts: List[str], model: str, use_azure: bool = False) List[List[float]][source]ΒΆ

Generate embeddings using OpenAI or Azure OpenAI API

_get_database_info(database_name: str) Dict[source]ΒΆ

Get database information

_init_azure_client(config)[source]ΒΆ

Initialize Azure OpenAI client with configuration

_init_database()[source]ΒΆ

Initialize SQLite database with required tables

_init_openai_client(config)[source]ΒΆ

Initialize OpenAI client with configuration

_load_database(arguments)[source]ΒΆ

Load existing database from path

_matches_filters(metadata: Dict, filters: Dict) bool[source]ΒΆ

Check if metadata matches the given filters

Search for similar documents in database

_substitute_env_vars(value)[source]ΒΆ

Substitute environment variables in configuration values

run(arguments)[source]ΒΆ

Main entry point for the tool

class tooluniverse.EmbeddingSync(tool_config)[source]ΒΆ

Bases: BaseTool

Sync embedding databases with HuggingFace Hub. Supports uploading local databases and downloading shared databases.

__init__(tool_config)[source]ΒΆ
_download_from_huggingface(arguments)[source]ΒΆ

Download database from HuggingFace Hub

_generate_readme(database_name: str, description: str, db_info: Dict) str[source]ΒΆ

Generate README content for HuggingFace repository

_get_database_info(database_name: str) Dict[source]ΒΆ

Get database information from local SQLite

_local_database_exists(database_name: str) bool[source]ΒΆ

Check if database exists locally

_merge_databases(source_db: str, target_db: str, source_name: str, target_name: str)[source]ΒΆ

Merge source database into target database (simplified implementation)

_rename_database_in_db(db_path: str, old_name: str, new_name: str)[source]ΒΆ

Rename database in SQLite file

_upload_to_huggingface(arguments)[source]ΒΆ

Upload local database to HuggingFace Hub

run(arguments)[source]ΒΆ

Main entry point for the tool

class tooluniverse.EuropePMCTool(tool_config, base_url='https://www.ebi.ac.uk/europepmc/webservices/rest/search')[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.

class tooluniverse.FDACountAdditiveReactionsTool(tool_config, endpoint_url='https://api.fda.gov/drug/event.json', api_key=None)[source]ΒΆ

Bases: FDADrugAdverseEventTool

Leverage openFDA API to count adverse reaction events across multiple drugs in one request.

__init__(tool_config, endpoint_url='https://api.fda.gov/drug/event.json', api_key=None)[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.

class tooluniverse.FDADrugAdverseEventTool(tool_config, endpoint_url='https://api.fda.gov/drug/event.json', api_key=None)[source]ΒΆ

Bases: BaseTool

__init__(tool_config, endpoint_url='https://api.fda.gov/drug/event.json', api_key=None)[source]ΒΆ
_map_value(param_name, value)[source]ΒΆ
_post_process(response)[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.

validate_enum_arguments(arguments)[source]ΒΆ

Validate that enum-based arguments match the allowed values

class tooluniverse.FDADrugLabelGetDrugGenericNameTool(tool_config=None, api_key=None)[source]ΒΆ

Bases: FDADrugLabelTool

__init__(tool_config=None, api_key=None)[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.

class tooluniverse.FDADrugLabelSearchIDTool(tool_config=None, api_key=None)[source]ΒΆ

Bases: FDATool

__init__(tool_config=None, api_key=None)[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.

class tooluniverse.FDADrugLabelSearchTool(tool_config=None, api_key=None)[source]ΒΆ

Bases: FDATool

__init__(tool_config=None, api_key=None)[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.

class tooluniverse.FDADrugLabelTool(tool_config, api_key=None)[source]ΒΆ

Bases: FDATool

__init__(tool_config, api_key=None)[source]ΒΆ
class tooluniverse.GWASAssociationByID(tool_config)[source]ΒΆ

Bases: GWASRESTTool

Get a specific GWAS association by its ID.

__init__(tool_config)[source]ΒΆ
run(arguments: Dict[str, Any]) Dict[str, Any][source]ΒΆ

Get association by ID.

class tooluniverse.GWASAssociationSearch(tool_config)[source]ΒΆ

Bases: GWASRESTTool

Search for GWAS associations by various criteria.

__init__(tool_config)[source]ΒΆ
run(arguments: Dict[str, Any]) Dict[str, Any][source]ΒΆ

Search for associations with optional filters.

class tooluniverse.GWASAssociationsForSNP(tool_config)[source]ΒΆ

Bases: GWASRESTTool

Get all associations for a specific SNP.

__init__(tool_config)[source]ΒΆ
run(arguments: Dict[str, Any]) Dict[str, Any][source]ΒΆ

Get associations for a SNP.

class tooluniverse.GWASAssociationsForStudy(tool_config)[source]ΒΆ

Bases: GWASRESTTool

Get all associations for a specific study.

__init__(tool_config)[source]ΒΆ
run(arguments: Dict[str, Any]) Dict[str, Any][source]ΒΆ

Get associations for a study.

class tooluniverse.GWASAssociationsForTrait(tool_config)[source]ΒΆ

Bases: GWASRESTTool

Get all associations for a specific trait, sorted by p-value.

__init__(tool_config)[source]ΒΆ
run(arguments: Dict[str, Any]) Dict[str, Any][source]ΒΆ

Get associations for a trait, sorted by significance.

class tooluniverse.GWASSNPByID(tool_config)[source]ΒΆ

Bases: GWASRESTTool

Get a specific GWAS SNP by its rs ID.

__init__(tool_config)[source]ΒΆ
run(arguments: Dict[str, Any]) Dict[str, Any][source]ΒΆ

Get SNP by rs ID.

class tooluniverse.GWASSNPSearch(tool_config)[source]ΒΆ

Bases: GWASRESTTool

Search for GWAS single nucleotide polymorphisms (SNPs).

__init__(tool_config)[source]ΒΆ
run(arguments: Dict[str, Any]) Dict[str, Any][source]ΒΆ

Search for SNPs with optional filters.

class tooluniverse.GWASSNPsForGene(tool_config)[source]ΒΆ

Bases: GWASRESTTool

Get SNPs mapped to a specific gene.

__init__(tool_config)[source]ΒΆ
run(arguments: Dict[str, Any]) Dict[str, Any][source]ΒΆ

Get SNPs for a gene.

class tooluniverse.GWASStudiesForTrait(tool_config)[source]ΒΆ

Bases: GWASRESTTool

Get studies for a specific trait with optional filters.

__init__(tool_config)[source]ΒΆ
run(arguments: Dict[str, Any]) Dict[str, Any][source]ΒΆ

Get studies for a trait with optional filters.

class tooluniverse.GWASStudyByID(tool_config)[source]ΒΆ

Bases: GWASRESTTool

Get a specific GWAS study by its ID.

__init__(tool_config)[source]ΒΆ
run(arguments: Dict[str, Any]) Dict[str, Any][source]ΒΆ

Get study by ID.

class tooluniverse.GWASStudySearch(tool_config)[source]ΒΆ

Bases: GWASRESTTool

Search for GWAS studies by various criteria.

__init__(tool_config)[source]ΒΆ
run(arguments: Dict[str, Any]) Dict[str, Any][source]ΒΆ

Search for studies with optional filters.

class tooluniverse.GWASVariantsForTrait(tool_config)[source]ΒΆ

Bases: GWASRESTTool

Get all variants associated with a specific trait.

__init__(tool_config)[source]ΒΆ
run(arguments: Dict[str, Any]) Dict[str, Any][source]ΒΆ

Get variants for a trait with pagination support.

class tooluniverse.GetSPLBySetIDTool(tool_config)[source]ΒΆ

Bases: BaseTool

Get complete SPL label based on SPL Set ID, returns content in XML or JSON format.

__init__(tool_config)[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.

class tooluniverse.HPAGetGeneJSONTool(tool_config)[source]ΒΆ

Bases: HPAJsonApiTool

Enhanced legacy tool - Get basic gene information using Ensembl Gene ID. Now uses the efficient JSON API instead of search API.

run(arguments: Dict[str, Any]) Dict[str, Any][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.

class tooluniverse.HPAGetGeneXMLTool(tool_config)[source]ΒΆ

Bases: HPASearchApiTool

Legacy tool - Get gene TSV format data (alternative to XML).

run(arguments: Dict[str, Any]) Dict[str, Any][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.

class tooluniverse.MCPAutoLoaderTool(tool_config)[source]ΒΆ

Bases: BaseTool, BaseMCPClient

An advanced MCP tool that automatically discovers and loads all tools from an MCP server. It can register discovered tools as individual ToolUniverse tools for seamless usage.

__del__()[source]ΒΆ

Cleanup when object is destroyed

__init__(tool_config)[source]ΒΆ
async auto_load_and_register(engine) Dict[str, Any][source]ΒΆ

Automatically discover, load and register all MCP tools

async call_tool(tool_name: str, arguments: Dict[str, Any]) Dict[str, Any][source]ΒΆ

Directly call an MCP tool by name

async discover_tools() Dict[str, Any][source]ΒΆ

Discover all available tools from the MCP server

generate_proxy_tool_configs() List[Dict[str, Any]][source]ΒΆ

Generate proxy tool configurations for discovered tools

register_tools_in_engine(engine)[source]ΒΆ

Register discovered tools directly in the ToolUniverse engine

run(arguments)[source]ΒΆ

Main run method for the auto-loader tool

class tooluniverse.MCPClientTool(tool_config)[source]ΒΆ

Bases: BaseTool, BaseMCPClient

A tool that acts as an MCP client to connect to existing MCP servers. Supports both HTTP and WebSocket transports.

__init__(tool_config)[source]ΒΆ
async _run_call_tool(arguments)[source]ΒΆ

Run call_tool operation

async _run_get_prompt(arguments)[source]ΒΆ

Run get_prompt operation

async _run_list_prompts()[source]ΒΆ

Run list_prompts operation

async _run_list_resources()[source]ΒΆ

Run list_resources operation

async _run_list_tools()[source]ΒΆ

Run list_tools operation

async _run_read_resource(arguments)[source]ΒΆ

Run read_resource operation

async call_tool(name: str, arguments: Dict[str, Any]) Dict[str, Any][source]ΒΆ

Call a tool on the MCP server

async get_prompt(name: str, arguments: Dict[str, Any] | None = None) Dict[str, Any][source]ΒΆ

Get a prompt from the MCP server

async list_prompts() List[Dict[str, Any]][source]ΒΆ

List available prompts from the MCP server

async list_resources() List[Dict[str, Any]][source]ΒΆ

List available resources from the MCP server

async list_tools() List[Dict[str, Any]][source]ΒΆ

List available tools from the MCP server

async read_resource(uri: str) Dict[str, Any][source]ΒΆ

Read a resource from the MCP server

run(arguments)[source]ΒΆ

Main run method for the tool. Supports different operations based on the β€˜operation’ argument.

class tooluniverse.MedlinePlusRESTTool(tool_config)[source]ΒΆ

Bases: BaseTool

MedlinePlus REST API tool class. Supports health topic search, code lookup, genetics information retrieval, etc.

__init__(tool_config)[source]ΒΆ
_build_url(arguments: dict) str[source]ΒΆ

Build complete URL

_extract_text_content(text_item: dict) str[source]ΒΆ

Extract content from text item

_format_response(response: Any, tool_name: str) Dict[str, Any][source]ΒΆ

Format response content

connect_lookup_by_code(cs: str, c: str, dn: str | None = None, language: str = 'en', format: str = 'json') Any[source]ΒΆ
get_genetics_condition_by_name(condition: str, format: str = 'json') Any[source]ΒΆ
get_genetics_gene_by_name(gene: str, format: str = 'json') Any[source]ΒΆ
get_genetics_index() Any[source]ΒΆ
run(arguments: dict)[source]ΒΆ

Execute tool call

search_topics_by_keyword(term: str, db: str, rettype: str = 'brief') Dict[str, Any][source]ΒΆ
class tooluniverse.MonarchDiseasesForMultiplePhenoTool(tool_config)[source]ΒΆ

Bases: MonarchTool

__init__(tool_config)[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.

class tooluniverse.MonarchTool(tool_config)[source]ΒΆ

Bases: RESTfulTool

__init__(tool_config)[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.

class tooluniverse.ODPHPItemList(tool_config)[source]ΒΆ

Bases: ODPHPRESTTool

Retrieve list of topics or categories.

run(arguments: Dict[str, Any]) Dict[str, Any][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.

class tooluniverse.ODPHPMyHealthfinder(tool_config)[source]ΒΆ

Bases: ODPHPRESTTool

Search for demographic-specific health recommendations (MyHealthfinder).

run(arguments: Dict[str, Any]) Dict[str, Any][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.

class tooluniverse.ODPHPOutlinkFetch(tool_config)[source]ΒΆ

Bases: BaseTool

Fetch article pages referenced by AccessibleVersion / RelatedItems.Url and return readable text. - HTML: extracts main/article/body text; strips nav/aside/footer/script/style. - PDF or non-HTML: returns metadata + URL so the agent can surface it.

__init__(tool_config)[source]ΒΆ
_extract_text(html: str) Dict[str, str][source]ΒΆ
run(arguments: Dict[str, Any]) Dict[str, Any][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.

class tooluniverse.ODPHPTopicSearch(tool_config)[source]ΒΆ

Bases: ODPHPRESTTool

Search for health topics by ID, category, or keyword.

run(arguments: Dict[str, Any]) Dict[str, Any][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.

class tooluniverse.OpentargetGeneticsTool(tool_config)[source]ΒΆ

Bases: GraphQLTool

__init__(tool_config)[source]ΒΆ
class tooluniverse.OpentargetTool(tool_config)[source]ΒΆ

Bases: GraphQLTool

__init__(tool_config)[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.

class tooluniverse.OpentargetToolDrugNameMatch(tool_config, drug_generic_tool=None)[source]ΒΆ

Bases: GraphQLTool

__init__(tool_config, drug_generic_tool=None)[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.

class tooluniverse.PackageTool(tool_config)[source]ΒΆ

Bases: BaseTool

Universal tool to provide information about Python packages. Fetches real-time data from PyPI API with local fallback.

__init__(tool_config)[source]ΒΆ
_get_installation_instructions() Dict[str, str][source]ΒΆ

Generate installation instructions

_get_local_info(include_examples: bool = True) Dict[str, Any][source]ΒΆ

Get package information from local configuration

_get_pypi_info(include_examples: bool = True) Dict[str, Any][source]ΒΆ

Fetch package information from PyPI API

_get_quick_start_guide() list[source]ΒΆ

Get quick start guide steps

_get_usage_example() str[source]ΒΆ

Get usage example for the package

run(arguments)[source]ΒΆ

Get comprehensive package information.

Parameters:

arguments (dict) – Optional parameters for customization

Returns:

Package information including name, description, installation, docs, usage

Return type:

dict

class tooluniverse.PubChemRESTTool(tool_config)[source]ΒΆ

Bases: BaseTool

Generic PubChem PUG-REST tool class. Directly concatenates URL from the fields.endpoint template and sends requests to PubChem PUG-REST.

__init__(tool_config)[source]ΒΆ
_build_url(arguments: dict) str[source]ΒΆ

Use regex to replace all {placeholder} in endpoint_template to generate complete URL path. For example endpoint_template=”/compound/cid/{cid}/property/{property_list}/JSON” arguments={β€œcid”:2244}, property_list=[β€œMolecularWeight”,”IUPACName”] β†’ β€œ/compound/cid/2244/property/MolecularWeight,IUPACName/JSON” Finally returns β€œhttps://pubchem.ncbi.nlm.nih.gov/rest/pug” + concatenated path.

run(arguments: dict)[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.

class tooluniverse.PubTatorTool(tool_config: Dict[str, Any])[source]ΒΆ

Bases: BaseTool

Generic wrapper around a single PubTator 3 endpoint supporting JSON-defined configs.

__init__(tool_config: Dict[str, Any])[source]ΒΆ
_compose_url(args: Dict[str, Any]) str[source]ΒΆ

Substitute template vars & build full URL.

_filter_search_results(result: Dict[str, Any]) Dict[str, Any][source]ΒΆ

Filter PubTatorSearch results by score threshold and remove facet items that only have β€˜name’, β€˜type’, and β€˜value’.

_query_params(args: Dict[str, Any]) Dict[str, str][source]ΒΆ

Translate caller arg names β†’ API param names, drop Nones, serialise lists.

run(arguments: Dict[str, Any])[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.

class tooluniverse.RCSBTool(tool_config)[source]ΒΆ

Bases: BaseTool

__init__(tool_config)[source]ΒΆ
prepare_input_ids(params: dict)[source]ΒΆ
run(params: dict)[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.

validate_params(params: dict)[source]ΒΆ
class tooluniverse.ReactomeRESTTool(tool_config)[source]ΒΆ

Bases: BaseTool

Generic Reactome Content Service REST tool. If there is no β€œfields.extract_path” in config or its value is empty, returns complete JSON; Otherwise, drills down according to the β€œdot-separated path” in extract_path and returns corresponding sub-node.

__init__(tool_config)[source]ΒΆ
_build_url(arguments: dict) str[source]ΒΆ

Combines endpoint_template (containing {xxx}) with path parameters from arguments to generate complete URL. For example endpoint_template=”/data/pathway/{stId}”, arguments={β€œstId”:”R-HSA-73817”} β†’ Returns β€œhttps://reactome.org/ContentService/data/pathway/R-HSA-73817”

run(arguments: dict)[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.

class tooluniverse.SMCP(name: str | None = None, tooluniverse_config: ToolUniverse | Dict[str, Any] | None = None, tool_categories: List[str] | None = None, exclude_tools: List[str] | None = None, exclude_categories: List[str] | None = None, include_tools: List[str] | None = None, tools_file: str | None = None, tool_config_files: Dict[str, str] | None = None, include_tool_types: List[str] | None = None, exclude_tool_types: List[str] | None = None, auto_expose_tools: bool = True, search_enabled: bool = True, max_workers: int = 5, hooks_enabled: bool = False, hook_config: Dict[str, Any] | None = None, hook_type: str | None = None, **kwargs)[source]ΒΆ

Bases: FastMCP

Scientific Model Context Protocol (SMCP) Server

SMCP is an enhanced MCP (Model Context Protocol) server that seamlessly integrates ToolUniverse’s extensive collection of scientific and scientific tools with the FastMCP framework. It provides a unified, AI-accessible interface for scientific computing, data analysis, and research workflows.

The SMCP server extends standard MCP capabilities with scientific domain expertise, intelligent tool discovery, and optimized configurations for research applications. It automatically handles the complex task of exposing hundreds of specialized tools through a consistent, well-documented interface.

Key Features:ΒΆ

πŸ”¬ Scientific Tool Integration: Native access to 350+ specialized tools covering

scientific databases, literature search, clinical data, genomics, proteomics, chemical informatics, and AI-powered analysis capabilities.

🧠 AI-Powered Tool Discovery: Multi-tiered intelligent search system using:
  • ToolFinderLLM: Cost-optimized LLM-based semantic understanding with pre-filtering

  • Tool_RAG: Embedding-based similarity search

  • Keyword Search: Simple text matching as reliable fallback

πŸ“‘ Full MCP Protocol Support: Complete implementation of MCP specification with:
  • Standard methods (tools/list, tools/call, resources/, prompts/)

  • Custom scientific methods (tools/find, tools/search)

  • Multi-transport support (stdio, HTTP, SSE)

  • JSON-RPC 2.0 compliance with proper error handling

⚑ High-Performance Architecture: Production-ready features including:
  • Configurable thread pools for concurrent tool execution

  • Intelligent tool loading and caching

  • Resource management and graceful degradation

  • Comprehensive error handling and recovery

πŸ”§ Developer-Friendly: Simplified configuration and deployment with:
  • Sensible defaults for scientific computing

  • Flexible customization options

  • Comprehensive documentation and examples

  • Built-in diagnostic and monitoring tools

Custom MCP Methods:ΒΆ

tools/find:

AI-powered tool discovery using natural language queries. Supports semantic search, category filtering, and flexible response formats.

tools/search:

Alternative endpoint for tool discovery with identical functionality to tools/find, provided for compatibility and convenience.

Parameters:ΒΆ

namestr, optional

Human-readable server name used in logs and identification. Default: β€œSMCP Server” Examples: β€œScientific Research API”, β€œDrug Discovery Server”

tooluniverse_configToolUniverse or dict, optional

Either a pre-configured ToolUniverse instance or configuration dict. If None, creates a new ToolUniverse with default settings. Allows reuse of existing tool configurations and customizations.

tool_categorieslist of str, optional

Specific ToolUniverse categories to load. If None and auto_expose_tools=True, loads all available tools. Common combinations: - Scientific: [β€œChEMBL”, β€œuniprot”, β€œopentarget”, β€œpubchem”, β€œhpa”] - Literature: [β€œEuropePMC”, β€œsemantic_scholar”, β€œpubtator”, β€œagents”] - Clinical: [β€œfda_drug_label”, β€œclinical_trials”, β€œadverse_events”]

exclude_toolslist of str, optional

Specific tool names to exclude from loading. These tools will not be exposed via the MCP interface even if they are in the loaded categories. Useful for removing specific problematic or unwanted tools.

exclude_categorieslist of str, optional

Tool categories to exclude from loading. These entire categories will be skipped during tool loading. Can be combined with tool_categories to first select categories and then exclude specific ones.

include_toolslist of str, optional

Specific tool names to include. If provided, only these tools will be loaded regardless of categories. Overrides category-based selection.

tools_filestr, optional

Path to a text file containing tool names to include (one per line). Alternative to include_tools parameter. Comments (lines starting with #) and empty lines are ignored.

tool_config_filesdict of str, optional

Additional tool configuration files to load. Format: {β€œcategory_name”: β€œ/path/to/config.json”}. These files will be loaded in addition to the default tool files.

include_tool_typeslist of str, optional

Specific tool types to include. If provided, only tools of these types will be loaded. Available types include: β€˜OpenTarget’, β€˜ToolFinderEmbedding’, β€˜ToolFinderKeyword’, β€˜ToolFinderLLM’, etc.

exclude_tool_typeslist of str, optional

Tool types to exclude from loading. These tool types will be skipped during tool loading. Useful for excluding entire categories of tools (e.g., all ToolFinder types or all OpenTarget tools).

auto_expose_toolsbool, default True

Whether to automatically expose ToolUniverse tools as MCP tools. When True, all loaded tools become available via the MCP interface with automatic schema conversion and execution wrapping.

search_enabledbool, default True

Enable AI-powered tool search functionality via tools/find method. Includes ToolFinderLLM (cost-optimized LLM-based), Tool_RAG (embedding-based), and simple keyword search capabilities with intelligent fallback.

max_workersint, default 5

Maximum number of concurrent worker threads for tool execution. Higher values allow more parallel tool calls but use more resources. Recommended: 5-20 depending on server capacity and expected load.

hooks_enabledbool, default False

Whether to enable output processing hooks for intelligent post-processing of tool outputs. When True, hooks can automatically summarize long outputs, save results to files, or apply other transformations.

hook_configdict, optional

Custom hook configuration dictionary. If provided, overrides default hook settings. Should contain β€˜hooks’ list with hook definitions. Example: {β€œhooks”: [{β€œname”: β€œsummarization_hook”, β€œtype”: β€œSummarizationHook”, …}]}

hook_typestr, optional

Simple hook type selection. Can be β€˜SummarizationHook’, β€˜FileSaveHook’, or a list of both. Provides an easy way to enable hooks without full configuration. Takes precedence over hooks_enabled when specified.

**kwargs

Additional arguments passed to the underlying FastMCP server instance. Supports all FastMCP configuration options for advanced customization.

Raises:ΒΆ

ImportError

If FastMCP is not installed. FastMCP is a required dependency for SMCP. Install with: pip install fastmcp

Notes:ΒΆ

  • SMCP automatically handles ToolUniverse tool loading and MCP conversion

  • Tool search uses ToolFinderLLM (optimized for cost) when available, gracefully falls back to simpler methods

  • All tools support JSON argument passing for maximum flexibility

  • Server supports graceful shutdown and comprehensive resource cleanup

  • Thread pool execution ensures non-blocking operation for concurrent requests

  • Built-in error handling provides informative debugging information

__init__(name: str | None = None, tooluniverse_config: ToolUniverse | Dict[str, Any] | None = None, tool_categories: List[str] | None = None, exclude_tools: List[str] | None = None, exclude_categories: List[str] | None = None, include_tools: List[str] | None = None, tools_file: str | None = None, tool_config_files: Dict[str, str] | None = None, include_tool_types: List[str] | None = None, exclude_tool_types: List[str] | None = None, auto_expose_tools: bool = True, search_enabled: bool = True, max_workers: int = 5, hooks_enabled: bool = False, hook_config: Dict[str, Any] | None = None, hook_type: str | None = None, **kwargs)[source]ΒΆ
_add_search_tools()[source]ΒΆ

Register AI-powered tool search and discovery functionality.

This method adds sophisticated tool discovery capabilities to the SMCP server, enabling clients to find relevant tools using natural language queries. It provides both programmatic (MCP tool) and protocol-level (tools/find method) interfaces for tool discovery.

Registered Tools:ΒΆ

find_tools:

Primary tool discovery interface with AI-powered search capabilities.

Parameters: - query (str): Natural language description of desired functionality - categories (list, optional): Tool categories to filter by - limit (int, default=10): Maximum number of results - use_advanced_search (bool, default=True): Use AI vs keyword search

Returns: JSON string with discovered tools and search metadata

search_tools:

Backward-compatible alias for find_tools with identical functionality. Maintained for compatibility with existing integrations.

Search Capabilities:ΒΆ

AI-Powered Search (ToolFinderLLM):
  • Uses Large Language Model to understand query semantics with optimized context

  • Pre-filters tools using keyword matching to reduce LLM context cost

  • Analyzes only essential tool information (name + description) for cost efficiency

  • Provides relevance scoring and reasoning

  • Handles complex queries like β€œanalyze protein interactions in cancer”

Embedding-Based Search (Tool_RAG):
  • Uses vector embeddings for semantic similarity matching

  • Fast approximate matching for large tool collections

  • Good balance between speed and semantic understanding

Keyword Search (Fallback):
  • Simple text matching against tool names and descriptions

  • Always available regardless of AI tool availability

  • Provides basic but reliable tool discovery

Search Strategy:ΒΆ

  1. Preference: ToolFinderLLM (most intelligent, cost-optimized)

  2. Fallback: Tool_RAG (semantic similarity)

  3. Final: Simple keyword matching (always works)

Integration Details:ΒΆ

  • Automatically initializes available search tools during setup

  • Shares search logic with tools/find MCP method

  • Provides consistent results across different interfaces

  • Handles tool loading and availability detection

Error Handling:ΒΆ

  • Graceful degradation when AI tools unavailable

  • Informative error messages for debugging

  • Fallback mechanisms ensure search always works

  • Detailed logging of search method selection

Usage Examples:ΒΆ

Via MCP tool interface: ```python result = await find_tools(

query=”protein structure prediction”, categories=[β€œuniprot”, β€œhpa”], limit=5

)ΒΆ

Via tools/find MCP method: ```json {

β€œmethod”: β€œtools/find”, β€œparams”: {

β€œquery”: β€œdrug interaction analysis”, β€œlimit”: 3

}

}ΒΆ

_add_utility_tools()[source]ΒΆ

Register essential server management and diagnostic tools.

This method adds a suite of utility tools that provide server introspection, tool management, and direct execution capabilities. These tools are essential for monitoring server health, understanding available capabilities, and providing administrative functionality.

Registered Utility Tools:ΒΆ

get_server_info:

Comprehensive server status and capability reporting.

Returns detailed JSON with: - Server identification (name, type, version info) - Tool statistics (total tools, exposed tools, categories) - Feature flags (search enabled, FastMCP status) - Resource usage (max workers, thread pool status)

Use cases: - Health checks and monitoring - Capability discovery by clients - Debugging server configuration issues

execute_tooluniverse_function:

Direct interface for executing ToolUniverse functions with custom parameters.

Parameters: - function_name (str): Name of the ToolUniverse tool to execute - arguments (str): JSON string containing tool parameters

Features: - Bypasses MCP tool wrappers for direct execution - Supports any loaded ToolUniverse tool - Provides detailed error reporting - Uses thread pool for non-blocking execution

Use cases: - Administrative tool execution - Debugging tool behavior - Custom automation scripts

list_available_tooluniverse_tools:

Comprehensive inventory of all available ToolUniverse tools.

Returns: - Complete tool catalog with names, descriptions, types - Parameter schemas and requirements for each tool - Tool statistics and categorization

Use cases: - Tool discovery and exploration - Documentation generation - Client capability mapping - Integration planning

Implementation Details:ΒΆ

Error Handling:
  • Each tool includes comprehensive try-catch blocks

  • Detailed error messages with context information

  • Graceful degradation when tools or data unavailable

  • JSON-formatted error responses for consistency

Thread Safety:
  • All tools use async execution patterns

  • Thread pool executor for CPU-intensive operations

  • Proper resource cleanup and management

  • Non-blocking I/O for network operations

Security Considerations:
  • execute_tooluniverse_function provides direct tool access

  • JSON parsing with proper validation

  • No file system access beyond ToolUniverse scope

  • Appropriate error message sanitization

Performance Optimization:
  • Lazy loading of tool information

  • Caching where appropriate

  • Minimal memory footprint

  • Efficient JSON serialization

Examples:ΒΆ

Server health check: ```python info = await get_server_info() status = json.loads(info) if status[β€˜total_tooluniverse_tools’] > 0:

# Server healthy pass

```

Direct tool execution: ```python result = await execute_tooluniverse_function(

function_name=”UniProt_get_entry_by_accession”, arguments=’{β€œaccession”: β€œP05067”}’

)ΒΆ

Tool inventory: `python tools = await list_available_tooluniverse_tools() catalog = json.loads(tools) # Available: {catalog['total_tools']} tools `

_create_mcp_tool_from_tooluniverse(tool_config: Dict[str, Any])[source]ΒΆ

Create an MCP tool from a ToolUniverse tool configuration.

This method creates a function with proper parameter signatures that match the ToolUniverse tool schema, enabling FastMCP’s automatic parameter validation.

async _custom_handle_request(request: Dict[str, Any]) Dict[str, Any][source]ΒΆ

Custom MCP request handler that supports enhanced scientific tool operations.

This handler intercepts MCP requests and provides specialized handling for scientific tool discovery methods while maintaining full compatibility with standard MCP protocol operations.

Parameters:ΒΆ

requestdict

JSON-RPC 2.0 request object containing: - method: The MCP method being called - id: Request identifier for response correlation - params: Method-specific parameters

Returns:ΒΆ

dict

JSON-RPC 2.0 response object with either: - result: Successful operation result - error: Error information with code and message

Supported Custom Methods:ΒΆ

tools/find:

Search for tools using natural language queries with AI-powered recommendations. Parameters: - query (required): Natural language description of desired functionality - categories (optional): List of tool categories to filter by - limit (optional): Maximum number of results (default: 10) - use_advanced_search (optional): Use AI vs keyword search (default: True) - search_method (optional): Specific search method - β€˜auto’, β€˜llm’, β€˜embedding’, β€˜keyword’ (default: β€˜auto’) - format (optional): Response format - β€˜detailed’ or β€˜mcp_standard’

tools/search:

Alias for tools/find method with identical parameters and behavior.

Standard MCP Methods:

All other methods are forwarded to the original FastMCP handler, ensuring full compatibility with MCP specification.

Error Codes:ΒΆ

  • -32601: Method not found (unknown method)

  • -32602: Invalid params (missing required parameters)

  • -32603: Internal error (server-side failures)

Examples:ΒΆ

Request for tool discovery: ```json {

β€œjsonrpc”: β€œ2.0”, β€œid”: β€œsearch_123”, β€œmethod”: β€œtools/find”, β€œparams”: {

β€œquery”: β€œprotein structure analysis”, β€œlimit”: 5, β€œformat”: β€œmcp_standard”

}

}ΒΆ

Successful response: ```json {

β€œjsonrpc”: β€œ2.0”, β€œid”: β€œsearch_123”, β€œresult”: {

β€œtools”: […], β€œ_meta”: {

β€œsearch_query”: β€œprotein structure analysis”, β€œsearch_method”: β€œAI-powered (ToolFinderLLM)”, β€œtotal_matches”: 5

}

}

}ΒΆ

_expose_tooluniverse_tools()[source]ΒΆ

Automatically expose ToolUniverse tools as MCP-compatible tools.

This method performs the critical task of converting ToolUniverse’s tool definitions into FastMCP-compatible tools that can be called via the MCP protocol. It handles the complex mapping between different tool formats while ensuring compatibility and usability.

Process Overview:ΒΆ

  1. Tool Inventory: Enumerate all loaded ToolUniverse tools

  2. Type Filtering: Skip meta-tools that shouldn’t be exposed

  3. Schema Conversion: Transform ToolUniverse schemas to MCP format

  4. Function Wrapping: Create async wrappers for tool execution

  5. Registration: Register tools with FastMCP framework

Tool Type Filtering:ΒΆ

Skips these internal tool types: - MCPAutoLoaderTool: Used for loading other MCP servers - MCPClientTool: Used for connecting to external MCP servers

These are meta-tools that manage other tools rather than providing end-user functionality, so they’re excluded from the MCP interface.

Schema Transformation:ΒΆ

ToolUniverse Tool Format: ```json {

β€œname”: β€œtool_name”, β€œparameter”: {

β€œtype”: β€œobject”, β€œproperties”: {…}, β€œrequired”: […]

}

}ΒΆ

MCP Tool Format: ```python async def tool_function(arguments: str = β€œ{}”) -> str:

# Tool execution logic

```

Execution Model:ΒΆ

  • JSON Arguments: All tools accept a single β€˜arguments’ parameter containing JSON-encoded tool parameters

  • Async Execution: Tools run in thread pool to prevent blocking

  • Error Handling: Comprehensive error catching and reporting

  • Type Safety: Proper argument parsing and validation

Duplicate Prevention:ΒΆ

  • Tracks exposed tools in self._exposed_tools set

  • Prevents re-registration of already exposed tools

  • Handles tool reloading scenarios gracefully

Error Recovery:ΒΆ

  • Individual tool failures don’t stop the entire process

  • Detailed error logging for debugging

  • Continues with remaining tools if some fail to convert

Performance Optimization:ΒΆ

  • Lazy evaluation of tool schemas

  • Minimal memory footprint per tool

  • Efficient tool lookup and execution

  • Thread pool reuse for all tool executions

Examples:ΒΆ

Original ToolUniverse tool call: ```python tu.run_one_function({

β€œname”: β€œUniProt_get_entry_by_accession”, β€œarguments”: {β€œaccession”: β€œP05067”}

})ΒΆ

Equivalent MCP tool call: `python await tool_function('{"accession": "P05067"}') `

_get_valid_categories()[source]ΒΆ

Get valid tool categories from ToolUniverse.

Returns:

Set of valid tool category names

Return type:

Set[str]

async _handle_tools_find(request_id: str, params: Dict[str, Any]) Dict[str, Any][source]ΒΆ

Handle the tools/find MCP method for AI-powered tool discovery.

This method implements the core functionality for the custom tools/find MCP method, enabling clients to discover relevant scientific tools using natural language queries. It supports both AI-powered semantic search and simple keyword matching.

Parameters:ΒΆ

request_idstr

Unique identifier for this request, used in the JSON-RPC response

paramsdict

Request parameters containing: - query (required): Natural language description of desired functionality - categories (optional): List of tool categories to filter results - limit (optional): Maximum number of tools to return (default: 10) - use_advanced_search (optional): Whether to use AI search (default: True) - search_method (optional): Specific search method - β€˜auto’, β€˜llm’, β€˜embedding’, β€˜keyword’ (default: β€˜auto’) - format (optional): Response format - β€˜detailed’ or β€˜mcp_standard’ (default: β€˜detailed’)

Returns:ΒΆ

dict

JSON-RPC 2.0 response containing either: - Success: Result with discovered tools and metadata - Error: Error object with appropriate code and message

Response Formats:ΒΆ

Detailed Format (default):

Returns comprehensive tool information including: - Tool names, descriptions, types - Parameter schemas with detailed property information - Search metadata (query, method used, match count)

MCP Standard Format:

Returns tools in standard MCP tools/list format: - Simplified tool schema compatible with MCP clients - inputSchema formatted for direct MCP consumption - Metadata included in separate _meta field

Search Methods:ΒΆ

AI-Powered Search (ToolFinderLLM):
  • Uses Large Language Model to understand query semantics

  • Analyzes tool descriptions for intelligent matching

  • Provides relevance scoring and reasoning

  • Automatically used when available and use_advanced_search=True

Simple Keyword Search:
  • Basic text matching against tool names and descriptions

  • Case-insensitive substring matching

  • Used as fallback or when use_advanced_search=False

Error Handling:ΒΆ

  • Validates required parameters (query must be provided)

  • Handles search failures gracefully with informative messages

  • Provides detailed error context for debugging

Examples:ΒΆ

Basic protein analysis search: ```python params = {

β€œquery”: β€œprotein structure analysis”, β€œlimit”: 3

}ΒΆ

Category-filtered drug search: ```python params = {

β€œquery”: β€œdrug interactions”, β€œcategories”: [β€œChEMBL”, β€œfda_drug_label”], β€œlimit”: 5, β€œformat”: β€œmcp_standard”

}ΒΆ

_init_tool_finder()[source]ΒΆ

Initialize intelligent tool discovery system with automatic fallback.

This method sets up the tool finder infrastructure that powers AI-driven tool discovery. It implements a tiered approach, trying the most advanced search methods first and falling back to simpler methods if needed.

Initialization Strategy:ΒΆ

Phase 1 - Detection:

Scans loaded ToolUniverse tools to identify available search tools: - ToolFinderLLM: Advanced LLM-based semantic search - Tool_RAG: Embedding-based similarity search

Phase 2 - Loading (if needed):

If no search tools are found, attempts to load them: - Loads β€˜tool_finder_llm’ and β€˜tool_finder’ categories - Re-scans for available tools after loading

Phase 3 - Selection:

Selects the best available search method: 1. ToolFinderLLM (preferred - most intelligent) 2. Tool_RAG (fallback - good semantic understanding) 3. Simple keyword search (always available)

Tool Finder Capabilities:ΒΆ

ToolFinderLLM:
  • Uses GPT-4 or similar LLM for query understanding

  • Analyzes tool descriptions for semantic matching

  • Provides relevance scoring and selection reasoning

  • Handles complex, multi-faceted queries effectively

  • Best for: β€œFind tools to analyze protein-drug interactions in cancer research”

Tool_RAG:
  • Uses pre-computed embeddings for fast similarity search

  • Good semantic understanding without LLM overhead

  • Faster than LLM-based search for simple queries

  • Best for: β€œprotein analysis”, β€œdrug discovery”

Simple Search:
  • Basic keyword matching against names and descriptions

  • No dependencies, always available

  • Fast and reliable for exact term matches

  • Best for: β€œchembl”, β€œuniprot”, β€œfda”

Configuration Management:ΒΆ

Sets instance attributes: - tool_finder_available (bool): Whether advanced search is available - tool_finder_type (str): Type of search tool loaded (β€œToolFinderLLM” | β€œTool_RAG”)

Error Handling:ΒΆ

  • Handles missing dependencies gracefully

  • Provides informative console output about search capabilities

  • Ensures search functionality always works (via simple fallback)

  • Logs detailed information for debugging

Performance Considerations:ΒΆ

  • Tool loading only happens if search tools aren’t already available

  • Search tool detection is cached to avoid repeated scans

  • ToolFinderLLM requires network access and API keys

  • Tool_RAG requires embedding files but works offline

Dependencies:ΒΆ

  • ToolFinderLLM: Requires OpenAI API access or compatible endpoint

  • Tool_RAG: Requires sentence-transformers and embedding data

  • Simple search: No external dependencies

Execute tool search using the most appropriate search method available.

Simplified unified interface that leverages the consistent tool interfaces. All search tools now return JSON format directly.

Parameters:ΒΆ

querystr

Natural language query describing the desired tool functionality

categorieslist of str, optional

Tool categories to filter results by

limitint

Maximum number of tools to return

use_advanced_searchbool

Whether to prefer AI-powered search when available

search_methodstr, default β€˜auto’

Specific search method: β€˜auto’, β€˜llm’, β€˜embedding’, β€˜keyword’

Returns:ΒΆ

str

JSON string containing search results

_register_custom_mcp_methods()[source]ΒΆ

Register custom MCP protocol methods for enhanced functionality.

This method extends the standard MCP protocol by registering custom handlers for scientific tool discovery and search operations. It safely patches the FastMCP request handler to support additional methods while maintaining compatibility with standard MCP operations.

Custom Methods Registered:ΒΆ

  • tools/find: AI-powered tool discovery using natural language queries

  • tools/search: Alternative endpoint for tool search (alias for tools/find)

Implementation Details:ΒΆ

  • Preserves original FastMCP request handler for standard methods

  • Uses method interception pattern to handle custom methods first

  • Falls back to original handler for unrecognized methods

  • Implements proper error handling and JSON-RPC 2.0 compliance

Error Handling:ΒΆ

  • Gracefully handles missing request handlers

  • Logs warnings for debugging when handler patching fails

  • Ensures server continues to function even if custom methods fail to register

Notes:ΒΆ

This method is called automatically during SMCP initialization and should not be called manually. It uses a guard to prevent double-patching.

_select_search_tool(search_method: str, use_advanced_search: bool) str[source]ΒΆ

Select the appropriate search tool based on method and availability.

Returns:

Tool name to use for search

Return type:

str

_setup_smcp_tools()[source]ΒΆ

Initialize and configure SMCP-specific tools and features.

This method orchestrates the complete setup of SMCP functionality including ToolUniverse tool loading, validation, automatic tool exposure to the MCP interface, search functionality initialization, and utility tool registration.

The setup process is designed to be robust, handle various edge cases gracefully, and provide informative feedback about the configuration process. It implements intelligent fallback strategies to ensure functionality even when specific components are unavailable.

Setup Process Overview:ΒΆ

  1. Tool Loading Assessment: Check if ToolUniverse already has tools loaded to avoid unnecessary reloading and potential conflicts

  2. Category Validation: If specific categories are requested, validate them against available categories and provide helpful feedback for invalid ones

  3. Tool Loading Strategy: Load tools using the most appropriate method: - Category-specific loading for focused deployments - Full loading for comprehensive access - Graceful fallback when category loading fails

  4. Tool Exposure: Convert loaded ToolUniverse tools to MCP format with proper schema transformation and execution wrapping

  5. Search Setup: Initialize multi-tiered search capabilities including AI-powered and fallback methods

  6. Utility Registration: Add server management and diagnostic tools

Tool Loading Strategy:ΒΆ

Already Loaded Check: If ToolUniverse already contains loaded tools (len(all_tools) > 0), skip the loading phase to prevent duplication and preserve existing configuration. This supports scenarios where users pre-configure ToolUniverse instances.

Category-Specific Loading: When tool_categories is specified: - Validate each category against available tool categories - Log warnings for invalid categories with suggestions - Load only valid categories to optimize performance - Fall back to full loading if no valid categories remain

Full Loading (Default): When auto_expose_tools=True and no specific categories are requested, load all available tools to provide comprehensive functionality.

Graceful Fallback: If category-specific loading fails for any reason, automatically fall back to loading all tools to ensure basic functionality.

Tool Exposure Process:ΒΆ

Schema Transformation: - Convert ToolUniverse parameter schemas to MCP-compatible format - Handle complex parameter types and validation rules - Preserve documentation and examples where available

Execution Wrapping: - Create async wrappers for synchronous ToolUniverse tools - Implement proper error handling and result formatting - Use thread pool execution to prevent blocking

Safety Mechanisms: - Skip meta-tools (MCPAutoLoaderTool, MCPClientTool) that shouldn’t be exposed - Track exposed tools to prevent duplicates - Handle tool conversion failures gracefully without stopping entire process

Search Setup:ΒΆ

Multi-Tiered Search Architecture: 1. ToolFinderLLM (Primary): Cost-optimized AI-powered semantic understanding using LLM 2. Tool_RAG (Secondary): Embedding-based similarity search 3. Keyword Search (Fallback): Simple text matching, always available

Initialization Process: - Check for availability of advanced search tools in loaded tools - Attempt to load search tools if not already present - Configure search capabilities based on what’s available - Provide clear feedback about search capabilities

Search Tool Loading: Attempts to load tool_finder_llm and tool_finder categories which include: - ToolFinderLLM: Cost-optimized LLM-based intelligent tool discovery - Tool_RAG: Embedding-based semantic search - Supporting utilities and configuration tools

Error Handling:ΒΆ

Category Validation Errors: - Log specific invalid categories with available alternatives - Continue with valid categories only - Fall back to full loading if no valid categories

Tool Loading Errors: - Log detailed error information for debugging - Continue setup process with already loaded tools - Ensure server remains functional even with partial failures

Search Setup Errors: - Gracefully handle missing search tool dependencies - Fall back to simpler search methods automatically - Log informative messages about search capabilities

Tool Exposure Errors: - Handle individual tool conversion failures without stopping process - Log specific tool errors for debugging - Continue with remaining tools to maximize functionality

Performance Considerations:ΒΆ

  • Lazy Loading: Only load tools when needed to minimize startup time

  • Efficient Validation: Quick category checks before expensive operations

  • Parallel Processing: Use thread pools for tool conversion where possible

  • Memory Management: Efficient tool representation and storage

Diagnostic Output:ΒΆ

Provides informative logging throughout the setup process: ` Tools already loaded in ToolUniverse (356 tools), skipping reload Exposing 356 tools from ToolUniverse βœ… ToolFinderLLM (cost-optimized) available for advanced search Exposed tool: UniProt_get_entry_by_accession (type: uniprot) `

Notes:ΒΆ

  • This method is called automatically during SMCP initialization

  • Should not be called manually after server initialization

  • Setup is idempotent - can be called multiple times safely

  • All setup phases include comprehensive error handling

  • Performance scales with the number of tools being loaded and exposed

add_custom_tool(name: str, function: Callable, description: str | None = None, **kwargs)[source]ΒΆ

Add a custom Python function as an MCP tool to the SMCP server.

This method provides a convenient way to extend SMCP functionality with custom tools beyond those provided by ToolUniverse. Custom tools are automatically integrated into the MCP interface and can be discovered and used by clients alongside existing tools.

Parameters:ΒΆ

namestr

Unique name for the tool in the MCP interface. Should be descriptive and follow naming conventions (lowercase with underscores preferred). Examples: β€œanalyze_protein_sequence”, β€œcustom_data_processor”

functionCallable

Python function to execute when the tool is called. The function: - Can be synchronous or asynchronous - Should have proper type annotations for parameters - Should include a comprehensive docstring - Will be automatically wrapped for MCP compatibility

descriptionstr, optional

Human-readable description of the tool’s functionality. If provided, this will be set as the function’s __doc__ attribute. If None, the function’s existing docstring will be used.

**kwargs

Additional FastMCP tool configuration options: - parameter_schema: Custom JSON schema for parameters - return_schema: Schema for return values - examples: Usage examples for the tool - tags: Categorization tags

Returns:ΒΆ

Callable

The decorated function registered with FastMCP framework.

Usage Examples:ΒΆ

Simple synchronous function: ```python def analyze_text(text: str, max_length: int = 100) -> str:

β€˜β€™β€™Analyze text and return summary.’’’ return text[:max_length] + β€œβ€¦β€ if len(text) > max_length else text

server.add_custom_tool(

name=”text_analyzer”, function=analyze_text, description=”Analyze and summarize text content”

)ΒΆ

Asynchronous function with complex parameters: ```python async def process_data(

data: List[Dict[str, Any]], processing_type: str = β€œstandard”

) -> Dict[str, Any]:

β€˜β€™β€™Process scientific data with specified method.’’’ # Custom processing logic here return {β€œprocessed_items”: len(data), β€œtype”: processing_type}

server.add_custom_tool(

name=”data_processor”, function=process_data

)ΒΆ

Function with custom schema: ```python def calculate_score(values: List[float]) -> float:

β€˜β€™β€™Calculate composite score from values.’’’ return sum(values) / len(values) if values else 0.0

server.add_custom_tool(

name=”score_calculator”, function=calculate_score, parameter_schema={

β€œtype”: β€œobject”, β€œproperties”: {

β€œvalues”: {

β€œtype”: β€œarray”, β€œitems”: {β€œtype”: β€œnumber”}, β€œdescription”: β€œList of numeric values to process”

}

}, β€œrequired”: [β€œvalues”]

}

)ΒΆ

Integration with ToolUniverse:ΒΆ

Custom tools work seamlessly alongside ToolUniverse tools: - Appear in tool discovery searches - Follow same calling conventions - Include in server diagnostics and listings - Support all MCP client interaction patterns

Best Practices:ΒΆ

  • Use descriptive, unique tool names

  • Include comprehensive docstrings

  • Add proper type annotations for parameters

  • Handle errors gracefully within the function

  • Consider async functions for I/O-bound operations

  • Test tools thoroughly before deployment

Notes:ΒΆ

  • Custom tools are registered immediately upon addition

  • Tools can be added before or after server startup

  • Function signature determines parameter schema automatically

  • Custom tools support all FastMCP features and conventions

async close()[source]ΒΆ

Perform comprehensive cleanup and resource management during server shutdown.

This method ensures graceful shutdown of the SMCP server by properly cleaning up all resources, stopping background tasks, and releasing system resources. It’s designed to be safe to call multiple times and handles errors gracefully.

Cleanup Operations:ΒΆ

Thread Pool Shutdown: - Gracefully stops the ThreadPoolExecutor used for tool execution - Waits for currently running tasks to complete - Prevents new tasks from being submitted - Times out after reasonable wait period to prevent hanging

Resource Cleanup: - Releases any open file handles or network connections - Clears internal caches and temporary data - Stops background monitoring tasks - Frees memory allocated for tool configurations

Error Handling: - Continues cleanup even if individual operations fail - Logs cleanup errors for debugging without raising exceptions - Ensures critical resources are always released

Usage Patterns:ΒΆ

Automatic Cleanup (Recommended): ```python server = SMCP(β€œMy Server”) try:

server.run_simple() # Cleanup happens automatically on exit

except KeyboardInterrupt:

pass # run_simple() handles cleanup

```

Manual Cleanup: ```python server = SMCP(β€œMy Server”) try:

# Custom server logic here pass

finally:

await server.close() # Explicit cleanup

```

Context Manager Pattern: ```python async with SMCP(β€œMy Server”) as server:

# Server operations pass

# Cleanup happens automatically ```

Performance Considerations:ΒΆ

  • Cleanup operations are typically fast (< 1 second)

  • Thread pool shutdown may take longer if tasks are running

  • Network connections are closed immediately

  • Memory cleanup depends on garbage collection

Error Recovery:ΒΆ

  • Individual cleanup failures don’t stop the overall process

  • Critical errors are logged but don’t raise exceptions

  • Cleanup is idempotent - safe to call multiple times

  • System resources are guaranteed to be released

Notes:ΒΆ

  • This method is called automatically by run_simple() on shutdown

  • Can be called manually for custom server lifecycle management

  • Async method to properly handle async resource cleanup

  • Safe to call even if server hasn’t been fully initialized

run_simple(transport: Literal['stdio', 'http', 'sse'] = 'http', host: str = '0.0.0.0', port: int = 7000, **kwargs)[source]ΒΆ

Start the SMCP server with simplified configuration and automatic setup.

This method provides a convenient way to launch the SMCP server with sensible defaults for different deployment scenarios. It handles transport configuration, logging setup, and graceful shutdown automatically.

Parameters:ΒΆ

transport{β€œstdio”, β€œhttp”, β€œsse”}, default β€œhttp”

Communication transport protocol:

  • β€œstdio”: Standard input/output communication * Best for: Command-line tools, subprocess integration * Pros: Low overhead, simple integration * Cons: Single client, no network access

  • β€œhttp”: HTTP-based communication (streamable-http) * Best for: Web applications, REST API integration * Pros: Wide compatibility, stateless, scalable * Cons: Higher overhead than stdio

  • β€œsse”: Server-Sent Events over HTTP * Best for: Real-time applications, streaming responses * Pros: Real-time communication, web-compatible * Cons: Browser limitations, more complex

hoststr, default β€œ0.0.0.0”

Server bind address for HTTP/SSE transports: - β€œ0.0.0.0”: Listen on all network interfaces (default) - β€œ127.0.0.1”: localhost only (more secure) - Specific IP: Bind to particular interface

portint, default 7000

Server port for HTTP/SSE transports. Choose ports: - 7000-7999: Recommended range for SMCP servers - Above 1024: No root privileges required - Check availability: Ensure port isn’t already in use

**kwargs

Additional arguments passed to FastMCP’s run() method: - debug (bool): Enable debug logging - access_log (bool): Log client requests - workers (int): Number of worker processes (HTTP only)

Server Startup Process:ΒΆ

  1. Initialization Summary: Displays server configuration and capabilities

  2. Transport Setup: Configures selected communication method

  3. Service Start: Begins listening for client connections

  4. Graceful Shutdown: Handles interrupts and cleanup

Deployment Scenarios:ΒΆ

Development & Testing: `python server = SMCP(name="Dev Server") server.run_simple(transport="stdio")  # For CLI testing `

Local Web Service: `python server = SMCP(name="Local API") server.run_simple(transport="http", host="127.0.0.1", port=8000) `

Production Service: ```python server = SMCP(

name=”Production SMCP”, tool_categories=[β€œChEMBL”, β€œuniprot”, β€œopentarget”], max_workers=20

) server.run_simple(

transport=”http”, host=”0.0.0.0”, port=7000, workers=4

)ΒΆ

Real-time Applications: `python server = SMCP(name="Streaming API") server.run_simple(transport="sse", port=7001) `

Error Handling:ΒΆ

  • KeyboardInterrupt: Graceful shutdown on Ctrl+C

  • Port in Use: Clear error message with suggestions

  • Transport Errors: Detailed debugging information

  • Cleanup: Automatic resource cleanup on exit

Logging Output:ΒΆ

Provides informative startup messages: ` πŸš€ Starting SMCP server 'My Server'... πŸ“Š Loaded 356 tools from ToolUniverse πŸ” Search enabled: True 🌐 Server running on http://0.0.0.0:7000 `

Security Considerations:ΒΆ

  • Use host=”127.0.0.1” for local-only access

  • Configure firewall rules for production deployment

  • Consider HTTPS termination with reverse proxy

  • Validate all client inputs through MCP protocol

Performance Notes:ΒΆ

  • HTTP transport supports multiple concurrent clients

  • stdio transport is single-client but lower latency

  • SSE transport enables real-time bidirectional communication

  • Thread pool size affects concurrent tool execution capacity

class tooluniverse.SearchSPLTool(tool_config)[source]ΒΆ

Bases: BaseTool

Search SPL list based on multiple filter conditions (drug_name/ndc/rxcui/setid/published_date). Returns original DailyMed API JSON (including metadata + data array).

__init__(tool_config)[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.

class tooluniverse.SemanticScholarTool(tool_config, base_url='https://api.semanticscholar.org/graph/v1/paper/search')[source]ΒΆ

Bases: BaseTool

Tool to search for papers on Semantic Scholar including abstracts.

__init__(tool_config, base_url='https://api.semanticscholar.org/graph/v1/paper/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.

class tooluniverse.ToolFinderEmbedding(tool_config, tooluniverse)[source]ΒΆ

Bases: BaseTool

A tool finder model that uses RAG (Retrieval-Augmented Generation) to find relevant tools based on user queries using semantic similarity search.

This class leverages sentence transformers to encode tool descriptions and find the most relevant tools for a given query through embedding-based similarity matching.

rag_model_nameΒΆ

Name of the sentence transformer model for embeddings

Type:

str

rag_modelΒΆ

The loaded sentence transformer model

Type:

SentenceTransformer

tool_desc_embeddingΒΆ

Cached embeddings of tool descriptions

Type:

torch.Tensor

tool_nameΒΆ

List of available tool names

Type:

list

tool_embedding_pathΒΆ

Path to cached tool embeddings file

Type:

str

special_tools_nameΒΆ

List of special tools to exclude from results

Type:

list

tooluniverseΒΆ

Reference to the tool universe containing all tools

__init__(tool_config, tooluniverse)[source]ΒΆ

Initialize the ToolFinderEmbedding with configuration and RAG model.

Parameters:

tool_config (dict) – Configuration dictionary for the tool

find_tools(message=None, picked_tool_names=None, rag_num=5, return_call_result=False, categories=None)[source]ΒΆ

Find relevant tools based on a message or pre-selected tool names.

This method either uses RAG inference to find tools based on a message or processes a list of pre-selected tool names. It filters out special tools and returns tool prompts suitable for use in agent workflows.

Parameters:
  • message (str, optional) – Query message to find tools for. Required if picked_tool_names is None.

  • picked_tool_names (list, optional) – Pre-selected tool names to process. Required if message is None.

  • rag_num (int, optional) – Number of tools to return after filtering. Defaults to 5.

  • return_call_result (bool, optional) – If True, returns both prompts and tool names. Defaults to False.

  • categories (list, optional) – List of tool categories to filter by. Currently not implemented for embedding-based search.

Returns:

  • If return_call_result is False: Tool prompts as a formatted string

  • If return_call_result is True: Tuple of (tool_prompts, tool_names)

Return type:

str or tuple

Raises:

AssertionError – If both message and picked_tool_names are None

load_rag_model()[source]ΒΆ

Load the sentence transformer model for RAG-based tool retrieval.

Configures the model with appropriate sequence length and tokenizer settings for optimal performance in tool description encoding.

load_tool_desc_embedding(tooluniverse, include_names=None, exclude_names=None, include_categories=None, exclude_categories=None)[source]ΒΆ

Load or generate embeddings for tool descriptions from the tool universe.

This method either loads cached embeddings from disk or generates new ones by encoding all tool descriptions. Embeddings are cached to disk for faster subsequent loads. Memory is properly cleaned up after embedding generation to avoid OOM issues.

Parameters:
  • tooluniverse – ToolUniverse instance containing all available tools

  • include_names (list, optional) – Specific tool names to include

  • exclude_names (list, optional) – Tool names to exclude

  • include_categories (list, optional) – Tool categories to include

  • exclude_categories (list, optional) – Tool categories to exclude

rag_infer(query, top_k=5)[source]ΒΆ

Perform RAG inference to find the most relevant tools for a given query.

Uses semantic similarity between the query embedding and pre-computed tool embeddings to identify the most relevant tools.

Parameters:
  • query (str) – User query or description of desired functionality

  • top_k (int, optional) – Number of top tools to return. Defaults to 5.

Returns:

List of top-k tool names ranked by relevance to the query

Return type:

list

Raises:

SystemExit – If tool_desc_embedding is not loaded

run(arguments)[source]ΒΆ

Run the tool finder with given arguments following the standard tool interface.

This is the main entry point for using ToolFinderEmbedding as a standard tool. It extracts parameters from the arguments dictionary and delegates to find_tools().

Parameters:

arguments (dict) – Dictionary containing: - description (str, optional): Query message to find tools for (maps to β€˜message’) - limit (int, optional): Number of tools to return (maps to β€˜rag_num’). Defaults to 5. - picked_tool_names (list, optional): Pre-selected tool names to process - return_call_result (bool, optional): Whether to return both prompts and names. Defaults to False. - categories (list, optional): List of tool categories to filter by

class tooluniverse.ToolFinderKeyword(tool_config, tooluniverse=None)[source]ΒΆ

Bases: BaseTool

Advanced keyword-based tool finder that uses sophisticated text processing and TF-IDF scoring.

This class implements natural language processing techniques for tool discovery including: - Tokenization and normalization - Stop word removal - Basic stemming - TF-IDF relevance scoring - Semantic phrase matching

The search operates by parsing user queries to extract key terms, processing them through NLP pipelines, and matching against pre-built indices of tool metadata for efficient and relevant tool discovery.

STEMMING_RULES = [('ies', 'y'), ('ied', 'y'), ('ying', 'y'), ('ing', ''), ('ly', ''), ('ed', ''), ('ies', 'y'), ('ier', 'y'), ('iest', 'y'), ('s', ''), ('es', ''), ('er', ''), ('est', ''), ('tion', 't'), ('sion', 's'), ('ness', ''), ('ment', ''), ('able', ''), ('ible', ''), ('ful', ''), ('less', ''), ('ous', ''), ('ive', ''), ('al', ''), ('ic', ''), ('ize', ''), ('ise', ''), ('ate', ''), ('fy', ''), ('ify', '')]ΒΆ
STOP_WORDS = {'a', 'all', 'an', 'and', 'any', 'are', 'as', 'at', 'be', 'boy', 'but', 'by', 'came', 'can', 'day', 'did', 'do', 'down', 'each', 'find', 'for', 'from', 'get', 'had', 'has', 'have', 'he', 'how', 'if', 'in', 'is', 'it', 'its', 'long', 'made', 'may', 'new', 'no', 'now', 'number', 'of', 'old', 'on', 'part', 'said', 'see', 'that', 'the', 'their', 'they', 'this', 'time', 'to', 'two', 'up', 'use', 'was', 'way', 'what', 'which', 'who', 'will', 'with', 'your'}ΒΆ
__init__(tool_config, tooluniverse=None)[source]ΒΆ

Initialize the Advanced Keyword-based Tool Finder.

Parameters:
  • tool_config (dict) – Configuration dictionary for the tool

  • tooluniverse – Reference to the ToolUniverse instance containing all tools

_apply_stemming(word: str) str[source]ΒΆ

Apply basic stemming rules to reduce words to their root form.

Parameters:

word (str) – Word to stem

Returns:

Stemmed word

Return type:

str

_build_tool_index(tools: List[Dict]) None[source]ΒΆ

Build TF-IDF index for all tools to enable efficient relevance scoring.

Parameters:

tools (List[Dict]) – List of tool configurations

_calculate_exact_match_bonus(query: str, tool: Dict) float[source]ΒΆ

Calculate bonus score for exact matches in tool name or key phrases.

Parameters:
  • query (str) – Original query string

  • tool (Dict) – Tool configuration

Returns:

Exact match bonus score

Return type:

float

_calculate_tfidf_score(query_terms: List[str], tool_name: str) float[source]ΒΆ

Calculate TF-IDF relevance score for a tool given query terms.

Parameters:
  • query_terms (List[str]) – Processed query terms and phrases

  • tool_name (str) – Name of the tool to score

Returns:

TF-IDF relevance score

Return type:

float

_extract_parameter_text(parameter_schema: Dict) List[str][source]ΒΆ

Extract searchable text from parameter schema.

Parameters:

parameter_schema (Dict) – Tool parameter schema

Returns:

List of text elements from parameters

Return type:

List[str]

_extract_phrases(tokens: List[str], max_phrase_length: int = 3) List[str][source]ΒΆ

Extract meaningful phrases from tokens for better semantic matching.

Parameters:
  • tokens (List[str]) – Tokenized words

  • max_phrase_length (int) – Maximum length of phrases to extract

Returns:

List of phrases and individual tokens

Return type:

List[str]

Original JSON-based search implementation for backward compatibility.

Parameters:

arguments (dict) – Search arguments

Returns:

JSON string containing search results with relevance scores

Return type:

str

_tokenize_and_normalize(text: str) List[str][source]ΒΆ

Tokenize text and apply normalization including stop word removal and stemming.

Parameters:

text (str) – Input text to tokenize

Returns:

List of processed tokens

Return type:

List[str]

find_tools(message=None, picked_tool_names=None, rag_num=5, return_call_result=False, categories=None)[source]ΒΆ

Find relevant tools based on a message or pre-selected tool names.

This method matches the interface of other tool finders to ensure seamless replacement. It uses keyword-based search instead of embedding similarity.

Parameters:
  • message (str, optional) – Query message to find tools for. Required if picked_tool_names is None.

  • picked_tool_names (list, optional) – Pre-selected tool names to process. Required if message is None.

  • rag_num (int, optional) – Number of tools to return after filtering. Defaults to 5.

  • return_call_result (bool, optional) – If True, returns both prompts and tool names. Defaults to False.

  • categories (list, optional) – List of tool categories to filter by.

Returns:

  • If return_call_result is False: Tool prompts as a formatted string

  • If return_call_result is True: Tuple of (tool_prompts, tool_names)

Return type:

str or tuple

Raises:

AssertionError – If both message and picked_tool_names are None

run(arguments)[source]ΒΆ

Find tools using advanced keyword-based search with NLP processing and TF-IDF scoring.

This method provides a unified interface compatible with other tool finders.

Parameters:

arguments (dict) – Dictionary containing: - description (str): Search query string (unified parameter name) - categories (list, optional): List of categories to filter by - limit (int, optional): Maximum number of results to return (default: 10) - picked_tool_names (list, optional): Pre-selected tool names to process - return_call_result (bool, optional): Whether to return both prompts and names. Defaults to False.

Returns:

  • If return_call_result is False: Tool prompts as a formatted string

  • If return_call_result is True: Tuple of (tool_prompts, tool_names)

Return type:

str or tuple

class tooluniverse.ToolFinderLLM(tool_config, tooluniverse=None)[source]ΒΆ

Bases: BaseTool

LLM-based tool finder that uses natural language processing to select relevant tools.

This class leverages AgenticTool’s LLM capabilities to analyze tool descriptions and match them with user queries. It’s optimized for minimal context window cost by only sending essential information (tool name and description) to the LLM, providing an intelligent alternative to embedding-based similarity search.

Cost optimizations: - Only includes tool name and description in LLM prompt - Uses compact formatting to minimize token usage - Excludes unnecessary tool metadata and parameters - Implements caching to avoid repeated tool processing

__init__(tool_config, tooluniverse=None)[source]ΒΆ

Initialize the LLM-based Tool Finder.

Parameters:
  • tool_config (dict) – Configuration dictionary containing LLM settings and prompts

  • tooluniverse – Reference to the ToolUniverse instance containing all tools

_format_as_json(result, query, limit, categories, return_call_result)[source]ΒΆ

Format the find_tools result as a standardized JSON string.

Parameters:
  • result – Result from find_tools method (either string, list, or tuple)

  • query – Original search query

  • limit – Requested number of tools

  • categories – Requested categories filter

  • return_call_result – Whether return_call_result was True

Returns:

JSON formatted search results

Return type:

str

_format_tools_for_prompt(tools)[source]ΒΆ

Format tools for inclusion in the LLM prompt with minimal information to reduce context cost. Only includes name and description to minimize token usage.

Parameters:

tools (list) – List of tool dictionaries

Returns:

Compact formatted tool descriptions for the prompt

Return type:

str

_get_available_tools(force_refresh=False)[source]ΒΆ

Get available tools with their descriptions, with caching.

Parameters:

force_refresh (bool) – Whether to force refresh the cache

Returns:

List of tool dictionaries with names and descriptions

Return type:

list

_get_tool_selection_prompt()[source]ΒΆ

Get the prompt template for tool selection. Optimized for minimal token usage.

_init_agentic_tool()[source]ΒΆ

Initialize the underlying AgenticTool for LLM operations.

_prefilter_tools_by_keywords(available_tools, query, max_tools=100)[source]ΒΆ

Pre-filter tools using keyword matching to reduce context size before LLM processing.

Parameters:
  • available_tools (list) – All available tools

  • query (str) – User query

  • max_tools (int) – Maximum number of tools to send to LLM

Returns:

Filtered list of tools

Return type:

list

clear_cache()[source]ΒΆ

Clear the tool cache to force refresh on next access.

find_tools(message=None, picked_tool_names=None, rag_num=5, return_call_result=False, categories=None, return_list_only=None)[source]ΒΆ

Find relevant tools based on a message or pre-selected tool names.

This method matches the interface of the original ToolFinderEmbedding to ensure seamless replacement. It uses LLM-based selection instead of embedding similarity.

Parameters:
  • message (str, optional) – Query message to find tools for. Required if picked_tool_names is None.

  • picked_tool_names (list, optional) – Pre-selected tool names to process. Required if message is None.

  • rag_num (int, optional) – Number of tools to return after filtering. Defaults to 5.

  • return_call_result (bool, optional) – If True, returns both prompts and tool names. Defaults to False.

  • categories (list, optional) – List of tool categories to filter by. Applied before LLM selection.

  • return_list_only (bool, optional) – If True, returns only a list of tool specifications. Overrides other return options.

Returns:

  • If return_list_only is True: List of tool specifications

  • If return_call_result is False: Tool prompts as a formatted string

  • If return_call_result is True: Tuple of (tool_prompts, tool_names)

Return type:

str, tuple, or list

Raises:

AssertionError – If both message and picked_tool_names are None

find_tools_legacy(query, limit=5, include_reasoning=False, return_format='prompts')[source]ΒΆ

Legacy method for finding tools with different parameter names.

This provides backward compatibility for any code that might use β€˜query’ instead of β€˜description’.

find_tools_llm(query, limit=5, include_reasoning=False, categories=None)[source]ΒΆ

Find relevant tools using LLM-based selection.

Parameters:
  • query (str) – User query describing needed functionality

  • limit (int) – Maximum number of tools to return

  • include_reasoning (bool) – Whether to include selection reasoning

  • categories (list, optional) – List of tool categories to filter by

Returns:

Dictionary containing selected tools and metadata

Return type:

dict

get_tool_stats()[source]ΒΆ

Get statistics about available tools.

run(arguments)[source]ΒΆ

Run the tool finder with given arguments following the standard tool interface.

This method now returns JSON format by default to ensure consistency with other search tools and simplify integration with SMCP.

Parameters:

arguments (dict) – Dictionary containing: - description (str, optional): Query message to find tools for (maps to β€˜message’) - limit (int, optional): Number of tools to return (maps to β€˜rag_num’). Defaults to 5. - picked_tool_names (list, optional): Pre-selected tool names to process - return_call_result (bool, optional): Whether to return both prompts and names. Defaults to False. - return_format (str, optional): β€˜json’ (default) or β€˜legacy’ for old format - return_list_only (bool, optional): Whether to return only tool specifications as a list - categories (list, optional): List of tool categories to filter by

class tooluniverse.ToolUniverse(tool_files={'ChEMBL': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/chembl_tools.json', 'EFO': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/efo_tools.json', 'Enrichr': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/enrichr_tools.json', 'EuropePMC': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/europe_pmc_tools.json', 'HumanBase': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/humanbase_tools.json', 'OpenAlex': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/openalex_tools.json', 'admetai': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/admetai_tools.json', 'adverse_event': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/adverse_event_tools.json', 'agents': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/agentic_tools.json', 'alphafold': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/alphafold_tools.json', 'clinical_trials': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/clinicaltrials_gov_tools.json', 'compose': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/compose_tools.json', 'dailymed': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/dailymed_tools.json', 'dataset': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/dataset_tools.json', 'disease_target_score': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/disease_target_score_tools.json', 'embedding': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/embedding_tools.json', 'fda_drug_adverse_event': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/fda_drug_adverse_event_tools.json', 'fda_drug_label': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/fda_drug_labeling_tools.json', 'go': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/gene_ontology_tools.json', 'gwas': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/gwas_tools.json', 'hpa': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/hpa_tools.json', 'idmap': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/idmap_tools.json', 'mcp_auto_loader_boltz': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/boltz_tools.json', 'mcp_auto_loader_expert_feedback': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/expert_feedback_tools.json', 'mcp_auto_loader_txagent': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/txagent_client_tools.json', 'mcp_auto_loader_uspto_downloader': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/uspto_downloader_tools.json', 'medlineplus': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/medlineplus_tools.json', 'monarch': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/monarch_tools.json', 'odphp': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/odphp_tools.json', 'opentarget': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/opentarget_tools.json', 'output_summarization': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/output_summarization_tools.json', 'pubchem': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/pubchem_tools.json', 'pubtator': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/pubtator_tools.json', 'rcsb_pdb': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/rcsb_pdb_tools.json', 'reactome': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/reactome_tools.json', 'semantic_scholar': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/semantic_scholar_tools.json', 'software_bioinformatics': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/packages/bioinformatics_core_tools.json', 'software_cheminformatics': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/packages/cheminformatics_tools.json', 'software_earth_sciences': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/packages/earth_sciences_tools.json', 'software_genomics': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/packages/genomics_tools.json', 'software_image_processing': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/packages/image_processing_tools.json', 'software_machine_learning': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/packages/machine_learning_tools.json', 'software_neuroscience': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/packages/neuroscience_tools.json', 'software_physics_astronomy': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/packages/physics_astronomy_tools.json', 'software_scientific_computing': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/packages/scientific_computing_tools.json', 'software_single_cell': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/packages/single_cell_tools.json', 'software_structural_biology': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/packages/structural_biology_tools.json', 'software_visualization': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/packages/visualization_tools.json', 'special_tools': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/special_tools.json', 'tool_composition': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/tool_composition_tools.json', 'tool_finder': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/finder_tools.json', 'uniprot': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/uniprot_tools.json', 'url': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/url_fetch_tools.json', 'uspto': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/uspto_tools.json', 'xml': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/xml_tools.json'}, keep_default_tools=True, log_level: str | None = None, hooks_enabled: bool = False, hook_config: dict | None = None, hook_type: str | None = None)[source]ΒΆ

Bases: object

A comprehensive tool management system for loading, organizing, and executing various scientific and data tools.

The ToolUniverse class provides a centralized interface for managing different types of tools including GraphQL tools, RESTful APIs, MCP clients, and specialized scientific tools. It handles tool loading, filtering, caching, and execution.

all_toolsΒΆ

List of all loaded tool configurations

Type:

list

all_tool_dictΒΆ

Dictionary mapping tool names to their configurations

Type:

dict

tool_category_dictsΒΆ

Dictionary organizing tools by category

Type:

dict

tool_filesΒΆ

Dictionary mapping category names to their JSON file paths

Type:

dict

callable_functionsΒΆ

Cache of instantiated tool objects

Type:

dict

__init__(tool_files={'ChEMBL': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/chembl_tools.json', 'EFO': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/efo_tools.json', 'Enrichr': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/enrichr_tools.json', 'EuropePMC': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/europe_pmc_tools.json', 'HumanBase': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/humanbase_tools.json', 'OpenAlex': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/openalex_tools.json', 'admetai': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/admetai_tools.json', 'adverse_event': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/adverse_event_tools.json', 'agents': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/agentic_tools.json', 'alphafold': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/alphafold_tools.json', 'clinical_trials': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/clinicaltrials_gov_tools.json', 'compose': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/compose_tools.json', 'dailymed': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/dailymed_tools.json', 'dataset': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/dataset_tools.json', 'disease_target_score': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/disease_target_score_tools.json', 'embedding': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/embedding_tools.json', 'fda_drug_adverse_event': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/fda_drug_adverse_event_tools.json', 'fda_drug_label': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/fda_drug_labeling_tools.json', 'go': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/gene_ontology_tools.json', 'gwas': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/gwas_tools.json', 'hpa': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/hpa_tools.json', 'idmap': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/idmap_tools.json', 'mcp_auto_loader_boltz': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/boltz_tools.json', 'mcp_auto_loader_expert_feedback': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/expert_feedback_tools.json', 'mcp_auto_loader_txagent': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/txagent_client_tools.json', 'mcp_auto_loader_uspto_downloader': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/uspto_downloader_tools.json', 'medlineplus': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/medlineplus_tools.json', 'monarch': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/monarch_tools.json', 'odphp': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/odphp_tools.json', 'opentarget': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/opentarget_tools.json', 'output_summarization': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/output_summarization_tools.json', 'pubchem': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/pubchem_tools.json', 'pubtator': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/pubtator_tools.json', 'rcsb_pdb': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/rcsb_pdb_tools.json', 'reactome': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/reactome_tools.json', 'semantic_scholar': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/semantic_scholar_tools.json', 'software_bioinformatics': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/packages/bioinformatics_core_tools.json', 'software_cheminformatics': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/packages/cheminformatics_tools.json', 'software_earth_sciences': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/packages/earth_sciences_tools.json', 'software_genomics': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/packages/genomics_tools.json', 'software_image_processing': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/packages/image_processing_tools.json', 'software_machine_learning': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/packages/machine_learning_tools.json', 'software_neuroscience': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/packages/neuroscience_tools.json', 'software_physics_astronomy': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/packages/physics_astronomy_tools.json', 'software_scientific_computing': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/packages/scientific_computing_tools.json', 'software_single_cell': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/packages/single_cell_tools.json', 'software_structural_biology': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/packages/structural_biology_tools.json', 'software_visualization': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/packages/visualization_tools.json', 'special_tools': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/special_tools.json', 'tool_composition': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/tool_composition_tools.json', 'tool_finder': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/finder_tools.json', 'uniprot': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/uniprot_tools.json', 'url': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/url_fetch_tools.json', 'uspto': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/uspto_tools.json', 'xml': '/home/runner/work/ToolUniverse/ToolUniverse/src/tooluniverse/data/xml_tools.json'}, keep_default_tools=True, log_level: str | None = None, hooks_enabled: bool = False, hook_config: dict | None = None, hook_type: str | None = None)[source]ΒΆ

Initialize the ToolUniverse with tool file configurations.

Parameters:
  • tool_files (dict, optional) – Dictionary mapping category names to JSON file paths. Defaults to default_tool_files.

  • keep_default_tools (bool, optional) – Whether to keep default tools when custom tool_files are provided. Defaults to True.

  • log_level (str, optional) – Log level for this instance. Can be β€˜DEBUG’, β€˜INFO’, β€˜WARNING’, β€˜ERROR’, β€˜CRITICAL’. If None, uses global setting.

  • hooks_enabled (bool, optional) – Whether to enable output hooks. Defaults to False.

  • hook_config (dict, optional) – Configuration for hooks. If None, uses default config.

  • hook_type (str or list, optional) – Simple hook type selection. Can be β€˜SummarizationHook’, β€˜FileSaveHook’, or a list of both. Defaults to β€˜SummarizationHook’. If both hook_config and hook_type are provided, hook_config takes precedence.

_check_api_key_requirements(tool_config)[source]ΒΆ

Check if a tool’s required API keys are available. Also supports optional_api_keys where at least one key from the list must be available.

Parameters:

tool_config (dict) – Tool configuration containing optional β€˜required_api_keys’ and β€˜optional_api_keys’ fields

Returns:

(bool, list) - (all_keys_available, missing_keys)

Return type:

tuple

_create_hook_config_from_type(hook_type)[source]ΒΆ

Create hook configuration from simple hook_type parameter.

Parameters:

hook_type (str or list) – Hook type(s) to enable. Can be β€˜SummarizationHook’, β€˜FileSaveHook’, or a list of both.

Returns:

Generated hook configuration

Return type:

dict

_filter_and_deduplicate_tools(exclude_tools_set, include_tools_set, include_tool_types_set=None, exclude_tool_types_set=None)[source]ΒΆ

Filter tools based on inclusion/exclusion criteria and remove duplicates.

Parameters:
  • exclude_tools_set (set) – Set of tool names to exclude

  • include_tools_set (set or None) – Set of tool names to include (if None, include all)

  • include_tool_types_set (set or None) – Set of tool types to include (if None, include all)

  • exclude_tool_types_set (set or None) – Set of tool types to exclude (if None, exclude none)

_get_api_key(key_name: str)[source]ΒΆ

Get API key from environment variables or loaded sources

_load_auto_discovered_configs()[source]ΒΆ

Load auto-discovered configs from the decorator registry.

This method loads tool configurations that were registered automatically via the @register_tool decorator with config parameter.

_load_tool_names_from_file(file_path)[source]ΒΆ

Load tool names from a text file (one tool name per line).

Parameters:

file_path (str) – Path to the text file containing tool names

Returns:

List of tool names loaded from the file

Return type:

list

_load_tools_from_mcp_server(server_url: str, config: Dict[str, Any]) Dict[str, Any]ΒΆ

Load tools from a specific MCP server.

_process_mcp_auto_loaders()[source]ΒΆ

Process any MCPAutoLoaderTool instances to automatically discover and register MCP tools.

This method scans through all loaded tools for MCPAutoLoaderTool instances and runs their auto-discovery process to find and register MCP tools from configured servers. It handles async operations properly with cleanup and error handling.

Side Effects:
  • May add new tools to the tool registry

  • Prints debug information about the discovery process

  • Updates tool counts after MCP registration

_scan_all_json_files()[source]ΒΆ

Recursively scan all JSON files in the data directory and its subdirectories.

Returns:

(all_tools, all_tool_names) where all_tools is a list of tool configs

and all_tool_names is a set of tool names for deduplication

Return type:

tuple

_scan_predefined_files()[source]ΒΆ

Scan predefined tool files (original behavior).

Returns:

(all_tools, all_tool_names) where all_tools is a list of tool configs

and all_tool_names is a set of tool names for deduplication

Return type:

tuple

call_id_gen()[source]ΒΆ

Generate a random call ID for function calls.

Returns:

A random 9-character string composed of letters and digits.

Return type:

str

check_function_call(fcall_str, function_config=None, format='llama')[source]ΒΆ

Validate a function call against tool configuration.

This method checks if a function call is valid by verifying the function name exists and the arguments match the expected parameters.

Parameters:
  • fcall_str – Function call string or data to validate.

  • function_config (dict, optional) – Specific function configuration to validate against. If None, uses the loaded tool configuration.

  • format (str, optional) – Format type for parsing. Defaults to β€˜llama’.

Returns:

A tuple of (is_valid, message) where:
  • is_valid (bool): True if the function call is valid, False otherwise

  • message (str): Error message if invalid, empty if valid

Return type:

tuple

discover_mcp_tools(server_urls: List[str] | None = None, **kwargs) Dict[str, Any]ΒΆ

Discover available tools from MCP servers without loading them.

This method connects to MCP servers to discover what tools are available without actually registering them in ToolUniverse. Useful for exploration and selective tool loading.

Parameters:ΒΆ

server_urlslist of str, optional

List of MCP server URLs to discover from

**kwargs

Additional options: - timeout (int): Connection timeout (default: 30) - include_schemas (bool): Include tool parameter schemas (default: True)

Returns:ΒΆ

dict

Discovery results with tools organized by server

Examples:ΒΆ

```python tu = ToolUniverse()

# Discover what’s available discovery = tu.discover_mcp_tools([

])

# Show available tools for server, info in discovery[β€œservers”].items():

print(f”n{server}:”) for tool in info.get(β€œtools”, []):

print(f” - {tool[β€˜name’]}: {tool[β€˜description’]}”)

```

export_tool_names(output_file, category_filter=None)[source]ΒΆ

Export tool names to a text file (one per line).

Parameters:
  • output_file (str) – Path to the output file

  • category_filter (list, optional) – List of categories to filter by

extract_function_call_json(lst, return_message=False, verbose=True, format='llama')[source]ΒΆ

Extract function call JSON from input data.

This method delegates to the utility function extract_function_call_json.

Parameters:
  • lst – Input data containing function call information.

  • return_message (bool, optional) – Whether to return message along with JSON. Defaults to False.

  • verbose (bool, optional) – Whether to enable verbose output. Defaults to True.

  • format (str, optional) – Format type for extraction. Defaults to β€˜llama’.

Returns:

Function call JSON, optionally with message if return_message is True.

Return type:

dict or tuple

filter_tool_lists(tool_name_list, tool_desc_list, include_names=None, exclude_names=None, include_categories=None, exclude_categories=None)[source]ΒΆ

Directly filter tool name and description lists based on names and/or categories.

This method takes existing tool name and description lists and filters them according to the specified criteria using the select_tools method for category-based filtering.

Parameters:
  • tool_name_list (list) – List of tool names to filter.

  • tool_desc_list (list) – List of tool descriptions to filter (must correspond to tool_name_list).

  • include_names (list, optional) – List of tool names to include.

  • exclude_names (list, optional) – List of tool names to exclude.

  • include_categories (list, optional) – List of categories to include.

  • exclude_categories (list, optional) – List of categories to exclude.

Returns:

A tuple containing (filtered_tool_name_list, filtered_tool_desc_list).

Return type:

tuple

find_tools_by_pattern(pattern, search_in='name', case_sensitive=False)[source]ΒΆ

Find tools matching a pattern in their name or description.

Parameters:
  • pattern (str) – Pattern to search for

  • search_in (str) – Where to search - β€˜name’, β€˜description’, or β€˜both’

  • case_sensitive (bool) – Whether search should be case sensitive

Returns:

List of matching tool configurations

Return type:

list

force_full_discovery()[source]ΒΆ

Force full tool discovery, importing all tool modules immediately.

This can be useful when you need to ensure all tools are available immediately, bypassing lazy loading.

Returns:

Updated tool registry with all discovered tools

Return type:

dict

generate_env_template(all_missing_keys, output_file: str = '.env.template')[source]ΒΆ

Generate a template .env file with all required API keys

get_available_tools(category_filter=None, name_only=True)[source]ΒΆ

Get available tools, optionally filtered by category.

Parameters:
  • category_filter (list, optional) – List of categories to filter by

  • name_only (bool) – If True, return only tool names; if False, return full configs

Returns:

List of tool names or tool configurations

Return type:

list

get_lazy_loading_status()[source]ΒΆ

Get information about lazy loading status and available tools.

Returns:

Dictionary with lazy loading status and tool counts

Return type:

dict

get_one_tool_by_one_name(tool_name, return_prompt=True)[source]ΒΆ

Retrieve a single tool specification by name, optionally prepared for prompting.

This is a convenience method that calls get_one_tool_by_one_name.

Parameters:
  • tool_name (str) – Name of the tool to retrieve.

  • return_prompt (bool, optional) – If True, returns tool prepared for prompting. If False, returns full tool configuration. Defaults to True.

Returns:

Tool configuration if found, None otherwise.

Return type:

dict or None

get_tool_by_name(tool_names, format='default')[source]ΒΆ

Retrieve tool configurations by their names.

Parameters:
  • tool_names (list) – List of tool names to retrieve.

  • format (str, optional) – Output format. Options: β€˜default’, β€˜openai’. If β€˜openai’, returns OpenAI function calling format. Defaults to β€˜default’.

Returns:

List of tool configurations for the specified names.

Tools not found will be reported but not included in the result.

Return type:

list

get_tool_description(tool_name)[source]ΒΆ

Get the description of a tool by its name.

This is a convenience method that calls get_one_tool_by_one_name.

Parameters:

tool_name (str) – Name of the tool.

Returns:

Tool configuration if found, None otherwise.

Return type:

dict or None

get_tool_specification_by_names(tool_names, format='default')[source]ΒΆ

Retrieve tool specifications by their names using tool_specification method.

Parameters:
  • tool_names (list) – List of tool names to retrieve.

  • format (str, optional) – Output format. Options: β€˜default’, β€˜openai’. If β€˜openai’, returns OpenAI function calling format. Defaults to β€˜default’.

Returns:

List of tool specifications for the specified names.

Tools not found will be reported but not included in the result.

Return type:

list

get_tool_type_by_name(tool_name)[source]ΒΆ

Get the type of a tool by its name.

Parameters:

tool_name (str) – Name of the tool.

Returns:

The type of the tool.

Return type:

str

Raises:

KeyError – If the tool name is not found in loaded tools.

get_tool_types()[source]ΒΆ

Get the types of tools available in the tool files.

Returns:

A list of tool type names (category keys).

Return type:

list

init_tool(tool=None, tool_name=None, add_to_cache=True)[source]ΒΆ

Initialize a tool instance from configuration or name.

This method creates a new tool instance using the tool type mappings and optionally caches it for future use. It handles special cases like the OpentargetToolDrugNameMatch which requires additional dependencies.

Parameters:
  • tool (dict, optional) – Tool configuration dictionary. Either this or tool_name must be provided.

  • tool_name (str, optional) – Name of the tool type to initialize. Either this or tool must be provided.

  • add_to_cache (bool, optional) – Whether to cache the initialized tool. Defaults to True.

Returns:

Initialized tool instance.

Return type:

object

Raises:

KeyError – If the tool type is not found in tool_type_mappings.

list_built_in_tools(mode='config', scan_all=False)[source]ΒΆ

List all built-in tool categories and their statistics with different modes.

This method provides a comprehensive overview of all available tools in the ToolUniverse, organized by categories. It reads directly from the default tool files to gather statistics, so it works even before calling load_tools().

Parameters:
  • mode (str, optional) – Organization mode for tools. Defaults to β€˜config’. - β€˜config’: Organize by config file categories (original behavior) - β€˜type’: Organize by tool types (implementation classes) - β€˜list_name’: Return a list of all tool names - β€˜list_spec’: Return a list of all tool specifications

  • scan_all (bool, optional) – Whether to scan all JSON files in data directory recursively. If True, scans all JSON files in data/ and its subdirectories. If False (default), uses predefined tool file mappings.

Returns:

  • For β€˜config’ and β€˜type’ modes: A dictionary containing tool statistics

  • For β€˜list_name’ mode: A list of all tool names

  • For β€˜list_spec’ mode: A list of all tool specifications

Return type:

dict or list

Example

>>> tool_universe = ToolUniverse()
>>> # Group by config file categories (predefined files only)
>>> stats = tool_universe.list_built_in_tools(mode='config')
>>> # Scan all JSON files in data directory recursively
>>> stats = tool_universe.list_built_in_tools(mode='config', scan_all=True)
>>> # Get all tool names from all JSON files
>>> tool_names = tool_universe.list_built_in_tools(mode='list_name', scan_all=True)

Note

  • This method reads directly from tool files and works without calling load_tools()

  • Tools are deduplicated across categories, so the same tool won’t be counted multiple times

  • The summary is automatically printed to console when this method is called (except for list_name and list_spec modes)

  • When scan_all=True, all JSON files in data/ and subdirectories are scanned

list_mcp_connections() Dict[str, Any]ΒΆ

List all active MCP connections and loaded tools.

Returns:ΒΆ

dict

Information about MCP connections, auto-loaders, and loaded tools

Examples:ΒΆ

```python tu = ToolUniverse() tu.load_mcp_tools([”http://localhost:8001”])

connections = tu.list_mcp_connections() print(f”Active MCP connections: {len(connections[β€˜connections’])}”) ```

load_mcp_tools(server_urls: List[str] | None = None, **kwargs)ΒΆ

Load MCP tools from remote servers into this ToolUniverse instance.

This method automatically discovers tools from MCP servers and registers them as ToolUniverse tools, enabling seamless usage of remote capabilities.

Parameters:ΒΆ

server_urlslist of str, optional

List of MCP server URLs to load tools from. Examples:

If None, attempts to discover from local MCP tool registry.

**kwargs

Additional configuration options:

  • tool_prefix (str): Prefix for loaded tool names (default: β€œmcp_”)

  • timeout (int): Connection timeout in seconds (default: 30)

  • auto_register (bool): Whether to auto-register discovered tools (default: True)

  • selected_tools (list): Specific tools to load from each server

  • categories (list): Tool categories to filter by

Returns:ΒΆ

dict

Summary of loaded tools with counts and any errors encountered.

Examples:ΒΆ

Load from specific servers: ```python tu = ToolUniverse()

# Load tools from multiple MCP servers result = tu.load_mcp_tools([

β€œhttp://localhost:8001”, # Local analysis server β€œhttp://ml-server:8002”, # Remote ML server β€œws://realtime:9000” # WebSocket server

])

print(f”Loaded {result[β€˜total_tools’]} tools from {result[β€˜servers_connected’]} servers”) ```

Load with custom configuration: ```python tu.load_mcp_tools(

server_urls=[”http://localhost:8001”], tool_prefix=”analysis_”, timeout=60, selected_tools=[β€œprotein_analysis”, β€œdrug_interaction”]

)ΒΆ

Auto-discovery from local registry: `python # If you have registered MCP tools locally, auto-discover their servers tu.load_mcp_tools()  # Uses servers from mcp_tool_registry `

load_tools(tool_type=None, exclude_tools=None, exclude_categories=None, include_tools=None, tool_config_files=None, tools_file=None, include_tool_types=None, exclude_tool_types=None)[source]ΒΆ

Loads tool definitions from JSON files into the instance’s tool registry.

If tool_type is None, loads all available tool categories from self.tool_files. Otherwise, loads only the specified tool categories.

After loading, deduplicates tools by their β€˜name’ field and updates the internal tool list. Also refreshes the tool name and description mapping.

Parameters:
  • tool_type (list, optional) – List of tool category names to load. If None, loads all categories.

  • exclude_tools (list, optional) – List of specific tool names to exclude from loading.

  • exclude_categories (list, optional) – List of tool categories to exclude from loading.

  • include_tools (list or str, optional) – List of specific tool names to include, or path to a text file containing tool names (one per line). If provided, only these tools will be loaded regardless of categories.

  • tool_config_files (dict, optional) – Additional tool configuration files to load. Format: {β€œcategory_name”: β€œ/path/to/config.json”}

  • tools_file (str, optional) – Path to a text file containing tool names to include (one per line). Alternative to include_tools when providing a file path.

  • include_tool_types (list, optional) – List of tool types to include (e.g., [β€œOpenTarget”, β€œChEMBLTool”]). If provided, only tools with these types will be loaded.

  • exclude_tool_types (list, optional) – List of tool types to exclude (e.g., [β€œToolFinderEmbedding”]). Tools with these types will be excluded.

Side Effects:
  • Updates self.all_tools with loaded and deduplicated tools.

  • Updates self.tool_category_dicts with loaded tools per category.

  • Calls self.refresh_tool_name_desc() to update tool name/description mapping.

  • Prints the number of tools before and after loading.

Examples

# Load specific tools by name tu.load_tools(include_tools=[β€œUniProt_get_entry_by_accession”, β€œChEMBL_get_molecule_by_chembl_id”])

# Load tools from a file tu.load_tools(tools_file=”/path/to/tool_names.txt”)

# Include only specific tool types tu.load_tools(include_tool_types=[β€œOpenTarget”, β€œChEMBLTool”])

# Exclude specific tool types tu.load_tools(exclude_tool_types=[β€œToolFinderEmbedding”, β€œUnknown”])

# Load additional config files tu.load_tools(tool_config_files={β€œcustom_tools”: β€œ/path/to/custom_tools.json”})

# Combine multiple options tu.load_tools(

tool_type=[β€œuniprot”, β€œChEMBL”], exclude_tools=[β€œproblematic_tool”], exclude_tool_types=[β€œUnknown”], tool_config_files={β€œcustom”: β€œ/path/to/custom.json”}

)

load_tools_from_names_list(tool_names, clear_existing=True)[source]ΒΆ

Load only specific tools by their names.

Parameters:
  • tool_names (list) – List of tool names to load

  • clear_existing (bool) – Whether to clear existing tools first

Returns:

Number of tools successfully loaded

Return type:

int

prepare_one_tool_prompt(tool)[source]ΒΆ

Prepare a single tool configuration for prompt usage by filtering to essential keys.

Parameters:

tool (dict) – Tool configuration dictionary.

Returns:

Tool configuration with only essential keys for prompting.

Return type:

dict

prepare_tool_examples(tool_list)[source]ΒΆ

Prepare tool configurations for example usage by keeping extended set of keys.

This method is similar to prepare_tool_prompts but includes additional keys useful for examples and documentation.

Parameters:

tool_list (list) – List of tool configuration dictionaries.

Returns:

Deep copy of tool list with only example-relevant keys.

Return type:

list

prepare_tool_prompts(tool_list)[source]ΒΆ

Prepare a list of tool configurations for prompt usage.

Parameters:

tool_list (list) – List of tool configuration dictionaries.

Returns:

List of tool configurations with only essential keys for prompting.

Return type:

list

refresh_tool_name_desc(enable_full_desc=False, include_names=None, exclude_names=None, include_categories=None, exclude_categories=None)[source]ΒΆ

Refresh the tool name and description mappings with optional filtering.

This method rebuilds the internal tool dictionary and generates filtered lists of tool names and descriptions based on the provided filter criteria.

Parameters:
  • enable_full_desc (bool, optional) – If True, includes full tool JSON as description. If False, uses β€œname: description” format. Defaults to False.

  • include_names (list, optional) – List of tool names to include.

  • exclude_names (list, optional) – List of tool names to exclude.

  • include_categories (list, optional) – List of categories to include.

  • exclude_categories (list, optional) – List of categories to exclude.

Returns:

A tuple containing (tool_name_list, tool_desc_list) after filtering.

Return type:

tuple

register_custom_tool(tool_class, tool_name=None, tool_config=None)[source]ΒΆ

Register a custom tool class at runtime.

Parameters:
  • tool_class – The tool class to register

  • tool_name (str, optional) – Name to register under. Uses class name if None.

  • tool_config (dict, optional) – Tool configuration dictionary to add to all_tools

Returns:

The name the tool was registered under

Return type:

str

remove_keys(tool_list, invalid_keys)[source]ΒΆ

Remove specified keys from a list of tool configurations.

Parameters:
  • tool_list (list) – List of tool configuration dictionaries.

  • invalid_keys (list) – List of keys to remove from each tool configuration.

Returns:

Deep copy of tool list with specified keys removed.

Return type:

list

return_all_loaded_tools()[source]ΒΆ

Return a deep copy of all loaded tools.

Returns:

A deep copy of the all_tools list to prevent external modification.

Return type:

list

run(fcall_str, return_message=False, verbose=True, format='llama')[source]ΒΆ

Execute function calls from input string or data.

This method parses function call data, validates it, and executes the corresponding tools. It supports both single function calls and multiple function calls in a list.

Parameters:
  • fcall_str – Input string or data containing function call information.

  • return_message (bool, optional) – Whether to return formatted messages. Defaults to False.

  • verbose (bool, optional) – Whether to enable verbose output. Defaults to True.

  • format (str, optional) – Format type for parsing. Defaults to β€˜llama’.

Returns:

  • For multiple function calls: List of formatted messages with tool responses

  • For single function call: Direct result from the tool

  • None: If the input is not a valid function call

Return type:

list or str or None

run_one_function(function_call_json)[source]ΒΆ

Execute a single function call.

This method validates the function call, initializes the tool if necessary, and executes it with the provided arguments. If hooks are enabled, it also applies output hooks to process the result.

Parameters:

function_call_json (dict) – Dictionary containing function name and arguments.

Returns:

Result from the tool execution, or error message if validation fails.

Return type:

str or dict

select_tools(include_names=None, exclude_names=None, include_categories=None, exclude_categories=None)[source]ΒΆ

Select tools based on tool names and/or categories (tool_files keys).

Parameters:
  • include_names (list, optional) – List of tool names to include. If None, include all.

  • exclude_names (list, optional) – List of tool names to exclude.

  • include_categories (list, optional) – List of categories (tool_files keys) to include. If None, include all.

  • exclude_categories (list, optional) – List of categories (tool_files keys) to exclude.

Returns:

List of selected tool configurations.

Return type:

list

toggle_hooks(enabled: bool)[source]ΒΆ

Enable or disable output hooks globally.

This method allows runtime control of the hook system. When enabled, it initializes the HookManager if not already present. When disabled, it deactivates the HookManager.

Parameters:

enabled (bool) – True to enable hooks, False to disable

tool_specification(tool_name, return_prompt=False, format='default')[source]ΒΆ

Retrieve a single tool configuration by name.

Parameters:
  • tool_name (str) – Name of the tool to retrieve.

  • return_prompt (bool, optional) – If True, returns tool prepared for prompting. If False, returns full tool configuration. Defaults to False.

  • format (str, optional) – Output format. Options: β€˜default’, β€˜openai’. If β€˜openai’, returns OpenAI function calling format. Defaults to β€˜default’.

Returns:

Tool configuration if found, None otherwise.

Return type:

dict or None

tool_to_str(tool_list)[source]ΒΆ

Convert a list of tool configurations to a formatted string.

Parameters:

tool_list (list) – List of tool configuration dictionaries.

Returns:

JSON-formatted string representation of the tools, with each tool

separated by double newlines.

Return type:

str

class tooluniverse.URLHTMLTagTool(tool_config)[source]ΒΆ

Bases: BaseTool

Fetches a webpage and extracts the content of a specified HTML tag. Expects: {β€œurl”: β€œhttps://…”} The tag to extract is specified in the tool’s configuration. The tag to extract is specified in the tool’s configuration. Optional: {β€œtimeout”: <seconds>} (default 20) Returns: {β€œcontent”: β€œ<extracted content>”} or {β€œerror”: β€œβ€¦β€}

__init__(tool_config)[source]ΒΆ
run(arguments: dict)[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.

class tooluniverse.URLToPDFTextTool(tool_config)[source]ΒΆ

Bases: BaseTool

Loads a webpage (with JavaScript), exports it as a PDF, and extracts text. Expects: {β€œurl”: β€œhttps://…”} Optional: {β€œtimeout”: <seconds>} (default 30) Returns: {β€œtext”: β€œ<extracted text>”} or {β€œerror”: β€œβ€¦β€}

__init__(tool_config)[source]ΒΆ
_ensure_playwright_browsers(browsers=('chromium',), with_deps: bool = False, timeout_seconds: int = 600)[source]ΒΆ

Ensure Playwright browser binaries are installed.

Returns:

None on success, or an error string on failure.

run(arguments: dict)[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.

class tooluniverse.USPTOOpenDataPortalTool(tool_config, api_key=None, base_url='https://api.uspto.gov/api/v1')[source]ΒΆ

Bases: BaseTool

A tool for interacting with the USPTO Open Data Portal API to search for and retrieve patent information. The run method dynamically constructs API requests based on the provided tool configuration.

__init__(tool_config, api_key=None, base_url='https://api.uspto.gov/api/v1')[source]ΒΆ

Initializes the USPTOOpenDataPortalTool.

Parameters:
  • tool_config – The configuration for the specific tool being run.

  • api_key – Your USPTO Open Data Portal API key.

  • base_url – The base URL for the USPTO API.

assign_by_path(d, path, value)[source]ΒΆ

Create nested dicts for a dot‑path and set the final key to value.

get_by_path(d, keys)[source]ΒΆ

Safely navigate nested dicts by a list of keys.

prune_item(item, return_fields)[source]ΒΆ
run(arguments)[source]ΒΆ

Runs the specified tool by constructing and executing an API call based on the tool’s configuration.

Parameters:

arguments – A dictionary of arguments for the tool, matching the parameters in the tool definition.

Returns:

The result of the API call, either as a dictionary (for JSON) or a string (for CSV).

class tooluniverse.UniProtRESTTool(tool_config: Dict)[source]ΒΆ

Bases: BaseTool

__init__(tool_config: Dict)[source]ΒΆ
_build_url(args: Dict[str, Any]) str[source]ΒΆ
_extract_data(data: Dict, extract_path: str) Any[source]ΒΆ

Custom data extraction with support for filtering

get_disease_variants_by_accession(accession: str) Any[source]ΒΆ
get_entry_by_accession(accession: str) Any[source]ΒΆ
get_function_by_accession(accession: str) Any[source]ΒΆ
get_names_taxonomy_by_accession(accession: str) Any[source]ΒΆ
get_ptm_processing_by_accession(accession: str) Any[source]ΒΆ
get_sequence_isoforms_by_accession(accession: str) Any[source]ΒΆ
get_subcellular_location_by_accession(accession: str) Any[source]ΒΆ
run(arguments: Dict[str, Any]) Any[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.

class tooluniverse.XMLDatasetTool(tool_config: Dict[str, Any])[source]ΒΆ

Bases: BaseTool

Tool to search and filter XML datasets that are organized as a collection of searchable records (e.g., dataset of medical subjects or drug descriptions). Supports user-friendly queries without requiring XPath knowledge.

__init__(tool_config: Dict[str, Any])[source]ΒΆ
_extract_field_value(element: Element, xpath_expr: str) str[source]ΒΆ

Extract field value using XPath expression.

_extract_record_data(record_element: Element) Dict[str, Any][source]ΒΆ

Extract data from a record element with caching.

_filter(arguments: Dict[str, Any]) Dict[str, Any][source]ΒΆ

Filter records based on field criteria.

_find_matches(record_data: Dict[str, Any], search_query: str, search_fields: List[str], case_sensitive: bool, exact_match: bool) List[str][source]ΒΆ

Find matching fields in a record.

_get_all_records_data() List[Dict[str, Any]][source]ΒΆ

Get all records data with caching.

_get_dataset_path() str | None[source]ΒΆ

Get the path to the XML dataset.

_get_filter_description(field: str, condition: str, value: str) str[source]ΒΆ

Get human-readable filter description.

_get_filter_function(condition: str, value: str)[source]ΒΆ

Get the appropriate filter function for the condition.

_get_searchable_value(record_data: Dict[str, Any], field: str, case_sensitive: bool) str[source]ΒΆ

Get searchable string value for a field.

_is_match(field_value: str, search_query: str, exact_match: bool) bool[source]ΒΆ

Check if field value matches search query.

_load_dataset() None[source]ΒΆ

Load and parse the XML dataset.

Search records by text content across multiple fields.

get_dataset_info() Dict[str, Any][source]ΒΆ

Get comprehensive information about the loaded XML dataset.

run(arguments: Dict[str, Any]) Dict[str, Any][source]ΒΆ

Main entry point for the tool.

tooluniverse.create_smcp_server(name: str = 'SMCP Server', tool_categories: List[str] | None = None, search_enabled: bool = True, **kwargs) SMCP[source]ΒΆ

Create a configured SMCP server with common defaults and best practices.

This convenience function simplifies SMCP server creation by providing sensible defaults for common use cases while still allowing full customization through additional parameters.

Parameters:ΒΆ

namestr, default β€œSMCP Server”

Human-readable server name used in logs and server identification. Choose descriptive names like: - β€œScientific Research API” - β€œDrug Discovery Server” - β€œProteomics Analysis Service”

tool_categorieslist of str, optional

Specific ToolUniverse categories to load. If None, loads all available tools (350+ tools). Common category combinations:

Scientific Research: [β€œChEMBL”, β€œuniprot”, β€œopentarget”, β€œpubchem”, β€œhpa”]

Drug Discovery: [β€œChEMBL”, β€œfda_drug_label”, β€œclinical_trials”, β€œpubchem”]

Literature Analysis: [β€œEuropePMC”, β€œsemantic_scholar”, β€œpubtator”, β€œagents”]

Minimal Setup: [β€œtool_finder_llm”, β€œspecial_tools”]

search_enabledbool, default True

Enable AI-powered tool discovery via tools/find method. Recommended to keep enabled unless you have specific performance requirements or want to minimize dependencies.

**kwargs

Additional SMCP configuration options:

  • tooluniverse_config: Pre-configured ToolUniverse instance

  • auto_expose_tools (bool, default True): Auto-expose ToolUniverse tools

  • max_workers (int, default 5): Thread pool size for tool execution

  • Any FastMCP server options (debug, logging, etc.)

Returns:ΒΆ

SMCP

Fully configured SMCP server instance ready to run.

Usage Examples:ΒΆ

Quick Start (all tools): `python server = create_smcp_server("Research Server") server.run_simple() `

Focused Server (specific domains): ```python server = create_smcp_server(

name=”Drug Discovery API”, tool_categories=[β€œChEMBL”, β€œfda_drug_label”, β€œclinical_trials”], max_workers=10

) server.run_simple(port=8000) ```

Custom Configuration: ```python server = create_smcp_server(

name=”High-Performance Server”, search_enabled=True, max_workers=20, debug=True

) server.run_simple(transport=”http”, host=”0.0.0.0”, port=7000) ```

Pre-configured ToolUniverse: ```python tu = ToolUniverse() tu.load_tools(tool_type=[β€œuniprot”, β€œChEMBL”]) server = create_smcp_server(

name=”Protein-Drug Server”, tooluniverse_config=tu, search_enabled=True

)ΒΆ

Benefits of Using This Function:ΒΆ

  • Simplified Setup: Reduces boilerplate code for common configurations

  • Best Practices: Applies recommended settings automatically

  • Consistent Naming: Encourages good server naming conventions

  • Future-Proof: Will include new recommended defaults in future versions

  • Documentation: Provides clear examples and guidance

Equivalent Manual Configuration:ΒΆ

This function is equivalent to: ```python server = SMCP(

name=name, tool_categories=tool_categories, search_enabled=search_enabled, auto_expose_tools=True, max_workers=5, **kwargs

)ΒΆ

When to Use Manual Configuration:ΒΆ

  • Need precise control over all initialization parameters

  • Using custom ToolUniverse configurations

  • Implementing custom MCP methods or tools

  • Advanced deployment scenarios with specific requirements

tooluniverse.get_tool_registry()[source]ΒΆ

Get a copy of the current tool registry.

tooluniverse.register_tool(tool_type_name=None, config=None)[source]ΒΆ

Decorator to automatically register tool classes and their configs.

Usage:

@register_tool(β€˜CustomToolName’, config={…}) class MyTool:

pass

SubpackagesΒΆ

SubmodulesΒΆ