get_term_ancestors
Retrieve parent terms of a specific term in a given ontology using the OLS MCP Server. Input the term's IRI and ontology identifier to receive JSON-formatted ancestor terms, with options to include obsolete entities and set result size.
Instructions
Get ancestor terms (parents) of a specific term.
Args: term_iri: The IRI of the term ontology: The ontology identifier include_obsolete: Include obsolete entities size: Maximum number of results
Returns: JSON formatted list of ancestor terms
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| include_obsolete | No | ||
| ontology | Yes | ||
| size | No | ||
| term_iri | Yes |
Implementation Reference
- src/ols_mcp_server/server.py:219-254 (handler)The handler function decorated with @mcp.tool(), implementing the core logic for retrieving ancestor terms from the OLS API. Includes input parameters, API call construction, response formatting, and error handling.@mcp.tool() async def get_term_ancestors( term_iri: str, ontology: str, include_obsolete: bool = False, size: int = 20 ) -> str: """Get ancestor terms (parents) of a specific term. Args: term_iri: The IRI of the term ontology: The ontology identifier include_obsolete: Include obsolete entities size: Maximum number of results Returns: JSON formatted list of ancestor terms """ encoded_iri = url_encode_iri(term_iri) params: dict[str, Any] = { "page": 0, "size": size, "includeObsoleteEntities": include_obsolete } url = f"{OLS_BASE_URL}/api/v2/ontologies/{ontology}/classes/{encoded_iri}/ancestors" try: response = await client.get(url, params=params) response.raise_for_status() data = response.json() return format_response(data, size) except httpx.HTTPError as e: return f"Error getting term ancestors: {str(e)}"