Skip to main content
Glama
seandavi

OLS MCP Server

by seandavi

get_term_ancestors

Retrieve parent terms from biological ontologies using term IRI and ontology identifier to understand hierarchical relationships in OLS MCP Server.

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
NameRequiredDescriptionDefault
term_iriYes
ontologyYes
include_obsoleteNo
sizeNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The core handler function for the 'get_term_ancestors' tool. It is decorated with @mcp.tool() which also serves as registration. Queries the OLS API for ancestor terms of a given term IRI in a specific ontology, formats the response, and handles errors.
    @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)}"
  • Registration of the 'get_term_ancestors' tool using FastMCP's @mcp.tool() decorator.
    @mcp.tool()
  • Helper function used by get_term_ancestors to format the API response into a readable JSON structure.
    def format_response(data: Any, max_items: int = 10) -> str:
        """Format API response data for display."""
        if isinstance(data, dict):
            if "elements" in data:
                # Handle paginated response
                elements = data["elements"][:max_items]
                total = data.get("totalElements", len(elements))
                
                result = []
                for item in elements:
                    if isinstance(item, dict):
                        # Extract key fields for display
                        label = item.get("label", "")
                        iri = item.get("iri", "")
                        description = item.get("description", [])
                        if isinstance(description, list) and description:
                            description = description[0]
                        elif isinstance(description, list):
                            description = ""
                        
                        result.append({
                            "label": label,
                            "iri": iri,
                            "description": description[:200] + "..." if len(str(description)) > 200 else description
                        })
                
                return json.dumps({
                    "items": result,
                    "total_items": total,
                    "showing": len(result)
                }, indent=2)
            else:
                # Single item response
                return json.dumps(data, indent=2)
        
        return json.dumps(data, indent=2)
  • Helper function used to double URL encode the term IRI for OLS API requests.
    def url_encode_iri(iri: str) -> str:
        """Double URL encode an IRI as required by OLS API."""
        return urllib.parse.quote(urllib.parse.quote(iri, safe=""), safe="")
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions that it returns a 'JSON formatted list of ancestor terms,' which gives some output context, but it doesn't cover important aspects like whether this is a read-only operation, potential rate limits, authentication needs, or error handling. For a tool with four parameters and no annotation coverage, this is a significant gap in transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured and appropriately sized, with clear sections for purpose, arguments, and returns. It uses bullet points for parameters, making it easy to scan. Every sentence adds value, such as clarifying the output format, though it could be slightly more front-loaded by emphasizing the core purpose first.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (4 parameters, no annotations, but with an output schema), the description is partially complete. It covers the basic purpose and parameters but lacks usage guidelines and detailed behavioral context. The presence of an output schema means the description doesn't need to explain return values in depth, but it should still address when to use this tool and any operational constraints.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description lists parameters in the 'Args' section with brief explanations (e.g., 'The IRI of the term'), adding some meaning beyond the input schema, which has 0% description coverage. However, it doesn't fully compensate for the schema gap—for example, it doesn't explain what an 'ontology identifier' entails or the implications of 'include_obsolete.' With low schema coverage, the description provides basic but incomplete parameter context.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Get ancestor terms (parents) of a specific term.' It specifies the verb ('Get') and resource ('ancestor terms'), making it easy to understand what the tool does. However, it doesn't explicitly differentiate from sibling tools like 'get_term_children' or 'get_term_info,' which would require a more specific comparison.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like 'get_term_children' (for descendants) or 'get_term_info' (for general term details), nor does it specify prerequisites or contexts for usage. This lack of comparative information leaves the agent without clear direction on tool selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/seandavi/ols-mcp-server'

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