Skip to main content
Glama

search_xml_content

Find specific records in Apple Health XML files by searching attribute values. The tool returns matching XML elements, limiting results to a specified maximum. It streams data for memory efficiency.

Instructions

Search for specific content in the Apple Health XML file and return matching records as XML text.

Parameters:

  • query: Text to search for in any attribute value

  • max_results: Maximum number of matching records to return (default: 50)

Returns:

  • A string containing up to max_results XML elements that match the query, or a message if no matches are found.

Notes for LLMs:

  • Searches both Record and Workout elements

  • Useful for finding all records containing a specific value, device, or type

  • This function streams the file for memory efficiency and does not load the entire file into memory.

  • If filename is not provided, the file set by set_xml_file will be used.

  • 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
max_resultsNo
queryNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • FastMCP tool handler decorated with @tool. Wraps the core search_xml function with try-except error handling and detailed docstring describing usage.
    @xml_reader_router.tool
    def search_xml_content(query: str = "", max_results: int = 50) -> str:
        """
        Search for specific content in the Apple Health XML file and return
        matching records as XML text.
    
        Parameters:
        - query: Text to search for in any attribute value
        - max_results: Maximum number of matching records to return (default: 50)
    
        Returns:
        - A string containing up to max_results XML elements that match the
          query, or a message if no matches are found.
    
        Notes for LLMs:
        - Searches both Record and Workout elements
        - Useful for finding all records containing a specific value, device, or type
        - This function streams the file for memory efficiency and does not load
          the entire file into memory.
        - If filename is not provided, the file set by set_xml_file will be used.
        - Do not guess, auto-fill, or assume any missing data.
        - When asked for medical advice, try to use my data from ElasticSearch first.
        """
        try:
            return search_xml(query, max_results)
        except Exception as e:
            return f"Error searching XML content: {str(e)}"
  • Core implementation of the XML content search. Streams the XML file using iterparse, searches Record and Workout elements for query matches in attributes, and formats results as XML strings.
    def search_xml(query: str = "", max_results: int = 50) -> str:
        results = []
        query_lower = query.lower()
        for elem in stream_xml_elements(["Record", "Workout"]):
            matches = any(value and query_lower in value.lower() for value in elem.attrib.values())
            if matches:
                elem_str = ET.tostring(elem, encoding="unicode", method="xml")
                results.append(elem_str)
                if len(results) >= max_results:
                    break
        if not results:
            return f"No matches found for query: '{query}'"
        return (
            f"""Search Results for '{query}' (showing up to {max_results} results):\n\n"""
            f"""{chr(10).join(results)}\n\nTotal matches found: {len(results)}"""
        )
  • app/mcp/v1/mcp.py:3-10 (registration)
    Registers the xml_reader_router (which includes the search_xml_content tool) by mounting it onto the main mcp_router. Also imports the tools modules.
    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)
    mcp_router.mount(xml_reader.xml_reader_router)
  • app/main.py:9-11 (registration)
    Mounts the main mcp_router (containing xml_reader_router and thus search_xml_content) onto the root FastMCP application server.
    mcp = FastMCP(settings.PROJECT_NAME)
    
    mcp.mount(mcp_router)
Behavior4/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 effectively describes key behaviors: it streams the file for memory efficiency, does not load the entire file, uses a default file if not specified, and returns up to max_results matches or a message if none are found. It also includes LLM-specific notes like not guessing missing data and prioritizing ElasticSearch for medical advice, adding valuable operational context.

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 appropriately sized and front-loaded, starting with the core purpose. It uses bullet points for parameters, returns, and notes, which enhances readability. However, the 'Notes for LLMs' section includes some extraneous advice (e.g., 'When asked for medical advice...') that is not directly related to tool invocation, slightly reducing efficiency.

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 tool's moderate complexity (2 parameters, no annotations, but with an output schema), the description is largely complete. It covers purpose, parameters, returns, and behavioral traits. The output schema likely details the return structure, so the description's high-level explanation of returns is sufficient. Minor gaps include lack of error handling details or explicit sibling tool comparisons.

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

Parameters4/5

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

The schema description coverage is 0%, so the description must compensate. It adds meaningful semantics beyond the schema: it explains that 'query' searches in any attribute value and 'max_results' limits the number of matching records returned, with a default of 50. This clarifies the purpose and usage of parameters that are otherwise only defined by type in the schema.

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

Purpose5/5

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

The description clearly states the tool searches for content in an Apple Health XML file and returns matching records as XML text. It specifies the verb 'search' and resource 'Apple Health XML file', distinguishing it from sibling tools like get_xml_by_type or get_xml_structure which retrieve different data formats or structures.

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

Usage Guidelines4/5

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

The description provides clear context for when to use this tool: 'Useful for finding all records containing a specific value, device, or type' and mentions it searches both Record and Workout elements. However, it does not explicitly state when not to use it or name specific alternatives among siblings, such as search_health_records_es, which might serve a similar purpose.

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