@trainheroic-unofficial/coach-mcp 0.6.3 → 0.6.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.
Files changed (2) hide show
  1. package/dist/server.mjs +72 -2
  2. package/package.json +3 -3
package/dist/server.mjs CHANGED
@@ -731,6 +731,66 @@ async function getArray(client, path, label) {
731
731
  if (!res.ok || !Array.isArray(res.data)) throw new Error(`${label} failed (HTTP ${res.status}).`);
732
732
  return res.data;
733
733
  }
734
+ /** Lifetime training totals. `use_metric` is required by the API (omitting it 400s). */
735
+ function fetchAthleteProfileSummary(client, userId, useMetric = false) {
736
+ return getJson(client, `/v5/athleteProfile/summary?user_id=${userId}&use_metric=${useMetric ? 1 : 0}`, "athlete profile summary");
737
+ }
738
+ /**
739
+ * Sort a roster-activity list most-recently-active first; never-logged rows (null date) last.
740
+ * Athletes tied on lastLoggedDate break by session count (more sessions first), so a tie is not
741
+ * left to arbitrary input order.
742
+ */
743
+ function sortRosterByRecency(rows) {
744
+ return [...rows].sort((a, b) => {
745
+ if (a.lastLoggedDate !== b.lastLoggedDate) {
746
+ if (a.lastLoggedDate === null) return 1;
747
+ if (b.lastLoggedDate === null) return -1;
748
+ return a.lastLoggedDate < b.lastLoggedDate ? 1 : -1;
749
+ }
750
+ return (b.sessionsCount ?? 0) - (a.sessionsCount ?? 0);
751
+ });
752
+ }
753
+ /**
754
+ * A coach's roster-activity ranking: each athlete's all-time training snapshot (session count,
755
+ * first/last logged date, total reps/volume), sorted most-recently-active first. There is no
756
+ * single roster-activity endpoint, so this fans out `/v5/athleteProfile/summary` per athlete with
757
+ * a small concurrency cap; pass the subset you care about for a large org. A failed or missing
758
+ * summary becomes a null-data row (sorted last), not an error.
759
+ */
760
+ async function fetchRosterActivity(client, athleteIds, useMetric = false) {
761
+ const rows = [];
762
+ const concurrency = 6;
763
+ for (let i = 0; i < athleteIds.length; i += concurrency) {
764
+ const chunk = athleteIds.slice(i, i + concurrency);
765
+ const settled = await Promise.all(chunk.map(async (id) => {
766
+ try {
767
+ return {
768
+ id,
769
+ summary: await fetchAthleteProfileSummary(client, id, useMetric)
770
+ };
771
+ } catch {
772
+ return {
773
+ id,
774
+ summary: null
775
+ };
776
+ }
777
+ }));
778
+ for (const { id, summary } of settled) {
779
+ const count = summary?.sessions_count ?? null;
780
+ const hasSessions = count !== null && count > 0;
781
+ const normDate = (d) => hasSessions && d !== void 0 && d !== "" && !d.startsWith("1970") ? d : null;
782
+ rows.push({
783
+ athleteId: id,
784
+ sessionsCount: count,
785
+ firstLoggedDate: normDate(summary?.first_logged_date),
786
+ lastLoggedDate: normDate(summary?.last_logged_date),
787
+ totalReps: summary?.reps_sum ?? null,
788
+ totalVolume: summary?.volume_sum ?? null
789
+ });
790
+ }
791
+ }
792
+ return sortRosterByRecency(rows);
793
+ }
734
794
  function fetchExerciseHistoryDetail(client, exerciseId, userId) {
735
795
  return getJson(client, `/v5/exercises/${exerciseId}/history?userId=${userId}`, "athlete exercise history");
736
796
  }
@@ -1401,6 +1461,7 @@ function historyInRange(presented, since, until) {
1401
1461
  //#endregion
1402
1462
  //#region ../core/src/tools/reads.ts
1403
1463
  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.";
1464
+ const ROSTER_ACTIVITY_DESC = "A coach's roster ranked by actual training recency: for each athleteId you pass (from list_athletes), the all-time sessionsCount, firstLoggedDate, lastLoggedDate, totalReps and totalVolume, sorted most-recently-active first. Use lastLoggedDate — the real training signal — NOT list_athletes' daysSinceLastLogin (app-login, not training) to answer 'who is my most recently active athlete' (the top row) or 'who is falling behind' (a stale or null lastLoggedDate, or low volume). A null lastLoggedDate means the athlete has never logged a session. This fans out one lookup per athlete, so for a large org pass only the athletes you care about. Then drill into a name with athlete_training (their month) or athlete_lift_history.";
1404
1465
  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.";
1405
1466
  function enc(value) {
1406
1467
  return encodeURIComponent(String(value));
@@ -1448,7 +1509,7 @@ function registerRosterReads(server, ctx) {
1448
1509
  }, () => apiCall(ctx, "GET", t.path));
1449
1510
  server.registerTool("list_athletes", {
1450
1511
  title: "List athletes",
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.",
1512
+ 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. To rank athletes by real training recency (most recently active, or who is falling behind), pass their ids to roster_activity instead of reading daysSinceLastLogin. 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.",
1452
1513
  inputSchema: {
1453
1514
  q: z.string().optional(),
1454
1515
  limit: z.number().int().positive().max(500).optional()
@@ -1526,6 +1587,15 @@ function registerEntityReads(server, ctx) {
1526
1587
  if (raw === true) return jsonResult(detail);
1527
1588
  return jsonResult(historyInRange(presentExerciseHistory(detail), since, until));
1528
1589
  }));
1590
+ server.registerTool("roster_activity", {
1591
+ title: "Roster training activity (recency)",
1592
+ description: ROSTER_ACTIVITY_DESC,
1593
+ inputSchema: {
1594
+ athleteIds: z.array(idParam).min(1),
1595
+ useMetric: z.boolean().optional()
1596
+ },
1597
+ annotations: READ
1598
+ }, ({ athleteIds, useMetric }) => attempt(async () => jsonResult(await fetchRosterActivity(ctx.client, athleteIds.map(toId), useMetric ?? false), { hint: "Sorted most-recently-active first; lastLoggedDate null = never logged. The top row is the most recently active athlete." })));
1529
1599
  server.registerTool("athlete_training", {
1530
1600
  title: "Athlete training month (roster)",
1531
1601
  description: ATHLETE_TRAINING_DESC,
@@ -2156,7 +2226,7 @@ var JsonFileLibraryCache = class {
2156
2226
  };
2157
2227
  //#endregion
2158
2228
  //#region package.json
2159
- var version = "0.6.3";
2229
+ var version = "0.6.4";
2160
2230
  //#endregion
2161
2231
  //#region src/server.ts
2162
2232
  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",
3
+ "version": "0.6.4",
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.3",
25
- "@trainheroic-unofficial/js": "0.6.3"
24
+ "@trainheroic-unofficial/core": "0.6.4",
25
+ "@trainheroic-unofficial/js": "0.6.4"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@types/node": "^26.0.0",