Skip to main content
Glama
biocontext-ai

BioContextAI Knowledgebase MCP

Official

bc_get_available_ontologies

Discover available biomedical ontologies with metadata to identify relevant terminology resources for research and data integration.

Instructions

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.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The handler function that implements the logic to retrieve all available ontologies from the OLS API, paginating through results and extracting metadata. Registered as an MCP tool via @core_mcp.tool() decorator.
    @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}"}
  • Defines the core_mcp FastMCP server instance named 'BC', to which all core tools including get_available_ontologies are registered via decorators.
    from fastmcp import FastMCP
    
    core_mcp = FastMCP(  # type: ignore
        "BC",
        instructions="Provides access to biomedical knowledge bases.",
    )
  • Registers the core_mcp server (containing get_available_ontologies) into the main BioContextAI MCP app with prefix 'bc' (slugify('BC')), making the tool available as 'bc_get_available_ontologies'.
    logger.info("Setting up MCP server...")
    for mcp in [core_mcp, *(await get_openapi_mcps())]:
        await mcp_app.import_server(
            mcp,
            slugify(mcp.name),
        )
    logger.info("MCP server setup complete.")
  • Re-exports the get_available_ontologies function for convenient import in core/__init__.py.
    from ._get_available_ontologies import get_available_ontologies
    from ._get_cell_ontology_terms import get_cell_ontology_terms
    from ._get_chebi_terms_by_chemical import get_chebi_terms_by_chemical
    from ._get_efo_id_by_disease_name import get_efo_id_by_disease_name
    from ._get_go_terms_by_gene import get_go_terms_by_gene
    from ._get_term_details import get_term_details
    from ._get_term_hierarchical_children import get_term_hierarchical_children
    from ._search_ontology_terms import search_ontology_terms
    
    __all__ = [
        "get_available_ontologies",
        "get_cell_ontology_terms",
        "get_chebi_terms_by_chemical",
        "get_efo_id_by_disease_name",
        "get_go_terms_by_gene",
        "get_term_details",
        "get_term_hierarchical_children",
        "search_ontology_terms",
    ]

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/biocontext-ai/knowledgebase-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server