@trainheroic-unofficial/coach-mcp 0.6.1 → 0.6.3
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/README.md +1 -1
- package/dist/server.mjs +84 -6
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -69,7 +69,7 @@ The individual tool names the assistant calls are snake_case (e.g. `list_athlete
|
|
|
69
69
|
|
|
70
70
|
## Develop
|
|
71
71
|
|
|
72
|
-
Run `pnpm install` once at the repo root (Node >=
|
|
72
|
+
Run `pnpm install` once at the repo root (Node >= 24, pnpm 11), then from this package. The `pnpm start`/`pnpm inspect` commands need `TRAINHEROIC_EMAIL` and `TRAINHEROIC_PASSWORD` exported in your shell. "MCP Inspector" is the [official MCP debugging UI](https://github.com/modelcontextprotocol/inspector).
|
|
73
73
|
|
|
74
74
|
```bash
|
|
75
75
|
pnpm start # run from source
|
package/dist/server.mjs
CHANGED
|
@@ -726,9 +726,71 @@ async function getJson(client, path, label) {
|
|
|
726
726
|
if (!res.ok) throw new Error(`${label} failed (HTTP ${res.status}).`);
|
|
727
727
|
return res.data;
|
|
728
728
|
}
|
|
729
|
+
async function getArray(client, path, label) {
|
|
730
|
+
const res = await client.request("GET", path);
|
|
731
|
+
if (!res.ok || !Array.isArray(res.data)) throw new Error(`${label} failed (HTTP ${res.status}).`);
|
|
732
|
+
return res.data;
|
|
733
|
+
}
|
|
729
734
|
function fetchExerciseHistoryDetail(client, exerciseId, userId) {
|
|
730
735
|
return getJson(client, `/v5/exercises/${exerciseId}/history?userId=${userId}`, "athlete exercise history");
|
|
731
736
|
}
|
|
737
|
+
/**
|
|
738
|
+
* A coach's month view of a roster athlete's logged sessions
|
|
739
|
+
* (`/2.0/coach/athlete/calendar/summary`). The trailing path segment is required by the API but
|
|
740
|
+
* ignored (any value returns the whole month); it mirrors the coach web app, which sends 7. The
|
|
741
|
+
* `userId` in each row is the roster athlete, not the calling coach.
|
|
742
|
+
*/
|
|
743
|
+
function fetchCoachAthleteCalendarSummary(client, athleteId, year, month) {
|
|
744
|
+
return getArray(client, `/2.0/coach/athlete/calendar/summary/${athleteId}/${year}/${month}/7`, "coach athlete calendar summary");
|
|
745
|
+
}
|
|
746
|
+
/**
|
|
747
|
+
* Flatten the coach athlete-calendar summary into compact per-session rows: title, the `logged`
|
|
748
|
+
* flag (the reliable did-they-train signal), rpe/duration/notes, and the exercises performed with
|
|
749
|
+
* the API's own set summary string (`abr`, e.g. "5 x 2 @ 205 lb"). The exercise titles here are
|
|
750
|
+
* the discovery handle a coach otherwise lacks: read what the athlete actually did, then pull the
|
|
751
|
+
* specific lift's PRs.
|
|
752
|
+
*/
|
|
753
|
+
function presentCoachAthleteTraining(raw, athleteId, year, month) {
|
|
754
|
+
const sessions = [];
|
|
755
|
+
let athleteName = null;
|
|
756
|
+
for (const item of raw) {
|
|
757
|
+
if (!isRecord(item)) continue;
|
|
758
|
+
if (athleteName === null && typeof item.athleteName === "string") athleteName = item.athleteName;
|
|
759
|
+
const exercises = [];
|
|
760
|
+
const sets = Array.isArray(item.sets) ? item.sets : [];
|
|
761
|
+
for (const set of sets) {
|
|
762
|
+
if (!isRecord(set)) continue;
|
|
763
|
+
const exs = Array.isArray(set.exercises) ? set.exercises : [];
|
|
764
|
+
for (const ex of exs) {
|
|
765
|
+
if (!isRecord(ex)) continue;
|
|
766
|
+
exercises.push({
|
|
767
|
+
exerciseId: coerceInt(ex.exercise_id),
|
|
768
|
+
title: typeof ex.title === "string" ? ex.title : "",
|
|
769
|
+
summary: typeof ex.abr === "string" && ex.abr !== "" ? ex.abr : null,
|
|
770
|
+
completed: coerceInt(ex.completed) === 1
|
|
771
|
+
});
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
sessions.push({
|
|
775
|
+
workoutId: coerceInt(item.workout_id),
|
|
776
|
+
savedWorkoutId: coerceInt(item.saved_workout_id),
|
|
777
|
+
title: typeof item.workout_title === "string" ? item.workout_title : "",
|
|
778
|
+
logged: coerceInt(item.logged) === 1,
|
|
779
|
+
completed: coerceInt(item.completed) === 1,
|
|
780
|
+
rpe: coerceInt(item.rpe),
|
|
781
|
+
durationMin: coerceInt(item.session_duration),
|
|
782
|
+
notes: typeof item.notes === "string" && item.notes !== "" ? item.notes : null,
|
|
783
|
+
exercises
|
|
784
|
+
});
|
|
785
|
+
}
|
|
786
|
+
return {
|
|
787
|
+
athleteId,
|
|
788
|
+
athleteName,
|
|
789
|
+
year,
|
|
790
|
+
month,
|
|
791
|
+
sessions
|
|
792
|
+
};
|
|
793
|
+
}
|
|
732
794
|
/** Flatten `/v5/exercises/{id}/history` into PRs + a session time-series. */
|
|
733
795
|
function presentExerciseHistory(detail) {
|
|
734
796
|
return {
|
|
@@ -1338,7 +1400,8 @@ function historyInRange(presented, since, until) {
|
|
|
1338
1400
|
}
|
|
1339
1401
|
//#endregion
|
|
1340
1402
|
//#region ../core/src/tools/reads.ts
|
|
1341
|
-
const ATHLETE_LIFT_HISTORY_DESC = "A roster athlete's lift history for ONE exercise: the all-time PR board (liftPRs — each entry carries its rep-max label, weight, and the date it was set) plus the dated session series (sets, estimated 1RM). This is the coach-side way to answer 'show me <athlete>'s PRs / how is <athlete>'s squat trending' — pass athleteId from list_athletes and exerciseId from exercise_resolve. There is no cross-exercise PR
|
|
1403
|
+
const ATHLETE_LIFT_HISTORY_DESC = "A roster athlete's lift history for ONE exercise: the all-time PR board (liftPRs — each entry carries its rep-max label, weight, and the date it was set) plus the dated session series (sets, estimated 1RM). This is the coach-side way to answer 'show me <athlete>'s PRs / how is <athlete>'s squat trending' — pass athleteId from list_athletes and exerciseId from exercise_resolve. There is no cross-exercise PR rollup, so you query one lift at a time, but do NOT guess lift names blindly: first call athlete_training for the month(s) of interest — it lists every exercise the athlete actually performed (with the exact exercise the program used, e.g. 'Clean & Jerk' not 'Clean') — then bring those exerciseIds here. An empty result means that lift was not logged. liftPRs stay all-time; pass since/until (YYYY-MM-DD, inclusive) to window the session series. raw:true returns the untouched API object.";
|
|
1404
|
+
const ATHLETE_TRAINING_DESC = "A roster athlete's training for one calendar month (coach-side): one row per session with its title, the `logged` flag (the reliable did-they-train signal — true means they logged it), rpe, duration (minutes), notes, and the exercises they performed, each with a set summary like '5 x 2 @ 205 lb'. Use this to answer 'how has <athlete> been training lately' in ONE call, and as the discovery handle a coach otherwise lacks: read the exercise titles here to learn what the athlete actually did, then pass the lifts you care about to athlete_lift_history for their dated PR board. Pass athleteId from list_athletes and a year + month (1-12); query the current month, and the previous month for more history. Sessions are in calendar order within the month (the API carries no per-session date). An empty list means no sessions that month.";
|
|
1342
1405
|
function enc(value) {
|
|
1343
1406
|
return encodeURIComponent(String(value));
|
|
1344
1407
|
}
|
|
@@ -1385,7 +1448,7 @@ function registerRosterReads(server, ctx) {
|
|
|
1385
1448
|
}, () => apiCall(ctx, "GET", t.path));
|
|
1386
1449
|
server.registerTool("list_athletes", {
|
|
1387
1450
|
title: "List athletes",
|
|
1388
|
-
description: "Every athlete on this coach's org roster, across all teams (not scoped to one team
|
|
1451
|
+
description: "Every athlete on this coach's org roster, across all teams (not scoped to one team; the account owner themselves and demo/placeholder athletes are included, so the roster count includes you). `daysSinceLastLogin` is app-login recency, not training activity — an athlete can have logged in today yet have no logged sessions; null means no login on record. For per-team attribution use each athlete's own `groups`/`groupTitles` (the teams they are enrolled in) and `teamCount`; there is no per-team roster endpoint or other per-athlete team field. Optional q (case-insensitive; each whitespace-separated word must appear in the record, so 'Kyle Jones' matches a 'Jones, [Demo] Kyle' entry) and limit, applied client-side, keep large rosters small.",
|
|
1389
1452
|
inputSchema: {
|
|
1390
1453
|
q: z.string().optional(),
|
|
1391
1454
|
limit: z.number().int().positive().max(500).optional()
|
|
@@ -1400,8 +1463,11 @@ function registerRosterReads(server, ctx) {
|
|
|
1400
1463
|
if (!Array.isArray(res.data)) return jsonResult(res.data);
|
|
1401
1464
|
let rows = res.data;
|
|
1402
1465
|
if (q !== void 0) {
|
|
1403
|
-
const
|
|
1404
|
-
rows = rows.filter((row) =>
|
|
1466
|
+
const needles = q.toLowerCase().split(/\s+/).filter((t) => t.length > 0);
|
|
1467
|
+
rows = rows.filter((row) => {
|
|
1468
|
+
const hay = JSON.stringify(row).toLowerCase();
|
|
1469
|
+
return needles.every((n) => hay.includes(n));
|
|
1470
|
+
});
|
|
1405
1471
|
}
|
|
1406
1472
|
const total = rows.length;
|
|
1407
1473
|
if (limit !== void 0 && rows.length > limit) return jsonResult({
|
|
@@ -1460,6 +1526,18 @@ function registerEntityReads(server, ctx) {
|
|
|
1460
1526
|
if (raw === true) return jsonResult(detail);
|
|
1461
1527
|
return jsonResult(historyInRange(presentExerciseHistory(detail), since, until));
|
|
1462
1528
|
}));
|
|
1529
|
+
server.registerTool("athlete_training", {
|
|
1530
|
+
title: "Athlete training month (roster)",
|
|
1531
|
+
description: ATHLETE_TRAINING_DESC,
|
|
1532
|
+
inputSchema: {
|
|
1533
|
+
athleteId: idParam,
|
|
1534
|
+
year: z.number().int(),
|
|
1535
|
+
month: z.number().int().min(1).max(12)
|
|
1536
|
+
},
|
|
1537
|
+
annotations: READ
|
|
1538
|
+
}, ({ athleteId, year, month }) => attempt(async () => {
|
|
1539
|
+
return jsonResult(presentCoachAthleteTraining(await fetchCoachAthleteCalendarSummary(ctx.client, toId(athleteId), year, month), toId(athleteId), year, month), { hint: "One session per row for the month. Use the exercise titles to pick lifts, then athlete_lift_history for their PRs." });
|
|
1540
|
+
}));
|
|
1463
1541
|
server.registerTool("get_program", {
|
|
1464
1542
|
title: "Get program detail",
|
|
1465
1543
|
description: "Full nested program structure (blocks + sessions) live from the API, by program id.",
|
|
@@ -1702,7 +1780,7 @@ const BODY_KEY = {
|
|
|
1702
1780
|
function registerAnalyticsTools(server, ctx) {
|
|
1703
1781
|
server.registerTool("analytics_query", {
|
|
1704
1782
|
title: "Pull an analytics report",
|
|
1705
|
-
description: "Read a TrainHeroic analytics report. The `metric` enum below IS the catalog — pick from it directly (analytics_categories lists the API's raw category names, which do NOT match these keys; you rarely need it). Team metrics (readiness-team, compliance-team, lift-progress-team) need teamId; athlete metrics (readiness-athlete, training-summary-athlete, lift-1rm-history, working-max-history) need userIds — get those from list_athletes. userIds takes MANY athletes in ONE call (pass the whole roster's ids at once); the report comes back with a row per athlete, so do not loop one id per call. For team-wide training volume there is no team summary metric: pass every athlete's userId to training-summary-athlete in a single call and the rows cover the team. An athlete with no logged sessions in range simply returns no rows (not an error). readiness-team takes a single `date`; every other metric takes dateStart/dateEnd. lift-1rm-history, lift-progress-team, and working-max-history also need exerciseId. All dates are YYYY-MM-DD.",
|
|
1783
|
+
description: "Read a TrainHeroic analytics report. The `metric` enum below IS the catalog — pick from it directly (analytics_categories lists the API's raw category names, which do NOT match these keys; you rarely need it). Team metrics (readiness-team, compliance-team, lift-progress-team) need teamId; athlete metrics (readiness-athlete, training-summary-athlete, lift-1rm-history, working-max-history) need userIds — get those from list_athletes. userIds takes MANY athletes in ONE call (pass the whole roster's ids at once); the report comes back with a row per athlete, so do not loop one id per call. For team-wide training volume there is no team summary metric: pass every athlete's userId to training-summary-athlete in a single call and the rows cover the team. An athlete with no logged sessions in range simply returns no rows (not an error). Use that for triage: training-summary-athlete with a single athleteId is the fastest 'has this athlete trained at all, and when' check — no rows means no logged training in range, so don't then fan out blind per-lift athlete_lift_history calls. Despite 'athlete' in the name this metric accepts 1–N userIds. readiness-team takes a single `date`; every other metric takes dateStart/dateEnd. lift-1rm-history, lift-progress-team, and working-max-history also need exerciseId. All dates are YYYY-MM-DD.",
|
|
1706
1784
|
inputSchema: {
|
|
1707
1785
|
metric: z.enum(METRIC_KEYS),
|
|
1708
1786
|
teamId: idParam.optional(),
|
|
@@ -2078,7 +2156,7 @@ var JsonFileLibraryCache = class {
|
|
|
2078
2156
|
};
|
|
2079
2157
|
//#endregion
|
|
2080
2158
|
//#region package.json
|
|
2081
|
-
var version = "0.6.
|
|
2159
|
+
var version = "0.6.3";
|
|
2082
2160
|
//#endregion
|
|
2083
2161
|
//#region src/server.ts
|
|
2084
2162
|
async function main() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trainheroic-unofficial/coach-mcp",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
23
23
|
"zod": "^4.4.3",
|
|
24
|
-
"@trainheroic-unofficial/core": "0.6.
|
|
25
|
-
"@trainheroic-unofficial/js": "0.6.
|
|
24
|
+
"@trainheroic-unofficial/core": "0.6.3",
|
|
25
|
+
"@trainheroic-unofficial/js": "0.6.3"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/node": "^26.0.0",
|