@trainheroic-unofficial/athlete-mcp 4.2.0 → 4.3.0

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 +44 -58
  2. package/package.json +8 -8
package/dist/server.mjs CHANGED
@@ -2,7 +2,7 @@ import { CLIENT_CAPABILITIES_META_KEY, McpServer, acceptedContent, inputRequired
2
2
  import { serveStdio } from "@modelcontextprotocol/server/stdio";
3
3
  import process from "node:process";
4
4
  import { z } from "zod";
5
- //#region ../dto/src/common.ts
5
+ // ../dto/src/common.ts
6
6
  /** An entity id as it arrives over the wire — a number or a numeric string. */
7
7
  const idSchema = z.union([z.string(), z.number()]);
8
8
  /**
@@ -11,8 +11,7 @@ const idSchema = z.union([z.string(), z.number()]);
11
11
  * a bad argument fails validation instead of becoming NaN in a URL or a query.
12
12
  */
13
13
  const idArgSchema = z.union([z.number().int(), z.string().regex(/^\d+$/u)]);
14
- //#endregion
15
- //#region ../dto/src/athlete.ts
14
+ // ../dto/src/athlete.ts
16
15
  const intLike$1 = z.union([z.number(), z.string()]);
17
16
  const intLikeOrNull$1 = z.union([
18
17
  z.number(),
@@ -416,8 +415,7 @@ const presentedExerciseHistorySchema = z.object({
416
415
  });
417
416
  /** Presented history first so the loose raw detail schema cannot swallow it. */
418
417
  const exerciseHistoryOutputSchema = z.union([presentedExerciseHistorySchema, exerciseHistoryDetailSchema]);
419
- //#endregion
420
- //#region ../dto/src/exercise.ts
418
+ // ../dto/src/exercise.ts
421
419
  /**
422
420
  * A row presented for display. The raw param-type codes are dropped and the fixed
423
421
  * measurement units are surfaced positionally in `units`, ordered by entry slot
@@ -476,8 +474,7 @@ z.object({
476
474
  text: z.string().min(1),
477
475
  replyTo: idSchema.optional()
478
476
  });
479
- //#endregion
480
- //#region ../dto/src/responses.ts
477
+ // ../dto/src/responses.ts
481
478
  const intLike = z.union([z.number(), z.string()]);
482
479
  const intLikeOrNull = z.union([
483
480
  z.number(),
@@ -519,8 +516,7 @@ z.object({
519
516
  pub_time: z.unknown().optional(),
520
517
  pub_timezone: z.string().optional()
521
518
  }).refine((v) => v.pub_enabled !== void 0 || v.pub_days !== void 0 || v.pub_time !== void 0 || v.pub_timezone !== void 0, { message: "Provide at least one pub_* field" });
522
- //#endregion
523
- //#region ../dto/src/tool-output.ts
519
+ // ../dto/src/tool-output.ts
524
520
  const nullableNumber = z.number().nullable();
525
521
  const nullableString = z.string().nullable();
526
522
  const truncationMarkerSchema = z.looseObject({
@@ -656,6 +652,7 @@ const workoutReadBlockOutputSchema = z.object({
656
652
  });
657
653
  const workoutReadOutputSchema = z.object({
658
654
  pwId: z.number(),
655
+ workoutId: z.number().nullable(),
659
656
  date: z.string(),
660
657
  published: z.json().optional(),
661
658
  instruction: z.string(),
@@ -723,8 +720,7 @@ z.object({
723
720
  programId: z.number(),
724
721
  containerId: nullableNumber
725
722
  });
726
- //#endregion
727
- //#region ../dto/src/workout.ts
723
+ // ../dto/src/workout.ts
728
724
  /** A single exercise prescription inside a block. */
729
725
  const exerciseSpecSchema = z.object({
730
726
  id: z.union([z.number(), z.string()]),
@@ -736,8 +732,8 @@ const exerciseSpecSchema = z.object({
736
732
  ]).optional().describe("Primary slot values; may be reps, distance, or time. State primaryUnit."),
737
733
  sets: z.number().optional(),
738
734
  weight: z.union([z.number(), z.array(z.number())]).optional().describe("Secondary slot values; may be weight or time. State secondaryUnit."),
739
- primaryUnit: z.string().trim().min(1).optional().describe("Intended primary unit from exercise_resolve, such as reps, m, mi, or sec."),
740
- secondaryUnit: z.string().trim().min(1).optional().describe("Intended secondary unit from exercise_resolve, such as lb or sec."),
735
+ primaryUnit: z.string().trim().min(1).optional().describe("Unit of the primary values, such as reps, m, mi, or sec. A unit other than the exercise's default from exercise_resolve is set on this session."),
736
+ secondaryUnit: z.string().trim().min(1).optional().describe("Unit of the secondary values, such as lb, %max, RPE, or sec. A unit other than the exercise's default from exercise_resolve is set on this session."),
741
737
  rpe: z.union([z.number(), z.string()]).optional(),
742
738
  instr: z.string().optional(),
743
739
  param_1_type: z.number().optional(),
@@ -797,8 +793,12 @@ z.object({
797
793
  title: z.string().min(1),
798
794
  instruction: z.string().optional()
799
795
  });
800
- //#endregion
801
- //#region ../core/src/context.ts
796
+ z.object({
797
+ workoutId: z.number().int().describe("The session's workout_id (workout_build returns it as workoutId)."),
798
+ pwId: z.number().int().describe("The session's programWorkout id (workout_build returns it as pwId)."),
799
+ title: z.string().trim().min(1).describe("Title of the new library template.")
800
+ });
801
+ // ../core/src/context.ts
802
802
  /** A tool argument that accepts a numeric id as a number or a string of digits. */
803
803
  const idParam = idArgSchema;
804
804
  function toId(value) {
@@ -978,8 +978,7 @@ function errorResult(message) {
978
978
  }]
979
979
  };
980
980
  }
981
- //#endregion
982
- //#region ../core/src/confirm.ts
981
+ // ../core/src/confirm.ts
983
982
  /**
984
983
  * Returned when the user was asked and said no. It must not tell the model how to retry: the
985
984
  * refusal is the answer. (The `confirm: true` fallback for clients that cannot elicit is
@@ -1035,8 +1034,7 @@ function confirmGate(ctx, message, confirmArg) {
1035
1034
  }
1036
1035
  }) } });
1037
1036
  }
1038
- //#endregion
1039
- //#region ../core/src/instructions.ts
1037
+ // ../core/src/instructions.ts
1040
1038
  /**
1041
1039
  * Server-level guidance passed as the MCP `instructions` string. The host model receives it
1042
1040
  * in the initialize result and treats it like a system hint. Its job is to stop tool-layer
@@ -1046,8 +1044,7 @@ function confirmGate(ctx, message, confirmArg) {
1046
1044
  * leak further. This tells the host to keep that wiring internal and speak in app terms.
1047
1045
  */
1048
1046
  const SERVER_INSTRUCTIONS = "Speak to the user in plain, everyday language about their training. Describe what you are doing in the TrainHeroic app's own terms (for example, say you are creating a workout rather than naming a tool). Do not surface internal tool names (the snake_case identifiers such as athlete_session_create), raw parameter names, or numeric ids in your replies unless the user explicitly asks for them; they are implementation details. The tool descriptions cross-reference each other by name only so you can chain them correctly. Keep that wiring to yourself.";
1049
- //#endregion
1050
- //#region ../js/src/date-window.ts
1047
+ // ../js/src/date-window.ts
1051
1048
  const DAY_MS = 864e5;
1052
1049
  const ISO_DAY = /^\d{4}-\d{2}-\d{2}$/u;
1053
1050
  function dayNumber(value) {
@@ -1062,8 +1059,7 @@ function dateSpanDays(start, end) {
1062
1059
  const last = dayNumber(end);
1063
1060
  return first === null || last === null || first > last ? null : last - first + 1;
1064
1061
  }
1065
- //#endregion
1066
- //#region ../js/src/http-error.ts
1062
+ // ../js/src/http-error.ts
1067
1063
  const MAX_REQUEST_KEYS = 50;
1068
1064
  const MAX_RESPONSE_DEPTH = 4;
1069
1065
  const MAX_RESPONSE_KEYS = 20;
@@ -1293,11 +1289,9 @@ function notifyHttpError(handler, method, url, status, diagnostics = {}) {
1293
1289
  Promise.resolve(handler(new TrainHeroicHttpError(method, url, status, diagnostics))).catch(() => {});
1294
1290
  } catch {}
1295
1291
  }
1296
- //#endregion
1297
- //#region ../js/src/transport.ts
1292
+ // ../js/src/transport.ts
1298
1293
  const defaultTrainHeroicTransport = (url, init) => fetch(url, init);
1299
- //#endregion
1300
- //#region ../js/src/auth.ts
1294
+ // ../js/src/auth.ts
1301
1295
  const DEFAULT_AUTH_URL = "https://apis.trainheroic.com/auth";
1302
1296
  /**
1303
1297
  * The login endpoint, allowing an env override so a test harness can authenticate against a local
@@ -1348,13 +1342,12 @@ async function loginTrainHeroic(email, password, options = {}) {
1348
1342
  role: data.role ?? ""
1349
1343
  };
1350
1344
  }
1351
- //#endregion
1352
- //#region ../js/src/exercise-util.ts
1345
+ // ../js/src/exercise-util.ts
1353
1346
  /**
1354
- * Display labels for TrainHeroic parameter types. The unit is FIXED PER EXERCISE
1355
- * (the API forces param_1_type/param_2_type back to the library default on save), so
1356
- * resolve/search surface it to stop callers picking, say, the miles "Run" for a
1357
- * metric workout. Keep in sync with the workout builder's unit table.
1347
+ * Display labels for TrainHeroic parameter types. Each library exercise has a default type per
1348
+ * slot, which resolve/search surface so callers know, say, that stock "Run" defaults to miles.
1349
+ * A session can set a different type on an exercise; the workout builder maps a stated unit
1350
+ * back to its type code through this table, so keep it in sync with the builder's unit aliases.
1358
1351
  */
1359
1352
  const PARAM_UNIT = {
1360
1353
  0: null,
@@ -1387,7 +1380,7 @@ function unitLabel(paramType) {
1387
1380
  return PARAM_UNIT[t] ?? null;
1388
1381
  }
1389
1382
  /**
1390
- * Fixed measurement units for an exercise, ordered by entry slot (param 1, then param 2).
1383
+ * Default measurement units for an exercise, ordered by entry slot (param 1, then param 2).
1391
1384
  * Positional, not semantic: some exercises reverse the slots, so the array is not labelled
1392
1385
  * by role. A null entry is an unset slot.
1393
1386
  */
@@ -1527,8 +1520,7 @@ function createLimiter(max) {
1527
1520
  function assertPositiveInteger(value, label) {
1528
1521
  if (!Number.isInteger(value) || value < 1) throw new RangeError(`${label} must be a positive integer; received ${value}.`);
1529
1522
  }
1530
- //#endregion
1531
- //#region ../js/src/client.ts
1523
+ // ../js/src/client.ts
1532
1524
  const DEFAULT_COACH_BASE = "https://api.trainheroic.com";
1533
1525
  const DEFAULT_APIS_BASE = "https://apis.trainheroic.com";
1534
1526
  const MAX_REQUEST_CONCURRENCY = 4;
@@ -1648,8 +1640,7 @@ var TrainHeroicClient = class {
1648
1640
  return this.#transport(url, init);
1649
1641
  }
1650
1642
  };
1651
- //#endregion
1652
- //#region ../js/src/athlete.ts
1643
+ // ../js/src/athlete.ts
1653
1644
  async function getJson(client, path, label) {
1654
1645
  const res = await client.request("GET", path);
1655
1646
  if (!res.ok) throw new Error(`${label} failed (HTTP ${res.status}).`);
@@ -2136,8 +2127,7 @@ function presentExerciseHistory(detail) {
2136
2127
  }))
2137
2128
  };
2138
2129
  }
2139
- //#endregion
2140
- //#region ../js/src/exercise-history.ts
2130
+ // ../js/src/exercise-history.ts
2141
2131
  /**
2142
2132
  * Trim a presented exercise history's session time-series to an inclusive YYYY-MM-DD window.
2143
2133
  * The `liftPRs` board stays all-time (PRs are not a windowed concept). Dates compare as their
@@ -2158,8 +2148,7 @@ function historyInRange(presented, since, until) {
2158
2148
  sessions
2159
2149
  };
2160
2150
  }
2161
- //#endregion
2162
- //#region ../js/src/exercise-set-payload.ts
2151
+ // ../js/src/exercise-set-payload.ts
2163
2152
  function slotData(exercise, key) {
2164
2153
  const value = exercise?.[key];
2165
2154
  return value === void 0 || value === null ? "" : String(value);
@@ -2227,8 +2216,7 @@ function buildExerciseSetPayload(savedWorkoutSetExerciseId, savedWorkoutSetId, w
2227
2216
  body.completed = logging && anyMade && allActiveSlotsMade ? 1 : 0;
2228
2217
  return body;
2229
2218
  }
2230
- //#endregion
2231
- //#region ../js/src/athlete-set-write.ts
2219
+ // ../js/src/athlete-set-write.ts
2232
2220
  const WRITE_CONCURRENCY = 4;
2233
2221
  /**
2234
2222
  * Coerce the loosely-typed `results` from a validated log/prescribe args object into the SDK's
@@ -2749,8 +2737,7 @@ async function logAdHocSession(client, args) {
2749
2737
  if (scheduledAlternatives.length > 0) result.scheduledAlternatives = scheduledAlternatives;
2750
2738
  return result;
2751
2739
  }
2752
- //#endregion
2753
- //#region ../js/src/util.ts
2740
+ // ../js/src/util.ts
2754
2741
  /**
2755
2742
  * Drop the keys whose value is `undefined`, so the result can be passed to a function or
2756
2743
  * spread into an object under `exactOptionalPropertyTypes` without the per-key
@@ -2765,8 +2752,7 @@ function definedProps(obj) {
2765
2752
  for (const [key, value] of Object.entries(obj)) if (value !== void 0) result[key] = value;
2766
2753
  return result;
2767
2754
  }
2768
- //#endregion
2769
- //#region ../js/src/athlete-workout-note.ts
2755
+ // ../js/src/athlete-workout-note.ts
2770
2756
  /**
2771
2757
  * PUT /1.0/athlete/savedworkout/{id} — set the athlete's session note (the free-text box on the
2772
2758
  * workout screen) and/or session RPE. The date + programWorkoutId (`athlete_workouts` `id`) locate
@@ -2796,8 +2782,7 @@ async function setAthleteWorkoutNote(client, args) {
2796
2782
  rpe: coerceInt(data.rpe) ?? (args.rpe !== void 0 ? args.rpe : null)
2797
2783
  };
2798
2784
  }
2799
- //#endregion
2800
- //#region ../js/src/athlete-exercise-note.ts
2785
+ // ../js/src/athlete-exercise-note.ts
2801
2786
  /**
2802
2787
  * PUT /1.0/athlete/savedworkoutsetexercise/{id} — set the athlete's per-exercise note (the
2803
2788
  * "Add exercise note" box on the exercise screen). A notes-only body leaves logged reps/weight
@@ -2818,9 +2803,13 @@ async function setAthleteExerciseNote(client, args) {
2818
2803
  notes: typeof data.notes === "string" ? data.notes : args.notes
2819
2804
  };
2820
2805
  }
2806
+ (() => {
2807
+ const map = /* @__PURE__ */ new Map();
2808
+ for (const [code, unit] of Object.entries(PARAM_UNIT)) if (unit !== null) map.set(unit, [...map.get(unit) ?? [], Number(code)]);
2809
+ return map;
2810
+ })();
2821
2811
  z.number().int().positive().max(36).optional();
