bc_get_available_ontologies
Retrieve a comprehensive list of available ontologies from the Ontology Lookup Service (OLS), including names, descriptions, and metadata, to facilitate ontology discovery for biomedical AI applications.
Instructions
Query the Ontology Lookup Service (OLS) for all available ontologies.
This function retrieves a list of all ontologies available in OLS, including their names, descriptions, and metadata. Use this function first to discover which ontologies are available before using other search functions.
Returns: dict: Dictionary containing available ontologies and their information or error message
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- Handler function decorated with @core_mcp.tool(), implementing the logic to fetch all available ontologies from OLS API, paginating results and formatting the response. This is the core implementation of the tool, registered via FastMCP with prefix 'BC' likely making the tool name 'bc_get_available_ontologies'.@core_mcp.tool() def get_available_ontologies() -> Dict[str, Any]: """Query OLS for all available ontologies with their metadata. Use this first to discover available ontologies. Returns: dict: Ontologies list with id, name, description, prefix, homepage, number of terms, status or error message. """ url = "https://www.ebi.ac.uk/ols4/api/v2/ontologies" try: # First request to get total count params = { "size": "100", # OLS now limits to 100 elements per page "page": "0", "lang": "en", } response = requests.get(url, params=params) response.raise_for_status() data = response.json() if not data.get("elements"): return {"error": "No ontologies found"} ontologies: list[Dict[str, Any]] = [] total_elements = data.get("totalElements", 0) total_pages = (total_elements + 99) // 100 # Ceiling division # Iterate through all pages for page in range(total_pages): params["page"] = str(page) response = requests.get(url, params=params) response.raise_for_status() data = response.json() # Extract ontology information page_ontologies = [ { "id": element.get("ontologyId", ""), "name": element.get("label", ""), "description": element.get("definition", ""), "prefix": element.get("ontologyPrefix", ""), "base_uri": element.get("baseUri", ""), "homepage": element.get("homepage", ""), "mailing_list": element.get("mailingList", ""), "number_of_terms": element.get("numberOfTerms", 0), "number_of_properties": element.get("numberOfProperties", 0), "number_of_individuals": element.get("numberOfIndividuals", 0), "last_loaded": element.get("lastLoaded", ""), "status": element.get("status", ""), } for element in data.get("elements", []) ] ontologies.extend(page_ontologies) # Sort by ontology ID for consistency ontologies.sort(key=lambda x: x["id"]) return { "ontologies": ontologies, "total_ontologies": total_elements, "page_info": { "total_pages": total_pages, "num_elements": len(ontologies), }, } except requests.exceptions.RequestException as e: return {"error": f"Failed to fetch available ontologies: {e!s}"}
- src/biocontext_kb/core/_server.py:1-6 (registration)Defines core_mcp FastMCP server instance with name 'BC', used by @core_mcp.tool() decorators to register tools, prefixing with 'bc_' for the tool names.from fastmcp import FastMCP core_mcp = FastMCP( # type: ignore "BC", instructions="Provides access to biomedical knowledge bases.", )