Skip to main content
Glama

search_health_records_es

Search and filter health records stored in Elasticsearch by type, source, date range, or value. Retrieve structured data for analysis, monitoring, or display using flexible query parameters.

Instructions

Search health records in Elasticsearch with flexible query building.

Parameters:

  • params: HealthRecordSearchParams object containing all search/filter parameters.

Notes for LLMs:

  • This function should return a list of health record documents (dicts) matching the search criteria.

  • Each document in the list should represent a single health record as stored in Elasticsearch.

  • If an error occurs, the function should return a list with a single dict containing an 'error' key and the error message.

  • Use this to retrieve structured health data for further analysis, filtering, or display.

  • Example source_name: "Rob’s iPhone", "Polar Flow", "Sync Solver".

  • Example date_from/date_to: "2020-01-01T00:00:00+00:00"

  • Example value_min/value_max: "10", "100.5"

  • IMPORTANT - Do not guess, auto-fill, or assume any missing data.

  • When asked for medical advice, try to use my data from ElasticSearch first.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
paramsYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • FastMCP tool handler for 'search_health_records_es' that delegates to the core Elasticsearch search logic.
    @es_reader_router.tool
    def search_health_records_es(params: HealthRecordSearchParams) -> list[dict[str, Any]]:
        """
        Search health records in Elasticsearch with flexible query building.
    
        Parameters:
        - params: HealthRecordSearchParams object containing all search/filter parameters.
    
        Notes for LLMs:
        - This function should return a list of health record documents (dicts)
          matching the search criteria.
        - Each document in the list should represent a single health record as stored in Elasticsearch.
        - If an error occurs, the function should return a list with a single dict
          containing an 'error' key and the error message.
        - Use this to retrieve structured health data for further analysis, filtering, or display.
        - Example source_name: "Rob’s iPhone", "Polar Flow", "Sync Solver".
        - Example date_from/date_to: "2020-01-01T00:00:00+00:00"
        - Example value_min/value_max: "10", "100.5"
        - IMPORTANT - Do not guess, autofill, or assume any missing data.
        - If there are multiple databases available (DuckDB, ClickHouse, Elasticsearch):
          first, ask the user which one he wants to use. DO NOT call any tools before
          the user specifies his intent.
        - If the user decides on an option, only use tools from this database,
          do not switch over to another until the user specifies that he wants
          to use a different one. You do not have to keep asking whether
          the user wants to use the same database that he used before.
        - If there is only one database available (DuckDB, ClickHouse, Elasticsearch):
          you can use the tools from this database without the user specifying it.
        """
        try:
            return search_health_records_logic(params)
        except Exception as e:
            return [{"error": f"Failed to search health records: {str(e)}"}]
  • Pydantic input schema defining parameters for searching health records (record_type, source_name, dates, value ranges, limit).
    class HealthRecordSearchParams(BaseModel):
        record_type: RecordType | WorkoutType | str | None = None
        source_name: str | None = None
        date_from: str | None = None
        date_to: str | None = None
        min_workout_duration: str | None = None
        max_workout_duration: str | None = None
        value_min: str | None = None
        value_max: str | None = None
        limit: int = 10
  • Core helper function implementing the Elasticsearch query construction and execution for health record search.
    def search_health_records_logic(params: HealthRecordSearchParams) -> list[dict[str, Any]]:
        must_conditions = []
        if params.record_type:
            must_conditions.append(_build_match_condition("type", params.record_type))
        if params.source_name:
            must_conditions.append(_build_match_condition("sourceName", params.source_name))
        if params.date_from or params.date_to:
            range_cond = _build_range_condition("dateComponents", params.date_from, params.date_to)
            if range_cond:
                must_conditions.append(range_cond)
        if params.value_min is not None or params.value_max is not None:
            range_cond = _build_range_condition("value", params.value_min, params.value_max)
            if range_cond:
                must_conditions.append(range_cond)
        query: dict[str, Any]
        if must_conditions:
            query = {"query": {"bool": {"must": must_conditions}}}
        else:
            query = {"query": {"match_all": {}}}
        query["size"] = params.limit
        response = _run_es_query(query)
        return [hit["_source"] for hit in response["hits"]["hits"]]
  • app/mcp/v1/mcp.py:3-9 (registration)
    Mounts the es_reader_router (containing search_health_records_es tool) into the main MCP router, making the tool available.
    from app.mcp.v1.tools import duckdb_reader, es_reader, xml_reader
    
    mcp_router = FastMCP(name="Main MCP")
    
    mcp_router.mount(duckdb_reader.duckdb_reader_router)
    # mcp_router.mount(ch_reader.ch_reader_router)
    mcp_router.mount(es_reader.es_reader_router)
Behavior4/5

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

With no annotations provided, the description carries full burden and does well by specifying return format (list of dicts), error handling behavior (returns list with error dict), and important behavioral constraints ('Do not guess, auto-fill, or assume any missing data'). It also provides example values for parameters, though it doesn't mention pagination, rate limits, or authentication requirements.

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

Conciseness3/5

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

The description is somewhat front-loaded with the core purpose, but contains multiple paragraphs with mixed guidance levels. Some sentences like 'Each document in the list should represent a single health record as stored in Elasticsearch' could be more concise. The structure could be improved by grouping related guidance more clearly.

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

Completeness4/5

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

Given the complexity (health data search with multiple filters), no annotations, and an output schema (which handles return values), the description provides good coverage. It explains the tool's purpose, parameter structure with examples, return format, error handling, and specific usage guidance. The main gap is lack of explicit sibling tool differentiation.

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

Parameters5/5

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

With 0% schema description coverage and 1 parameter (a nested object with 7 fields), the description provides excellent compensation. It explains the parameter structure ('HealthRecordSearchParams object containing all search/filter parameters') and gives concrete examples for source_name, date_from/date_to, and value_min/value_max parameters, adding significant meaning beyond the bare schema.

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 searches health records in Elasticsearch with flexible query building. It specifies the resource (health records) and action (search), but doesn't explicitly differentiate from sibling tools like 'search_xml_content' or 'get_health_summary_es' beyond mentioning Elasticsearch context.

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

Usage Guidelines3/5

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

The description provides some implied usage guidance ('Use this to retrieve structured health data for further analysis, filtering, or display') and a specific directive for medical advice scenarios. However, it doesn't explicitly state when to use this versus alternatives like 'get_health_summary_es' or 'get_statistics_by_type_es', nor does it provide clear exclusion criteria.

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

Related 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/the-momentum/apple-health-mcp-server'

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