2822
- //#endregion
2823
- //#region ../core/src/tools/athlete-training.ts
2812
+ // ../core/src/tools/athlete-training.ts
2824
2813
  /** Identity, profile, prefs, working maxes, leaderboard. */
2825
2814
  function registerProfileTools(server, ctx, whoami, userId) {
2826
2815
  server.registerTool("athlete_whoami", {
@@ -3248,11 +3237,9 @@ function registerAthleteTrainingTools(server, ctx) {
3248
3237
  registerLogTool(server, ctx);
3249
3238
  registerSwapTool(server, ctx);
3250
3239
  }
3251
- //#endregion
3252
- //#region package.json
3253
- var version = "4.2.0";
3254
- //#endregion
3255
- //#region src/server.ts
3240
+ // package.json
3241
+ var version = "4.3.0";
3242
+ // src/server.ts
3256
3243
  function main() {
3257
3244
  const email = process.env.TRAINHEROIC_EMAIL;
3258
3245
  const password = process.env.TRAINHEROIC_PASSWORD;
@@ -3271,5 +3258,4 @@ function main() {
3271
3258
  });
3272
3259
  }
3273
3260
  main();
3274
- //#endregion
3275
3261
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trainheroic-unofficial/athlete-mcp",
3
- "version": "4.2.0",
3
+ "version": "4.3.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -19,17 +19,17 @@
19
19
  "dist"
20
20
  ],
21
21
  "dependencies": {
22
- "@modelcontextprotocol/server": "2.3.1",
23
- "zod": "^4.6.5",
24
- "@trainheroic-unofficial/core": "4.2.0",
25
- "@trainheroic-unofficial/js": "4.2.0"
22
+ "@modelcontextprotocol/server": "2.4.0",
23
+ "zod": "^4.6.7",
24
+ "@trainheroic-unofficial/core": "4.3.0",
25
+ "@trainheroic-unofficial/js": "4.3.0"
26
26
  },
27
27
  "devDependencies": {
28
- "@types/node": "^26.6.4",
29
- "tsdown": "^0.23.0",
28
+ "@types/node": "^26.6.6",
29
+ "tsdown": "^0.23.7",
30
30
  "tsx": "^4.23.15",
31
31
  "typescript": "^7.0.2",
32
- "vitest": "^5.0.3"
32
+ "vitest": "^5.1.0"
33
33
  },
34
34
  "scripts": {
35
35
  "start": "tsx src/server.ts",