get_body_metrics
Retrieve body composition data including skinfold measurements from the MCP Logger fitness tracking database to monitor physical progress over time.
Instructions
Get body metrics with skinfolds.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| from_date | No | ||
| to_date | No | ||
| limit | No | ||
| offset | No |
Implementation Reference
- src/main.py:683-718 (handler)The get_body_metrics function is decorated as an MCP tool and handles the retrieval of body metrics data including associated skinfolds from the database.
def get_body_metrics( from_date: Optional[str] = None, to_date: Optional[str] = None, limit: int = 31, offset: int = 0, ) -> dict[str, list[dict[str, Any]]]: """Get body metrics with skinfolds.""" conn = get_connection() cursor = conn.cursor() filters = [] params = [] if from_date: filters.append("date >= ?") params.append(_ensure_date(from_date)) if to_date: filters.append("date <= ?") params.append(_ensure_date(to_date)) base = "SELECT * FROM body_metrics" if filters: base += " WHERE " + " AND ".join(filters) base += " ORDER BY date DESC LIMIT ? OFFSET ?" params.extend([limit, offset]) cursor.execute(base, params) metrics_list = [] for row in cursor.fetchall(): metrics = _row_to_dict(row) cursor.execute("SELECT site_name, mm FROM skinfolds WHERE body_metrics_id = ?", (metrics["id"],)) skinfolds = {r["site_name"]: r["mm"] for r in cursor.fetchall()} metrics["skinfolds"] = skinfolds metrics_list.append(metrics) conn.close() return {"metrics": metrics_list}