@thebriangao/totem 1.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.dockerignore +23 -0
- package/.env.example +66 -0
- package/CHANGELOG.md +283 -0
- package/CONTRIBUTING.md +149 -0
- package/Dockerfile +53 -0
- package/LICENSE +37 -0
- package/README.md +587 -0
- package/SECURITY.md +79 -0
- package/TOOLS.md +429 -0
- package/WHOOP.md +2673 -0
- package/assets/banner.svg +38 -0
- package/dist/cli/index.js +589 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/setup.js +1127 -0
- package/dist/cli/setup.js.map +1 -0
- package/dist/cli/ui.js +512 -0
- package/dist/cli/ui.js.map +1 -0
- package/dist/cli/update.js +465 -0
- package/dist/cli/update.js.map +1 -0
- package/dist/data/behaviors.js +2777 -0
- package/dist/data/behaviors.js.map +1 -0
- package/dist/data/endpoints.js +320 -0
- package/dist/data/endpoints.js.map +1 -0
- package/dist/data/exercises.js +4863 -0
- package/dist/data/exercises.js.map +1 -0
- package/dist/data/sports.js +212 -0
- package/dist/data/sports.js.map +1 -0
- package/dist/lib/concurrency.js +27 -0
- package/dist/lib/concurrency.js.map +1 -0
- package/dist/lib/dates.js +29 -0
- package/dist/lib/dates.js.map +1 -0
- package/dist/lib/format.js +22 -0
- package/dist/lib/format.js.map +1 -0
- package/dist/lib/stats.js +32 -0
- package/dist/lib/stats.js.map +1 -0
- package/dist/lib/timezone.js +249 -0
- package/dist/lib/timezone.js.map +1 -0
- package/dist/lib/walk.js +396 -0
- package/dist/lib/walk.js.map +1 -0
- package/dist/projections/behavior_impact.js +96 -0
- package/dist/projections/behavior_impact.js.map +1 -0
- package/dist/projections/calendar.js +33 -0
- package/dist/projections/calendar.js.map +1 -0
- package/dist/projections/communities.js +105 -0
- package/dist/projections/communities.js.map +1 -0
- package/dist/projections/cycle.js +81 -0
- package/dist/projections/cycle.js.map +1 -0
- package/dist/projections/hr_zones.js +35 -0
- package/dist/projections/hr_zones.js.map +1 -0
- package/dist/projections/journal.js +56 -0
- package/dist/projections/journal.js.map +1 -0
- package/dist/projections/leaderboard.js +37 -0
- package/dist/projections/leaderboard.js.map +1 -0
- package/dist/projections/lift_exercise.js +22 -0
- package/dist/projections/lift_exercise.js.map +1 -0
- package/dist/projections/lift_history.js +133 -0
- package/dist/projections/lift_history.js.map +1 -0
- package/dist/projections/lift_library.js +71 -0
- package/dist/projections/lift_library.js.map +1 -0
- package/dist/projections/lift_progression.js +138 -0
- package/dist/projections/lift_progression.js.map +1 -0
- package/dist/projections/lift_prs.js +20 -0
- package/dist/projections/lift_prs.js.map +1 -0
- package/dist/projections/live_hr.js +19 -0
- package/dist/projections/live_hr.js.map +1 -0
- package/dist/projections/live_state.js +23 -0
- package/dist/projections/live_state.js.map +1 -0
- package/dist/projections/live_stress.js +11 -0
- package/dist/projections/live_stress.js.map +1 -0
- package/dist/projections/performance_assessment.js +15 -0
- package/dist/projections/performance_assessment.js.map +1 -0
- package/dist/projections/profile.js +59 -0
- package/dist/projections/profile.js.map +1 -0
- package/dist/projections/recovery.js +131 -0
- package/dist/projections/recovery.js.map +1 -0
- package/dist/projections/sleep.js +256 -0
- package/dist/projections/sleep.js.map +1 -0
- package/dist/projections/sleep_need.js +32 -0
- package/dist/projections/sleep_need.js.map +1 -0
- package/dist/projections/smart_alarm.js +45 -0
- package/dist/projections/smart_alarm.js.map +1 -0
- package/dist/projections/strain.js +128 -0
- package/dist/projections/strain.js.map +1 -0
- package/dist/projections/stress.js +86 -0
- package/dist/projections/stress.js.map +1 -0
- package/dist/projections/today.js +129 -0
- package/dist/projections/today.js.map +1 -0
- package/dist/projections/trend.js +149 -0
- package/dist/projections/trend.js.map +1 -0
- package/dist/projections/workout.js +161 -0
- package/dist/projections/workout.js.map +1 -0
- package/dist/projections/workouts.js +37 -0
- package/dist/projections/workouts.js.map +1 -0
- package/dist/schemas/calendar.js +12 -0
- package/dist/schemas/calendar.js.map +1 -0
- package/dist/schemas/coach.js +11 -0
- package/dist/schemas/coach.js.map +1 -0
- package/dist/schemas/communities.js +51 -0
- package/dist/schemas/communities.js.map +1 -0
- package/dist/schemas/compare.js +15 -0
- package/dist/schemas/compare.js.map +1 -0
- package/dist/schemas/escape.js +18 -0
- package/dist/schemas/escape.js.map +1 -0
- package/dist/schemas/journal.js +69 -0
- package/dist/schemas/journal.js.map +1 -0
- package/dist/schemas/leaderboard.js +25 -0
- package/dist/schemas/leaderboard.js.map +1 -0
- package/dist/schemas/live.js +26 -0
- package/dist/schemas/live.js.map +1 -0
- package/dist/schemas/performance.js +12 -0
- package/dist/schemas/performance.js.map +1 -0
- package/dist/schemas/primitives.js +29 -0
- package/dist/schemas/primitives.js.map +1 -0
- package/dist/schemas/profile.js +39 -0
- package/dist/schemas/profile.js.map +1 -0
- package/dist/schemas/recovery.js +27 -0
- package/dist/schemas/recovery.js.map +1 -0
- package/dist/schemas/settings.js +26 -0
- package/dist/schemas/settings.js.map +1 -0
- package/dist/schemas/sleep.js +38 -0
- package/dist/schemas/sleep.js.map +1 -0
- package/dist/schemas/sleep_need.js +15 -0
- package/dist/schemas/sleep_need.js.map +1 -0
- package/dist/schemas/smart_alarm.js +36 -0
- package/dist/schemas/smart_alarm.js.map +1 -0
- package/dist/schemas/strain.js +24 -0
- package/dist/schemas/strain.js.map +1 -0
- package/dist/schemas/strength.js +170 -0
- package/dist/schemas/strength.js.map +1 -0
- package/dist/schemas/stress.js +16 -0
- package/dist/schemas/stress.js.map +1 -0
- package/dist/schemas/today.js +38 -0
- package/dist/schemas/today.js.map +1 -0
- package/dist/schemas/trend.js +50 -0
- package/dist/schemas/trend.js.map +1 -0
- package/dist/schemas/womens_health.js +23 -0
- package/dist/schemas/womens_health.js.map +1 -0
- package/dist/schemas/workouts.js +50 -0
- package/dist/schemas/workouts.js.map +1 -0
- package/dist/scripts/cognito_bootstrap.js +278 -0
- package/dist/scripts/cognito_bootstrap.js.map +1 -0
- package/dist/server-http.js +221 -0
- package/dist/server-http.js.map +1 -0
- package/dist/server.js +74 -0
- package/dist/server.js.map +1 -0
- package/dist/tools/register.js +117 -0
- package/dist/tools/register.js.map +1 -0
- package/dist/tools/v2/activity_create.js +64 -0
- package/dist/tools/v2/activity_create.js.map +1 -0
- package/dist/tools/v2/activity_delete.js +26 -0
- package/dist/tools/v2/activity_delete.js.map +1 -0
- package/dist/tools/v2/behavior_impact.js +36 -0
- package/dist/tools/v2/behavior_impact.js.map +1 -0
- package/dist/tools/v2/calendar.js +28 -0
- package/dist/tools/v2/calendar.js.map +1 -0
- package/dist/tools/v2/coach_ask.js +117 -0
- package/dist/tools/v2/coach_ask.js.map +1 -0
- package/dist/tools/v2/communities.js +60 -0
- package/dist/tools/v2/communities.js.map +1 -0
- package/dist/tools/v2/compare.js +67 -0
- package/dist/tools/v2/compare.js.map +1 -0
- package/dist/tools/v2/cycle.js +23 -0
- package/dist/tools/v2/cycle.js.map +1 -0
- package/dist/tools/v2/cycle_log.js +43 -0
- package/dist/tools/v2/cycle_log.js.map +1 -0
- package/dist/tools/v2/day.js +32 -0
- package/dist/tools/v2/day.js.map +1 -0
- package/dist/tools/v2/endpoints.js +28 -0
- package/dist/tools/v2/endpoints.js.map +1 -0
- package/dist/tools/v2/hidden_metric.js +28 -0
- package/dist/tools/v2/hidden_metric.js.map +1 -0
- package/dist/tools/v2/hr_zones.js +24 -0
- package/dist/tools/v2/hr_zones.js.map +1 -0
- package/dist/tools/v2/hr_zones_set.js +51 -0
- package/dist/tools/v2/hr_zones_set.js.map +1 -0
- package/dist/tools/v2/journal.js +26 -0
- package/dist/tools/v2/journal.js.map +1 -0
- package/dist/tools/v2/journal_autopop.js +19 -0
- package/dist/tools/v2/journal_autopop.js.map +1 -0
- package/dist/tools/v2/journal_catalog.js +44 -0
- package/dist/tools/v2/journal_catalog.js.map +1 -0
- package/dist/tools/v2/journal_log.js +78 -0
- package/dist/tools/v2/journal_log.js.map +1 -0
- package/dist/tools/v2/leaderboard.js +79 -0
- package/dist/tools/v2/leaderboard.js.map +1 -0
- package/dist/tools/v2/lift_catalog.js +47 -0
- package/dist/tools/v2/lift_catalog.js.map +1 -0
- package/dist/tools/v2/lift_custom_exercise.js +108 -0
- package/dist/tools/v2/lift_custom_exercise.js.map +1 -0
- package/dist/tools/v2/lift_exercise.js +31 -0
- package/dist/tools/v2/lift_exercise.js.map +1 -0
- package/dist/tools/v2/lift_history.js +39 -0
- package/dist/tools/v2/lift_history.js.map +1 -0
- package/dist/tools/v2/lift_library.js +22 -0
- package/dist/tools/v2/lift_library.js.map +1 -0
- package/dist/tools/v2/lift_log.js +95 -0
- package/dist/tools/v2/lift_log.js.map +1 -0
- package/dist/tools/v2/lift_progression.js +30 -0
- package/dist/tools/v2/lift_progression.js.map +1 -0
- package/dist/tools/v2/lift_prs.js +21 -0
- package/dist/tools/v2/lift_prs.js.map +1 -0
- package/dist/tools/v2/lift_template_save.js +83 -0
- package/dist/tools/v2/lift_template_save.js.map +1 -0
- package/dist/tools/v2/live_hr.js +21 -0
- package/dist/tools/v2/live_hr.js.map +1 -0
- package/dist/tools/v2/live_state.js +21 -0
- package/dist/tools/v2/live_state.js.map +1 -0
- package/dist/tools/v2/live_stress.js +22 -0
- package/dist/tools/v2/live_stress.js.map +1 -0
- package/dist/tools/v2/performance_assessment.js +38 -0
- package/dist/tools/v2/performance_assessment.js.map +1 -0
- package/dist/tools/v2/profile.js +28 -0
- package/dist/tools/v2/profile.js.map +1 -0
- package/dist/tools/v2/profile_update.js +66 -0
- package/dist/tools/v2/profile_update.js.map +1 -0
- package/dist/tools/v2/raw.js +43 -0
- package/dist/tools/v2/raw.js.map +1 -0
- package/dist/tools/v2/recovery.js +31 -0
- package/dist/tools/v2/recovery.js.map +1 -0
- package/dist/tools/v2/sleep.js +23 -0
- package/dist/tools/v2/sleep.js.map +1 -0
- package/dist/tools/v2/sleep_need.js +21 -0
- package/dist/tools/v2/sleep_need.js.map +1 -0
- package/dist/tools/v2/smart_alarm.js +24 -0
- package/dist/tools/v2/smart_alarm.js.map +1 -0
- package/dist/tools/v2/smart_alarm_set.js +94 -0
- package/dist/tools/v2/smart_alarm_set.js.map +1 -0
- package/dist/tools/v2/sports_catalog.js +26 -0
- package/dist/tools/v2/sports_catalog.js.map +1 -0
- package/dist/tools/v2/strain.js +23 -0
- package/dist/tools/v2/strain.js.map +1 -0
- package/dist/tools/v2/stress.js +23 -0
- package/dist/tools/v2/stress.js.map +1 -0
- package/dist/tools/v2/symptom_log.js +72 -0
- package/dist/tools/v2/symptom_log.js.map +1 -0
- package/dist/tools/v2/today.js +30 -0
- package/dist/tools/v2/today.js.map +1 -0
- package/dist/tools/v2/trend.js +26 -0
- package/dist/tools/v2/trend.js.map +1 -0
- package/dist/tools/v2/workout.js +23 -0
- package/dist/tools/v2/workout.js.map +1 -0
- package/dist/tools/v2/workouts.js +32 -0
- package/dist/tools/v2/workouts.js.map +1 -0
- package/dist/whoop/build_lift_body.js +67 -0
- package/dist/whoop/build_lift_body.js.map +1 -0
- package/dist/whoop/client.js +84 -0
- package/dist/whoop/client.js.map +1 -0
- package/dist/whoop/cognito.js +110 -0
- package/dist/whoop/cognito.js.map +1 -0
- package/dist/whoop/constants.js +4 -0
- package/dist/whoop/constants.js.map +1 -0
- package/dist/whoop/device.js +103 -0
- package/dist/whoop/device.js.map +1 -0
- package/dist/whoop/errors.js +42 -0
- package/dist/whoop/errors.js.map +1 -0
- package/dist/whoop/init_timezone.js +62 -0
- package/dist/whoop/init_timezone.js.map +1 -0
- package/dist/whoop/installation.js +62 -0
- package/dist/whoop/installation.js.map +1 -0
- package/dist/whoop/json_out.js +9 -0
- package/dist/whoop/json_out.js.map +1 -0
- package/dist/whoop/oauth_provider.js +297 -0
- package/dist/whoop/oauth_provider.js.map +1 -0
- package/dist/whoop/session_state.js +34 -0
- package/dist/whoop/session_state.js.map +1 -0
- package/dist/whoop/token_manager.js +60 -0
- package/dist/whoop/token_manager.js.map +1 -0
- package/dist/whoop/token_store.js +47 -0
- package/dist/whoop/token_store.js.map +1 -0
- package/dist/whoop/types.js +82 -0
- package/dist/whoop/types.js.map +1 -0
- package/dist/whoop/write_safety.js +23 -0
- package/dist/whoop/write_safety.js.map +1 -0
- package/package.json +66 -0
- package/src/cli/index.ts +597 -0
- package/src/cli/setup.ts +1106 -0
- package/src/cli/ui.ts +505 -0
- package/src/cli/update.ts +442 -0
- package/src/data/behaviors.ts +2784 -0
- package/src/data/endpoints.ts +319 -0
- package/src/data/exercises.ts +4868 -0
- package/src/data/sports.ts +218 -0
- package/src/lib/concurrency.ts +28 -0
- package/src/lib/dates.ts +35 -0
- package/src/lib/format.ts +27 -0
- package/src/lib/stats.ts +35 -0
- package/src/lib/timezone.ts +269 -0
- package/src/lib/walk.ts +418 -0
- package/src/projections/behavior_impact.ts +98 -0
- package/src/projections/calendar.ts +46 -0
- package/src/projections/communities.ts +135 -0
- package/src/projections/cycle.ts +85 -0
- package/src/projections/hr_zones.ts +43 -0
- package/src/projections/journal.ts +55 -0
- package/src/projections/leaderboard.ts +49 -0
- package/src/projections/lift_exercise.ts +29 -0
- package/src/projections/lift_history.ts +140 -0
- package/src/projections/lift_library.ts +70 -0
- package/src/projections/lift_progression.ts +138 -0
- package/src/projections/lift_prs.ts +23 -0
- package/src/projections/live_hr.ts +21 -0
- package/src/projections/live_state.ts +28 -0
- package/src/projections/live_stress.ts +13 -0
- package/src/projections/performance_assessment.ts +19 -0
- package/src/projections/profile.ts +71 -0
- package/src/projections/recovery.ts +133 -0
- package/src/projections/sleep.ts +276 -0
- package/src/projections/sleep_need.ts +36 -0
- package/src/projections/smart_alarm.ts +70 -0
- package/src/projections/strain.ts +131 -0
- package/src/projections/stress.ts +95 -0
- package/src/projections/today.ts +166 -0
- package/src/projections/trend.ts +149 -0
- package/src/projections/workout.ts +168 -0
- package/src/projections/workouts.ts +36 -0
- package/src/schemas/calendar.ts +13 -0
- package/src/schemas/coach.ts +11 -0
- package/src/schemas/communities.ts +56 -0
- package/src/schemas/compare.ts +17 -0
- package/src/schemas/escape.ts +21 -0
- package/src/schemas/journal.ts +80 -0
- package/src/schemas/leaderboard.ts +26 -0
- package/src/schemas/live.ts +31 -0
- package/src/schemas/performance.ts +13 -0
- package/src/schemas/primitives.ts +35 -0
- package/src/schemas/profile.ts +40 -0
- package/src/schemas/recovery.ts +28 -0
- package/src/schemas/settings.ts +30 -0
- package/src/schemas/sleep.ts +40 -0
- package/src/schemas/sleep_need.ts +16 -0
- package/src/schemas/smart_alarm.ts +40 -0
- package/src/schemas/strain.ts +25 -0
- package/src/schemas/strength.ts +189 -0
- package/src/schemas/stress.ts +17 -0
- package/src/schemas/today.ts +39 -0
- package/src/schemas/trend.ts +53 -0
- package/src/schemas/womens_health.ts +26 -0
- package/src/schemas/workouts.ts +55 -0
- package/src/scripts/cognito_bootstrap.ts +249 -0
- package/src/server-http.ts +241 -0
- package/src/server.ts +85 -0
- package/src/tools/register.ts +120 -0
- package/src/tools/v2/activity_create.ts +74 -0
- package/src/tools/v2/activity_delete.ts +33 -0
- package/src/tools/v2/behavior_impact.ts +39 -0
- package/src/tools/v2/calendar.ts +33 -0
- package/src/tools/v2/coach_ask.ts +131 -0
- package/src/tools/v2/communities.ts +65 -0
- package/src/tools/v2/compare.ts +83 -0
- package/src/tools/v2/cycle.ts +28 -0
- package/src/tools/v2/cycle_log.ts +51 -0
- package/src/tools/v2/day.ts +37 -0
- package/src/tools/v2/endpoints.ts +32 -0
- package/src/tools/v2/hidden_metric.ts +33 -0
- package/src/tools/v2/hr_zones.ts +29 -0
- package/src/tools/v2/hr_zones_set.ts +57 -0
- package/src/tools/v2/journal.ts +31 -0
- package/src/tools/v2/journal_autopop.ts +26 -0
- package/src/tools/v2/journal_catalog.ts +48 -0
- package/src/tools/v2/journal_log.ts +84 -0
- package/src/tools/v2/leaderboard.ts +92 -0
- package/src/tools/v2/lift_catalog.ts +48 -0
- package/src/tools/v2/lift_custom_exercise.ts +117 -0
- package/src/tools/v2/lift_exercise.ts +35 -0
- package/src/tools/v2/lift_history.ts +52 -0
- package/src/tools/v2/lift_library.ts +28 -0
- package/src/tools/v2/lift_log.ts +102 -0
- package/src/tools/v2/lift_progression.ts +34 -0
- package/src/tools/v2/lift_prs.ts +26 -0
- package/src/tools/v2/lift_template_save.ts +89 -0
- package/src/tools/v2/live_hr.ts +26 -0
- package/src/tools/v2/live_state.ts +26 -0
- package/src/tools/v2/live_stress.ts +27 -0
- package/src/tools/v2/performance_assessment.ts +44 -0
- package/src/tools/v2/profile.ts +33 -0
- package/src/tools/v2/profile_update.ts +76 -0
- package/src/tools/v2/raw.ts +50 -0
- package/src/tools/v2/recovery.ts +36 -0
- package/src/tools/v2/sleep.ts +28 -0
- package/src/tools/v2/sleep_need.ts +26 -0
- package/src/tools/v2/smart_alarm.ts +29 -0
- package/src/tools/v2/smart_alarm_set.ts +103 -0
- package/src/tools/v2/sports_catalog.ts +32 -0
- package/src/tools/v2/strain.ts +28 -0
- package/src/tools/v2/stress.ts +28 -0
- package/src/tools/v2/symptom_log.ts +78 -0
- package/src/tools/v2/today.ts +35 -0
- package/src/tools/v2/trend.ts +31 -0
- package/src/tools/v2/workout.ts +28 -0
- package/src/tools/v2/workouts.ts +37 -0
- package/src/whoop/build_lift_body.ts +84 -0
- package/src/whoop/client.ts +118 -0
- package/src/whoop/cognito.ts +150 -0
- package/src/whoop/constants.ts +3 -0
- package/src/whoop/device.ts +106 -0
- package/src/whoop/errors.ts +41 -0
- package/src/whoop/init_timezone.ts +64 -0
- package/src/whoop/installation.ts +58 -0
- package/src/whoop/json_out.ts +9 -0
- package/src/whoop/oauth_provider.ts +377 -0
- package/src/whoop/session_state.ts +41 -0
- package/src/whoop/token_manager.ts +76 -0
- package/src/whoop/token_store.ts +45 -0
- package/src/whoop/types.ts +89 -0
- package/src/whoop/write_safety.ts +30 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import type { WhoopClient } from "../../whoop/client.js";
|
|
4
|
+
import { CycleOut } from "../../schemas/womens_health.js";
|
|
5
|
+
import { projectCycle } from "../../projections/cycle.js";
|
|
6
|
+
import { WhoopProjectionError } from "../../whoop/errors.js";
|
|
7
|
+
import { jsonOut } from "../../whoop/json_out.js";
|
|
8
|
+
import { todayIso } from "../../lib/dates.js";
|
|
9
|
+
|
|
10
|
+
export function registerCycle(server: McpServer, client: WhoopClient): void {
|
|
11
|
+
server.tool(
|
|
12
|
+
"whoop_cycle",
|
|
13
|
+
"Current menstrual cycle status for a date: phase (e.g. Luteal Phase), cycle day, typical cycle length, and predicted next-period / ovulation dates. Requires women's-health tracking enabled on the account; fields return null if it isn't set up.",
|
|
14
|
+
{ date: z.iso.date().optional() },
|
|
15
|
+
async ({ date }) => {
|
|
16
|
+
const d = date ?? todayIso();
|
|
17
|
+
const raw = await client.get("/womens-health-service/v1/menstrual-cycle-insights", { date: d });
|
|
18
|
+
const projected = projectCycle(raw, d);
|
|
19
|
+
try {
|
|
20
|
+
const out = CycleOut.parse(projected);
|
|
21
|
+
return { content: [{ type: "text", text: jsonOut(out) }] };
|
|
22
|
+
} catch (e) {
|
|
23
|
+
if (e instanceof z.ZodError) throw new WhoopProjectionError("whoop_cycle", e);
|
|
24
|
+
throw e;
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
);
|
|
28
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import type { WhoopClient } from "../../whoop/client.js";
|
|
4
|
+
import { CycleLogOut } from "../../schemas/womens_health.js";
|
|
5
|
+
import { preview } from "../../whoop/write_safety.js";
|
|
6
|
+
import { jsonOut } from "../../whoop/json_out.js";
|
|
7
|
+
|
|
8
|
+
const PATH = "/womens-health-service/v1/menstrual-cycle-insights/log";
|
|
9
|
+
|
|
10
|
+
export function registerCycleLog(server: McpServer, client: WhoopClient): void {
|
|
11
|
+
server.tool(
|
|
12
|
+
"whoop_cycle_log",
|
|
13
|
+
"WRITE: log a period or ovulation event for a date — pass period:true (optionally period_flow for flow intensity) OR ovulation:true, not both on the same date. Women's-health tracking must be set up on the account first (else the API 400s).",
|
|
14
|
+
{
|
|
15
|
+
date: z.iso.date(),
|
|
16
|
+
period: z.boolean().optional(),
|
|
17
|
+
period_flow: z.number().nullable().optional().describe("Magnitude if logging period."),
|
|
18
|
+
ovulation: z.boolean().optional(),
|
|
19
|
+
confirm: z.boolean().default(false),
|
|
20
|
+
},
|
|
21
|
+
async ({ date, period, period_flow, ovulation, confirm }) => {
|
|
22
|
+
if (period === true && ovulation === true) {
|
|
23
|
+
return {
|
|
24
|
+
content: [{ type: "text", text: jsonOut({ error: "Cannot log period and ovulation on the same date — Whoop's API rejects this with 400. Pick one or call cycle_log twice on different dates." }) }],
|
|
25
|
+
isError: true,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const parts = date.split("-").map(Number);
|
|
29
|
+
const y = parts[0] ?? 1970;
|
|
30
|
+
const m = parts[1] ?? 1;
|
|
31
|
+
const d = parts[2] ?? 1;
|
|
32
|
+
const body = {
|
|
33
|
+
period_logs: [
|
|
34
|
+
{
|
|
35
|
+
date: [y, m, d],
|
|
36
|
+
period: { answered_yes: period ?? false, magnitude_input_value: period_flow ?? null },
|
|
37
|
+
ovulation: { answered_yes: ovulation ?? false, magnitude_input_value: null },
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
};
|
|
41
|
+
if (!confirm) {
|
|
42
|
+
return {
|
|
43
|
+
content: [{ type: "text", text: jsonOut(preview("PUT", PATH, { date, period, ovulation })) }],
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
await client.put(PATH, body);
|
|
47
|
+
const out = CycleLogOut.parse({ logged: true as const, date });
|
|
48
|
+
return { content: [{ type: "text", text: jsonOut(out) }] };
|
|
49
|
+
},
|
|
50
|
+
);
|
|
51
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import type { WhoopClient } from "../../whoop/client.js";
|
|
4
|
+
import { TodayOut } from "../../schemas/today.js";
|
|
5
|
+
import { projectToday } from "../../projections/today.js";
|
|
6
|
+
import { WhoopProjectionError } from "../../whoop/errors.js";
|
|
7
|
+
import { jsonOut } from "../../whoop/json_out.js";
|
|
8
|
+
|
|
9
|
+
export function registerDay(server: McpServer, client: WhoopClient): void {
|
|
10
|
+
server.tool(
|
|
11
|
+
"whoop_day",
|
|
12
|
+
"Composite snapshot for any past date: recovery, sleep + stages, day strain, workouts count. Same shape as whoop_today but current_state is always null (not relevant for historical days).",
|
|
13
|
+
{
|
|
14
|
+
date: z.iso.date().describe("YYYY-MM-DD date to fetch. Required."),
|
|
15
|
+
},
|
|
16
|
+
async ({ date }) => {
|
|
17
|
+
// Window the target date so we catch the sleep that *ends* on it.
|
|
18
|
+
const dayMs = Date.parse(`${date}T00:00:00.000Z`);
|
|
19
|
+
const start = new Date(dayMs - 86_400_000).toISOString();
|
|
20
|
+
const end = new Date(dayMs + 2 * 86_400_000).toISOString();
|
|
21
|
+
const [home, sleep, recovery] = await Promise.all([
|
|
22
|
+
client.get("/home-service/v1/home", { date }),
|
|
23
|
+
// Light sleep summary (~1 KB) — the full hypnogram lives in whoop_sleep.
|
|
24
|
+
client.get("/developer/v2/activity/sleep", { start, end, limit: "10" }).catch(() => null),
|
|
25
|
+
client.get("/developer/v2/recovery", { start, end, limit: "10" }).catch(() => null),
|
|
26
|
+
]);
|
|
27
|
+
const projected = projectToday({ home, sleep, recovery, state: null, date });
|
|
28
|
+
try {
|
|
29
|
+
const out = TodayOut.parse(projected);
|
|
30
|
+
return { content: [{ type: "text", text: jsonOut(out) }] };
|
|
31
|
+
} catch (e) {
|
|
32
|
+
if (e instanceof z.ZodError) throw new WhoopProjectionError("whoop_day", e);
|
|
33
|
+
throw e;
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
);
|
|
37
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { EndpointsOut } from "../../schemas/escape.js";
|
|
4
|
+
import { ENDPOINTS } from "../../data/endpoints.js";
|
|
5
|
+
import { jsonOut } from "../../whoop/json_out.js";
|
|
6
|
+
|
|
7
|
+
export function registerEndpoints(server: McpServer, _client: unknown): void {
|
|
8
|
+
server.tool(
|
|
9
|
+
"whoop_endpoints",
|
|
10
|
+
"Search the bundled catalog of Whoop iOS API endpoints. Call before whoop_raw to discover paths.",
|
|
11
|
+
{
|
|
12
|
+
filter: z.string().optional(),
|
|
13
|
+
method: z.enum(["GET", "POST", "PUT", "DELETE"]).optional(),
|
|
14
|
+
limit: z.number().int().min(1).max(500).default(200),
|
|
15
|
+
},
|
|
16
|
+
async ({ filter, method, limit }) => {
|
|
17
|
+
const f = filter?.toLowerCase();
|
|
18
|
+
const matches = ENDPOINTS.filter((line) => {
|
|
19
|
+
if (method && !line.startsWith(method + " ")) return false;
|
|
20
|
+
if (f && !line.toLowerCase().includes(f)) return false;
|
|
21
|
+
return true;
|
|
22
|
+
});
|
|
23
|
+
const out = EndpointsOut.parse({
|
|
24
|
+
total_in_catalog: ENDPOINTS.length,
|
|
25
|
+
matched: matches.length,
|
|
26
|
+
truncated: matches.length > limit,
|
|
27
|
+
endpoints: matches.slice(0, limit),
|
|
28
|
+
});
|
|
29
|
+
return { content: [{ type: "text", text: jsonOut(out) }] };
|
|
30
|
+
},
|
|
31
|
+
);
|
|
32
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import type { WhoopClient } from "../../whoop/client.js";
|
|
4
|
+
import { HiddenMetricOut } from "../../schemas/settings.js";
|
|
5
|
+
import { preview } from "../../whoop/write_safety.js";
|
|
6
|
+
import { jsonOut } from "../../whoop/json_out.js";
|
|
7
|
+
|
|
8
|
+
export function registerHiddenMetric(server: McpServer, client: WhoopClient): void {
|
|
9
|
+
server.tool(
|
|
10
|
+
"whoop_hidden_metric",
|
|
11
|
+
"WRITE: show or hide a dashboard metric. metric: BODY_COMP or HEALTHSPAN. action: hide or show.",
|
|
12
|
+
{
|
|
13
|
+
metric: z.enum(["BODY_COMP", "HEALTHSPAN"]),
|
|
14
|
+
action: z.enum(["hide", "show"]),
|
|
15
|
+
confirm: z.boolean().default(false),
|
|
16
|
+
},
|
|
17
|
+
async ({ metric, action, confirm }) => {
|
|
18
|
+
const path = `/users-service/v1/hidden-metrics/${metric}`;
|
|
19
|
+
const method = action === "hide" ? "POST" : "DELETE";
|
|
20
|
+
if (!confirm) {
|
|
21
|
+
return { content: [{ type: "text", text: jsonOut(preview(method, path, { metric, action })) }] };
|
|
22
|
+
}
|
|
23
|
+
if (action === "hide") await client.post(path, undefined);
|
|
24
|
+
else await client.delete(path);
|
|
25
|
+
const out = HiddenMetricOut.parse({
|
|
26
|
+
updated: true as const,
|
|
27
|
+
metric,
|
|
28
|
+
is_hidden: action === "hide",
|
|
29
|
+
});
|
|
30
|
+
return { content: [{ type: "text", text: jsonOut(out) }] };
|
|
31
|
+
},
|
|
32
|
+
);
|
|
33
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import type { WhoopClient } from "../../whoop/client.js";
|
|
4
|
+
import { HrZonesOut } from "../../schemas/settings.js";
|
|
5
|
+
import { projectHrZones } from "../../projections/hr_zones.js";
|
|
6
|
+
import { WhoopProjectionError } from "../../whoop/errors.js";
|
|
7
|
+
import { jsonOut } from "../../whoop/json_out.js";
|
|
8
|
+
|
|
9
|
+
export function registerHrZones(server: McpServer, client: WhoopClient): void {
|
|
10
|
+
server.tool(
|
|
11
|
+
"whoop_hr_zones",
|
|
12
|
+
"Current heart-rate zones + max HR + last updated.",
|
|
13
|
+
{},
|
|
14
|
+
async () => {
|
|
15
|
+
const [zones, settings] = await Promise.all([
|
|
16
|
+
client.get("/hr-zones-service/v1/bff/zones").catch(() => null),
|
|
17
|
+
client.get("/hr-zones-service/v1/bff/settings").catch(() => null),
|
|
18
|
+
]);
|
|
19
|
+
const projected = projectHrZones({ zones, settings });
|
|
20
|
+
try {
|
|
21
|
+
const out = HrZonesOut.parse(projected);
|
|
22
|
+
return { content: [{ type: "text", text: jsonOut(out) }] };
|
|
23
|
+
} catch (e) {
|
|
24
|
+
if (e instanceof z.ZodError) throw new WhoopProjectionError("whoop_hr_zones", e);
|
|
25
|
+
throw e;
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
);
|
|
29
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import type { WhoopClient } from "../../whoop/client.js";
|
|
4
|
+
import { HrZonesSetOut } from "../../schemas/settings.js";
|
|
5
|
+
import { preview } from "../../whoop/write_safety.js";
|
|
6
|
+
import { jsonOut } from "../../whoop/json_out.js";
|
|
7
|
+
|
|
8
|
+
export function registerHrZonesSet(server: McpServer, client: WhoopClient): void {
|
|
9
|
+
server.tool(
|
|
10
|
+
"whoop_hr_zones_set",
|
|
11
|
+
"WRITE: set your heart-rate zones. mode=max_hr → pass max_hr (bpm) and Whoop recomputes the 5 zones; mode=custom → pass all 5 zones (ZONE_1..ZONE_5, each with min/max bpm).",
|
|
12
|
+
{
|
|
13
|
+
mode: z.enum(["max_hr", "custom"]),
|
|
14
|
+
max_hr: z.number().int().optional().describe("Required for mode=max_hr."),
|
|
15
|
+
zones: z
|
|
16
|
+
.array(z.object({
|
|
17
|
+
id: z.enum(["ZONE_1", "ZONE_2", "ZONE_3", "ZONE_4", "ZONE_5"]),
|
|
18
|
+
min: z.number().int(),
|
|
19
|
+
max: z.number().int(),
|
|
20
|
+
}))
|
|
21
|
+
.optional()
|
|
22
|
+
.describe("Required for mode=custom. Must be 5 entries."),
|
|
23
|
+
confirm: z.boolean().default(false),
|
|
24
|
+
},
|
|
25
|
+
async ({ mode, max_hr, zones, confirm }) => {
|
|
26
|
+
let path: string;
|
|
27
|
+
let body: unknown;
|
|
28
|
+
if (mode === "max_hr") {
|
|
29
|
+
if (max_hr === undefined) {
|
|
30
|
+
return {
|
|
31
|
+
content: [{ type: "text", text: jsonOut({ error: "mode=max_hr requires max_hr" }) }],
|
|
32
|
+
isError: true,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
path = "/hr-zones-service/v1/maxhr";
|
|
36
|
+
body = { max_heart_rate: max_hr };
|
|
37
|
+
} else {
|
|
38
|
+
if (!zones || zones.length !== 5) {
|
|
39
|
+
return {
|
|
40
|
+
content: [{ type: "text", text: jsonOut({ error: "mode=custom requires exactly 5 zones" }) }],
|
|
41
|
+
isError: true,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
path = "/hr-zones-service/v1/bff/custom";
|
|
45
|
+
body = { zones, is_custom: true };
|
|
46
|
+
}
|
|
47
|
+
if (!confirm) {
|
|
48
|
+
return {
|
|
49
|
+
content: [{ type: "text", text: jsonOut(preview("POST", path, { mode, summary: body })) }],
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
await client.post(path, body);
|
|
53
|
+
const out = HrZonesSetOut.parse({ updated: true as const, mode });
|
|
54
|
+
return { content: [{ type: "text", text: jsonOut(out) }] };
|
|
55
|
+
},
|
|
56
|
+
);
|
|
57
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import type { WhoopClient } from "../../whoop/client.js";
|
|
4
|
+
import { JournalOut } from "../../schemas/journal.js";
|
|
5
|
+
import { projectJournal } from "../../projections/journal.js";
|
|
6
|
+
import { WhoopProjectionError } from "../../whoop/errors.js";
|
|
7
|
+
import { jsonOut } from "../../whoop/json_out.js";
|
|
8
|
+
import { todayIso } from "../../lib/dates.js";
|
|
9
|
+
|
|
10
|
+
export function registerJournal(server: McpServer, client: WhoopClient): void {
|
|
11
|
+
server.tool(
|
|
12
|
+
"whoop_journal",
|
|
13
|
+
"Your journal entry for a date: tracked behaviors with values + human-readable names (resolved from the bundled catalog).",
|
|
14
|
+
{ date: z.iso.date().optional() },
|
|
15
|
+
async ({ date }) => {
|
|
16
|
+
const d = date ?? todayIso();
|
|
17
|
+
// v3 drafts is the authoritative endpoint for "what did I log".
|
|
18
|
+
// The v2 /behaviors/user/{date} endpoint returns the tracked-behaviors
|
|
19
|
+
// catalog (which behaviors the user has enabled), not the entries.
|
|
20
|
+
const raw = await client.get(`/journal-service/v3/journals/drafts/mobile/${d}`);
|
|
21
|
+
const projected = projectJournal(raw, d);
|
|
22
|
+
try {
|
|
23
|
+
const out = JournalOut.parse(projected);
|
|
24
|
+
return { content: [{ type: "text", text: jsonOut(out) }] };
|
|
25
|
+
} catch (e) {
|
|
26
|
+
if (e instanceof z.ZodError) throw new WhoopProjectionError("whoop_journal", e);
|
|
27
|
+
throw e;
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
);
|
|
31
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import type { WhoopClient } from "../../whoop/client.js";
|
|
4
|
+
import { JournalAutopopOut } from "../../schemas/journal.js";
|
|
5
|
+
import { preview } from "../../whoop/write_safety.js";
|
|
6
|
+
import { jsonOut } from "../../whoop/json_out.js";
|
|
7
|
+
|
|
8
|
+
export function registerJournalAutopop(server: McpServer, client: WhoopClient): void {
|
|
9
|
+
server.tool(
|
|
10
|
+
"whoop_journal_autopop",
|
|
11
|
+
"WRITE: trigger Whoop to auto-populate the journal from inferred behaviors (HealthKit data, workout patterns).",
|
|
12
|
+
{
|
|
13
|
+
cycle_id: z.number().int().describe("Get from whoop_journal or whoop_today."),
|
|
14
|
+
confirm: z.boolean().default(false),
|
|
15
|
+
},
|
|
16
|
+
async ({ cycle_id, confirm }) => {
|
|
17
|
+
const path = `/autopop-service/v1/autopop/JOURNAL/${cycle_id}`;
|
|
18
|
+
if (!confirm) {
|
|
19
|
+
return { content: [{ type: "text", text: jsonOut(preview("PUT", path, { cycle_id })) }] };
|
|
20
|
+
}
|
|
21
|
+
await client.put(path, {});
|
|
22
|
+
const out = JournalAutopopOut.parse({ triggered: true as const, cycle_id });
|
|
23
|
+
return { content: [{ type: "text", text: jsonOut(out) }] };
|
|
24
|
+
},
|
|
25
|
+
);
|
|
26
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { JournalCatalogOut } from "../../schemas/journal.js";
|
|
4
|
+
import { BEHAVIORS } from "../../data/behaviors.js";
|
|
5
|
+
import { jsonOut } from "../../whoop/json_out.js";
|
|
6
|
+
import { markConsulted } from "../../whoop/session_state.js";
|
|
7
|
+
|
|
8
|
+
const CATEGORIES = [
|
|
9
|
+
"Drugs & Medication",
|
|
10
|
+
"Health & Symptoms",
|
|
11
|
+
"Hormonal Health",
|
|
12
|
+
"Lifestyle",
|
|
13
|
+
"Mental Wellbeing",
|
|
14
|
+
"Nutrition",
|
|
15
|
+
"Recovery",
|
|
16
|
+
"Sleep & Circadian Health",
|
|
17
|
+
"Supplements",
|
|
18
|
+
] as const;
|
|
19
|
+
|
|
20
|
+
export function registerJournalCatalog(server: McpServer, _client: unknown): void {
|
|
21
|
+
server.tool(
|
|
22
|
+
"whoop_journal_catalog",
|
|
23
|
+
"Search the 308-behavior journal catalog to get a behavior_tracker_id and its magnitude type for whoop_journal_log. Filter by substring, magnitude_type (bare, boolean, or magnitude), or category (Drugs & Medication, Health & Symptoms, Hormonal Health, Lifestyle, Mental Wellbeing, Nutrition, Recovery, Sleep & Circadian Health, Supplements).",
|
|
24
|
+
{
|
|
25
|
+
category: z.enum(CATEGORIES).optional(),
|
|
26
|
+
search: z.string().optional(),
|
|
27
|
+
magnitude_type: z.enum(["bare", "boolean", "magnitude"]).optional(),
|
|
28
|
+
limit: z.number().int().min(1).max(308).default(100),
|
|
29
|
+
},
|
|
30
|
+
async ({ category, search, magnitude_type, limit }) => {
|
|
31
|
+
markConsulted("behaviors");
|
|
32
|
+
const s = search?.toLowerCase();
|
|
33
|
+
const matches = BEHAVIORS.filter((b) => {
|
|
34
|
+
if (category && b.category !== category) return false;
|
|
35
|
+
if (s && !(b.title.toLowerCase().includes(s) || b.internal_name.toLowerCase().includes(s))) return false;
|
|
36
|
+
if (magnitude_type && b.magnitude !== magnitude_type) return false;
|
|
37
|
+
return true;
|
|
38
|
+
});
|
|
39
|
+
const out = JournalCatalogOut.parse({
|
|
40
|
+
total_in_catalog: 308,
|
|
41
|
+
matched: matches.length,
|
|
42
|
+
truncated: matches.length > limit,
|
|
43
|
+
behaviors: matches.slice(0, limit),
|
|
44
|
+
});
|
|
45
|
+
return { content: [{ type: "text", text: jsonOut(out) }] };
|
|
46
|
+
},
|
|
47
|
+
);
|
|
48
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import type { WhoopClient } from "../../whoop/client.js";
|
|
4
|
+
import { JournalLogOut } from "../../schemas/journal.js";
|
|
5
|
+
import { preview } from "../../whoop/write_safety.js";
|
|
6
|
+
import { jsonOut } from "../../whoop/json_out.js";
|
|
7
|
+
import { todayIso } from "../../lib/dates.js";
|
|
8
|
+
import { BEHAVIORS_BY_ID } from "../../data/behaviors.js";
|
|
9
|
+
import { gateError } from "../../whoop/session_state.js";
|
|
10
|
+
|
|
11
|
+
export function registerJournalLog(server: McpServer, client: WhoopClient): void {
|
|
12
|
+
server.tool(
|
|
13
|
+
"whoop_journal_log",
|
|
14
|
+
"WRITE: save the full journal entry for a date — this REPLACES the whole day's entry, so first call whoop_journal to read what's already logged today and resend those entries together with your additions, or they'll be wiped. Use whoop_journal_catalog for each behavior_tracker_id and its magnitude type: bare → pass just the id, boolean → add answered_yes, magnitude → add magnitude_value.",
|
|
15
|
+
{
|
|
16
|
+
date: z.iso.date().optional(),
|
|
17
|
+
behaviors: z.array(z.object({
|
|
18
|
+
behavior_tracker_id: z.number().int(),
|
|
19
|
+
answered_yes: z.boolean().optional(),
|
|
20
|
+
magnitude_value: z.number().optional(),
|
|
21
|
+
magnitude_label: z.string().optional(),
|
|
22
|
+
})),
|
|
23
|
+
notes: z.string().optional(),
|
|
24
|
+
confirm: z.boolean().default(false),
|
|
25
|
+
},
|
|
26
|
+
async ({ date, behaviors, notes, confirm }) => {
|
|
27
|
+
const gate = gateError("behaviors", "whoop_journal_catalog");
|
|
28
|
+
if (gate) return { content: [{ type: "text", text: JSON.stringify(gate, null, 2) }], isError: true };
|
|
29
|
+
const d = date ?? todayIso();
|
|
30
|
+
const unknownIds = behaviors
|
|
31
|
+
.filter((b) => !BEHAVIORS_BY_ID.has(b.behavior_tracker_id))
|
|
32
|
+
.map((b) => b.behavior_tracker_id);
|
|
33
|
+
if (unknownIds.length > 0) {
|
|
34
|
+
return {
|
|
35
|
+
content: [
|
|
36
|
+
{
|
|
37
|
+
type: "text",
|
|
38
|
+
text: jsonOut({
|
|
39
|
+
error: "Unknown behavior_tracker_id",
|
|
40
|
+
unknown: unknownIds,
|
|
41
|
+
hint: "Use whoop_journal_catalog",
|
|
42
|
+
}),
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
isError: true,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const tracker_inputs = behaviors.map((b) => {
|
|
49
|
+
const input: Record<string, unknown> = { behavior_tracker_id: b.behavior_tracker_id };
|
|
50
|
+
if (b.answered_yes !== undefined) input.answered_yes = b.answered_yes;
|
|
51
|
+
if (b.magnitude_value !== undefined) {
|
|
52
|
+
input.magnitude_input_value = b.magnitude_value;
|
|
53
|
+
input.magnitude_input_label = b.magnitude_label ?? String(b.magnitude_value);
|
|
54
|
+
}
|
|
55
|
+
return input;
|
|
56
|
+
});
|
|
57
|
+
const body: Record<string, unknown> = { tracker_inputs };
|
|
58
|
+
if (notes !== undefined) body.notes = notes;
|
|
59
|
+
const path = `/journal-service/v2/journals/entries/user/date/${d}`;
|
|
60
|
+
if (!confirm) {
|
|
61
|
+
const sampleTitles = behaviors
|
|
62
|
+
.slice(0, 5)
|
|
63
|
+
.map((b) => BEHAVIORS_BY_ID.get(b.behavior_tracker_id)?.title ?? `#${b.behavior_tracker_id}`);
|
|
64
|
+
return {
|
|
65
|
+
content: [
|
|
66
|
+
{
|
|
67
|
+
type: "text",
|
|
68
|
+
text: jsonOut(
|
|
69
|
+
preview("PUT", path, {
|
|
70
|
+
date: d,
|
|
71
|
+
behaviors_count: behaviors.length,
|
|
72
|
+
sample_titles: sampleTitles,
|
|
73
|
+
}),
|
|
74
|
+
),
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
await client.put(path, body);
|
|
80
|
+
const out = JournalLogOut.parse({ logged: true as const, date: d, behaviors_count: behaviors.length });
|
|
81
|
+
return { content: [{ type: "text", text: jsonOut(out) }] };
|
|
82
|
+
},
|
|
83
|
+
);
|
|
84
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import type { WhoopClient } from "../../whoop/client.js";
|
|
4
|
+
import { LeaderboardOut } from "../../schemas/leaderboard.js";
|
|
5
|
+
import { projectLeaderboard } from "../../projections/leaderboard.js";
|
|
6
|
+
import { WhoopProjectionError } from "../../whoop/errors.js";
|
|
7
|
+
import { jsonOut } from "../../whoop/json_out.js";
|
|
8
|
+
import { todayIso } from "../../lib/dates.js";
|
|
9
|
+
|
|
10
|
+
export function registerLeaderboard(server: McpServer, client: WhoopClient): void {
|
|
11
|
+
server.tool(
|
|
12
|
+
"whoop_leaderboard",
|
|
13
|
+
"Community leaderboard ranking + your own position in it. Auto-discovers your first community if community_id is omitted. metric: recovery, sleep, or strain. window: day, week, or month.",
|
|
14
|
+
{
|
|
15
|
+
community_id: z.number().int().optional(),
|
|
16
|
+
date: z.iso.date().optional(),
|
|
17
|
+
window: z.enum(["day", "week", "month"]).default("day"),
|
|
18
|
+
metric: z.enum(["recovery", "sleep", "strain"]).default("recovery"),
|
|
19
|
+
},
|
|
20
|
+
async ({ community_id, date, window, metric }) => {
|
|
21
|
+
let cId = community_id;
|
|
22
|
+
let cName: string | null = null;
|
|
23
|
+
if (cId === undefined) {
|
|
24
|
+
const memberships = await client.get<{ records?: { id: number; name?: string }[] }>(
|
|
25
|
+
"/community-service/v1/communities/memberships",
|
|
26
|
+
);
|
|
27
|
+
const first = memberships.records?.[0];
|
|
28
|
+
if (!first) {
|
|
29
|
+
return {
|
|
30
|
+
content: [{ type: "text", text: jsonOut({ error: "no community memberships found" }) }],
|
|
31
|
+
isError: true,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
cId = first.id;
|
|
35
|
+
cName = first.name ?? null;
|
|
36
|
+
}
|
|
37
|
+
const d = date ?? todayIso();
|
|
38
|
+
const stat = metric === "recovery" ? "score" : metric === "sleep" ? "performance" : "day_strain";
|
|
39
|
+
const windowSeg = window === "day" ? d : `average/${window}`;
|
|
40
|
+
const userId = process.env.WHOOP_USER_ID;
|
|
41
|
+
// week/month leaderboards require startDate, endDate, and teamType params.
|
|
42
|
+
// Compute the window's date range.
|
|
43
|
+
function windowRange(): { startDate: string; endDate: string } {
|
|
44
|
+
const end = new Date(d + "T00:00:00Z");
|
|
45
|
+
const start = new Date(end);
|
|
46
|
+
if (window === "week") start.setUTCDate(end.getUTCDate() - 6);
|
|
47
|
+
else if (window === "month") start.setUTCDate(end.getUTCDate() - 29);
|
|
48
|
+
return { startDate: start.toISOString().slice(0, 10), endDate: end.toISOString().slice(0, 10) };
|
|
49
|
+
}
|
|
50
|
+
const params: Record<string, string> = { teamType: "COMMUNITY" };
|
|
51
|
+
if (window !== "day") {
|
|
52
|
+
const { startDate, endDate } = windowRange();
|
|
53
|
+
params.startDate = startDate;
|
|
54
|
+
params.endDate = endDate;
|
|
55
|
+
params.includeCompliance = "true";
|
|
56
|
+
params.complianceCutoff = "70";
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const [board, userRow] = await Promise.all([
|
|
60
|
+
client.get(
|
|
61
|
+
`/community-service/v1/leaderboards/communities/${cId}/${windowSeg}/${metric}/${stat}`,
|
|
62
|
+
params,
|
|
63
|
+
),
|
|
64
|
+
userId
|
|
65
|
+
? client
|
|
66
|
+
.get(
|
|
67
|
+
`/community-service/v1/leaderboards/communities/${cId}/${windowSeg}/${metric}/${stat}/user/${userId}`,
|
|
68
|
+
params,
|
|
69
|
+
)
|
|
70
|
+
.catch(() => null)
|
|
71
|
+
: Promise.resolve(null),
|
|
72
|
+
]);
|
|
73
|
+
|
|
74
|
+
const projected = projectLeaderboard({
|
|
75
|
+
community_id: cId,
|
|
76
|
+
community_name: cName,
|
|
77
|
+
window,
|
|
78
|
+
metric,
|
|
79
|
+
date: d,
|
|
80
|
+
board,
|
|
81
|
+
user_row: userRow,
|
|
82
|
+
});
|
|
83
|
+
try {
|
|
84
|
+
const out = LeaderboardOut.parse(projected);
|
|
85
|
+
return { content: [{ type: "text", text: jsonOut(out) }] };
|
|
86
|
+
} catch (e) {
|
|
87
|
+
if (e instanceof z.ZodError) throw new WhoopProjectionError("whoop_leaderboard", e);
|
|
88
|
+
throw e;
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
);
|
|
92
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { LiftCatalogOut } from "../../schemas/strength.js";
|
|
4
|
+
import { EXERCISES } from "../../data/exercises.js";
|
|
5
|
+
import { jsonOut } from "../../whoop/json_out.js";
|
|
6
|
+
import { markConsulted } from "../../whoop/session_state.js";
|
|
7
|
+
|
|
8
|
+
export function registerLiftCatalog(server: McpServer, _client: unknown): void {
|
|
9
|
+
server.tool(
|
|
10
|
+
"whoop_lift_catalog",
|
|
11
|
+
"Search the 372-exercise Strength Trainer catalog to get the exact exercise_id for whoop_lift_log, lift_exercise, or lift_progression. Filter by name substring, muscle, equipment, movement_pattern, or laterality (BILATERAL, LEFT, RIGHT, ALTERNATING), and read the id from the result.",
|
|
12
|
+
{
|
|
13
|
+
search: z.string().optional(),
|
|
14
|
+
muscle: z.string().optional(),
|
|
15
|
+
equipment: z.string().optional(),
|
|
16
|
+
movement_pattern: z.string().optional(),
|
|
17
|
+
laterality: z.enum(["BILATERAL", "LEFT", "RIGHT", "ALTERNATING"]).optional(),
|
|
18
|
+
limit: z.number().int().min(1).max(372).default(50),
|
|
19
|
+
},
|
|
20
|
+
async ({ search, muscle, equipment, movement_pattern, laterality, limit }) => {
|
|
21
|
+
markConsulted("exercises");
|
|
22
|
+
const s = search?.toLowerCase();
|
|
23
|
+
const matches = EXERCISES.filter((e) => {
|
|
24
|
+
if (s && !(e.name.toLowerCase().includes(s) || e.exercise_id.toLowerCase().includes(s))) return false;
|
|
25
|
+
if (muscle && !e.muscle_groups.includes(muscle.toUpperCase())) return false;
|
|
26
|
+
if (equipment && !e.equipment.toLowerCase().includes(equipment.toLowerCase())) return false;
|
|
27
|
+
if (movement_pattern && !e.movement_pattern.toLowerCase().includes(movement_pattern.toLowerCase())) return false;
|
|
28
|
+
if (laterality && e.laterality !== laterality) return false;
|
|
29
|
+
return true;
|
|
30
|
+
});
|
|
31
|
+
const out = LiftCatalogOut.parse({
|
|
32
|
+
total_in_catalog: 372,
|
|
33
|
+
matched: matches.length,
|
|
34
|
+
truncated: matches.length > limit,
|
|
35
|
+
exercises: matches.slice(0, limit).map((e) => ({
|
|
36
|
+
exercise_id: e.exercise_id,
|
|
37
|
+
name: e.name,
|
|
38
|
+
muscle_groups: [...e.muscle_groups],
|
|
39
|
+
primary_muscle: e.primary_muscle,
|
|
40
|
+
equipment: e.equipment,
|
|
41
|
+
movement_pattern: e.movement_pattern,
|
|
42
|
+
laterality: e.laterality,
|
|
43
|
+
})),
|
|
44
|
+
});
|
|
45
|
+
return { content: [{ type: "text", text: jsonOut(out) }] };
|
|
46
|
+
},
|
|
47
|
+
);
|
|
48
|
+
}
|