Skip to main content
Glama
seandavi

OLS MCP Server

by seandavi

search_terms

Search biological and medical ontologies to find standardized terms using the OLS API. Retrieve ontology terms with filters for exact matches, obsolete terms, and specific ontologies.

Instructions

Search for terms across ontologies using the OLS search API.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes
ontologyNo
exact_matchNo
include_obsoleteNo
rowsNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The main handler function for the 'search_terms' tool, decorated with @mcp.tool() which also serves as registration. It performs search queries against the OLS API and formats the response.
    @mcp.tool()
    async def search_terms(
        query: Annotated[str, "Search query text"],
        ontology: Annotated[Optional[str], "Optional ontology ID to restrict search (e.g., 'efo', 'go', 'hp'); may be a list of IDs separated by commas"] = None,
        exact_match: Annotated[bool, "Whether to perform exact matching"] = False,
        include_obsolete: Annotated[bool, "Include obsolete terms in results"] = False,
        rows: Annotated[int, "Maximum number of results to return"] = 10
    ) -> TermSearchResponse | str:
        """Search for terms across ontologies using the OLS search API."""
        params = {
            "q": query,
            "rows": rows,
            "start": 0,
            "exact": exact_match,
            "obsoletes": include_obsolete
        }
        
        if ontology:
            params["ontology"] = ontology
        
        url = f"{OLS_BASE_URL}/api/search"
        
        try:
            response = await client.get(url, params=params)
            response.raise_for_status()
            data = response.json()
            
            if "response" in data and "docs" in data["response"]:
                # Transform legacy API format
                docs = data["response"]["docs"]
                result = {
                    "elements": docs,
                    "totalElements": data["response"].get("numFound", len(docs))
                }
                return format_response(result, rows)
            
            return format_response(data, rows)
            
        except httpx.HTTPError as e:
            return f"Error searching terms: {str(e)}"
  • Pydantic model defining the structured output schema for the search_terms tool response.
    class TermSearchResponse(PagedResponse):
        num_found: int = Field(0, description="Total number of terms found", alias="numFound")
        terms: list[TermInfo] = Field(..., description="List of terms matching the search criteria")
  • Base Pydantic model for paginated responses, inherited by TermSearchResponse.
    class PagedResponse(BaseModel):
        total_elements: int = Field(0, description="Total number of items", alias="totalElements")
        page: int = Field(0, description="Current page number")
        size: int = Field(20, description="Starting index of the current page", alias="numElements")
        total_pages: int = Field(0, description="Total number of pages", alias="totalPages")
  • Pydantic model for individual term information used in TermSearchResponse.
    class TermInfo(BaseModel):
        iri: HttpUrl = Field(..., description="IRI of the term")
        ontology_name: str = Field(..., description="Name of the ontology containing the term")
        short_form: str = Field(..., description="Short form identifier for the term")
        label: str = Field(..., description="Human-readable label for the term")
        obo_id: Optional[str] = Field(None, description="OBOLibrary ID for the term", alias="oboId")
        is_obsolete: Optional[bool] = Field(False, description="Indicates if the term is obsolete")
  • Helper function used by search_terms to format and truncate API responses for display.
    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)
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It mentions the OLS search API but doesn't disclose behavioral traits such as rate limits, authentication needs, pagination behavior (implied by 'rows' parameter), or what happens with large result sets. For a search tool with 5 parameters and no annotation coverage, this is a significant gap.

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

Conciseness5/5

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

The description is a single, efficient sentence that front-loads the core purpose without unnecessary details. Every word earns its place, making it easy for an agent to quickly grasp the tool's function.

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 5 parameters with 0% schema coverage, no annotations, but an output schema exists, the description is incomplete. It adequately states what the tool does but lacks parameter explanations and behavioral context. The output schema mitigates some gaps, but overall it's minimally viable with clear deficiencies.

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

Parameters2/5

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

Schema description coverage is 0%, so the description must compensate. It doesn't explain any parameters beyond implying 'query' is for search terms. Parameters like 'ontology', 'exact_match', 'include_obsolete', and 'rows' are undocumented in both schema and description, leaving their purposes ambiguous.

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 action ('Search for terms') and the scope ('across ontologies using the OLS search API'), which distinguishes it from siblings like 'search_ontologies' or 'find_similar_terms'. However, it doesn't explicitly differentiate from 'find_similar_terms' in terms of search methodology or output focus.

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 like 'find_similar_terms' or 'search_ontologies'. It mentions the API but doesn't specify use cases, prerequisites, or exclusions, leaving the agent to infer usage from the tool name alone.

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