diff --git a/README.md b/README.md index 0e8064d..8095a83 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@
Apple Health Data Management
+Apple Health Data Exploration
[](mailto:hello@themomentum.ai?subject=Apple%20Health%20MCP%20Server%20Inquiry) [](https://themomentum.ai) @@ -14,48 +14,8 @@Built with β€οΈ by Momentum β’ Transforming healthcare data management with AI
diff --git a/docs/about.md b/docs/about.md new file mode 100644 index 0000000..cdb76df --- /dev/null +++ b/docs/about.md @@ -0,0 +1,18 @@ +# About The Project + +[β Back to README](../README.md) + +**Apple Health MCP Server** implements a Model Context Protocol (MCP) server designed for seamless interaction between LLM-based agents and Apple Health data. It provides a standardized interface for querying, analyzing, and managing Apple Health recordsβimported from XML exports and indexed in Elasticsearch, Clickhouse or DuckDBβthrough a comprehensive suite of tools. These tools are accessible from MCP-compatible clients (such as Claude Desktop), enabling users to explore, search, and analyze personal health data using natural-language prompts and advanced filtering, all without requiring direct knowledge of the underlying data formats or Elasticsearch/ClickHouse/DuckDB queries. + +## ποΈ Architecture + +The Apple Health MCP Server is built with a modular, extensible architecture designed for robust health data management and LLM integration: + +- **MCP Tools**: Dedicated tools for Apple Health XML structure analysis, record search, type-based extraction, and statistics/trend generation. Each tool is accessible via the MCP protocol for natural language and programmatic access. +- **XML Import & Parsing**: Efficient streaming and parsing of large Apple Health XML exports, extracting records, workouts, and metadata for further analysis. +- **Elasticsearch Backend**: All health records are indexed in Elasticsearch, enabling fast, scalable search, filtering, and aggregation across large datasets. +- **ClickHouse Backend**: Health records can also be indexed to a ClickHouse database, making the deployment easier for the enduser by using an in-memory database instead of a server-based approach. +- **DuckDB Backend**: Alternative to both Elasticsearch and ClickHouse, DuckDB may offer faster import and query speeds. +- **Service Layer**: Business logic for XML and database operations is encapsulated in dedicated service modules, ensuring separation of concerns and easy extensibility. +- **FastMCP Framework**: Provides the MCP server interface, routing, and tool registration, making the system compatible with LLM-based agents and MCP clients (e.g., Claude Desktop). +- **Configuration & Deployment**: Environment-based configuration and Docker support for easy setup and deployment in various environments. diff --git a/docs/configuration.md b/docs/configuration.md new file mode 100644 index 0000000..299536f --- /dev/null +++ b/docs/configuration.md @@ -0,0 +1,22 @@ +# Configuration + +[β Back to README](../README.md) + +## Environment Variables + +> **Note:** All variables below are optional unless marked as required. If not set, the server will use the default values shown. Only `RAW_XML_PATH` is required and must point to your Apple Health XML file. + +| Variable | Description | Example Value | Required | +|--------------------|--------------------------------------------|----------------------|----------| +| RAW_XML_PATH | Path to the Apple Health XML file | `raw.xml` | β | +| ES_HOST | Elasticsearch host | `localhost` | β | +| ES_PORT | Elasticsearch port | `9200` | β | +| ES_USER | Elasticsearch username | `elastic` | β | +| ES_PASSWORD | Elasticsearch password | `elastic` | β | +| ES_INDEX | Elasticsearch index name | `apple_health_data` | β | +| CH_DIRNAME | ClickHouse directory name | `applehealth.chdb` | β | +| CH_DB_NAME | ClickHouse database name | `applehealth` | β | +| CH_TABLE_NAME | ClickHouse table name | `data` | β | +| DUCKDB_FILENAME | DuckDB parquet file name | `applehealth` | β | +| CHUNK_SIZE | Records indexed into CH/DuckDB at once | `50000` | β | +| XML_SAMPLE_SIZE | Number of XML records to sample | `1000` | β | diff --git a/docs/getting-started.md b/docs/getting-started.md new file mode 100644 index 0000000..628912b --- /dev/null +++ b/docs/getting-started.md @@ -0,0 +1,127 @@ +# Getting Started + +[β Back to README](../README.md) + +Follow these steps to set up Apple Health MCP Server in your environment. + +## Prerequisites + +- **Docker (recommended) or uv + docker**: For dependency management + + π [uv Installation Guide](https://docs.astral.sh/uv/getting-started/installation/) +- **Clone the repository**: + ```sh + git clone https://github.com/the-momentum/apple-health-mcp-server + cd apple-health-mcp-server + ``` + +- **Set up environment variables**: + ```sh + cp config/.env.example config/.env + ``` + Edit the `config/.env` file with your credentials and configuration. See [Environment Variables](../README.md#-Environment-Variables) + +## Prepare Your Data + +1. Export your Apple Health data as an XML file from your iPhone and place it somewhere in your filesystem. By default, the server expects the file in the project root directory. + - if you need working example, we suggest this dataset: https://drive.google.com/file/d/1bWiWmlqFkM3MxJZUD2yAsNHlYrHvCmcZ/view?usp=drive_link + - Rob Mulla. Predict My Sleep Patterns. https://kaggle.com/competitions/kaggle-pog-series-s01e04, 2023. Kaggle. +2. Prepare an Elasticsearch instance and populate it from the XML file: + - Run `make es` to start Elasticsearch and import your XML data. + - (Optional) To clear all data from the Elasticsearch index, run: + ```sh + uv run python scripts/xml2es.py --delete-all + ``` +3. If you choose to use ClickHouse instead of Elasticsearch: + - Run `make ch` to create a database with your exported XML data + - **Note: If you are using Windows, Docker is the only way to integrate ClickHouse into this MCP Server.** + - On Windows: Run `mingw32-make chwin` (or any other version of `make` available on Windows) + +4. Lastly, if you're going to be using DuckDB: + - Run `make duckdb` to create a parquet file with your exported XML data + - If you want to connect to the file through http(s): + - The only thing you need to do is change the .env path, e.g. `localhost:8080/applehealth.parquet` + - If you want an example on how to host the files locally, run `uv run tests/fileserver.py` + + +## Configuration Files + +You can run the MCP Server in your LLM Client in two ways: +- **Docker** (recommended) +- **Local (uv run)** + +### Docker MCP Server + +1. Build the Docker image: + ```sh + make build + ``` +2. Add the following config to your LLM Client settings (replace `