get_xml_structure
Analyze the structure and metadata of Apple Health XML export files to identify root elements, record types, workout types, and data sources without loading full content for quick insights.
Instructions
Analyze the structure and metadata of an Apple Health XML export file without loading the entire content.
Returns:
file_size_mb: Size of the file in megabytes
root_elements: List of unique root-level XML tags
record_types: List of unique health record types (see RecordType for most frequent types, but may include others)
workout_types: List of unique workout types
sources: List of unique data sources (device/app names)
Notes for LLMs:
Use this to quickly understand the contents and structure of a health XML file
RecordType contains only the most frequent types; other types may appear as strings
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
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- app/mcp/v1/tools/xml_reader.py:11-34 (handler)Handler function decorated with @tool that implements the get_xml_structure tool logic by delegating to analyze_xml_structure().@xml_reader_router.tool def get_xml_structure() -> dict[str, Any]: """ Analyze the structure and metadata of an Apple Health XML export file without loading the entire content. Returns: - file_size_mb: Size of the file in megabytes - root_elements: List of unique root-level XML tags - record_types: List of unique health record types (see RecordType for most frequent types, but may include others) - workout_types: List of unique workout types - sources: List of unique data sources (device/app names) Notes for LLMs: - Use this to quickly understand the contents and structure of a health XML file - RecordType contains only the most frequent types; other types may appear as strings - 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 analyze_xml_structure() except Exception as e: return {"error": f"Failed to analyze XML structure: {str(e)}"}
- app/mcp/v1/mcp.py:10-10 (registration)Mounts the xml_reader_router (containing the get_xml_structure tool) to the main mcp_router, registering the tool.mcp_router.mount(xml_reader.xml_reader_router)
- Core helper function that streams the XML file, analyzes its structure, collects metadata like record types, workout types, sources, and file size.def analyze_xml_structure() -> dict[str, Any]: xml_path = get_xml_path() structure = { "file_size_mb": round(xml_path.stat().st_size / (1024 * 1024), 2), "root_elements": set(), "record_types": set(), "workout_types": set(), "sources": set(), } for elem in stream_xml_elements(): structure["root_elements"].add(elem.tag) if rt := extract_record_type(elem): structure["record_types"].add(rt) if wt := extract_workout_type(elem): structure["workout_types"].add(wt) if src := extract_source(elem): structure["sources"].add(src) # Convert sets to lists for k in ["root_elements", "record_types", "workout_types", "sources"]: structure[k] = list(structure[k]) return structure