@trainheroic-unofficial/coach-mcp 3.1.0 → 3.2.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.
- package/dist/server.mjs +407 -35
- package/package.json +3 -3
package/dist/server.mjs
CHANGED
|
@@ -279,6 +279,28 @@ const programWorkoutResponseSchema = z.looseObject({
|
|
|
279
279
|
});
|
|
280
280
|
/** The calendar edit-view response we read sessions back from. */
|
|
281
281
|
const programsEditResponseSchema = z.looseObject({ programWorkouts: z.array(programWorkoutResponseSchema).optional() });
|
|
282
|
+
/** A standalone program create response (container id + usable calendar/program id). */
|
|
283
|
+
const programCreateResponseSchema = z.looseObject({
|
|
284
|
+
id: intLike,
|
|
285
|
+
title: z.string(),
|
|
286
|
+
programId: intLike,
|
|
287
|
+
group_program: intLike,
|
|
288
|
+
type: intLike,
|
|
289
|
+
program: z.looseObject({
|
|
290
|
+
id: intLike,
|
|
291
|
+
program_type: intLike
|
|
292
|
+
}).optional()
|
|
293
|
+
});
|
|
294
|
+
//#endregion
|
|
295
|
+
//#region ../dto/src/team.ts
|
|
296
|
+
/** Fields merged onto the program object for `POST /1.0/coach/team/updatePublishSettings`. */
|
|
297
|
+
const teamPublishPatchObject = z.object({
|
|
298
|
+
pub_enabled: z.union([z.number(), z.boolean()]).optional(),
|
|
299
|
+
pub_days: z.unknown().optional(),
|
|
300
|
+
pub_time: z.unknown().optional(),
|
|
301
|
+
pub_timezone: z.string().optional()
|
|
302
|
+
});
|
|
303
|
+
const teamPublishPatchSchema = teamPublishPatchObject.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" });
|
|
282
304
|
//#endregion
|
|
283
305
|
//#region ../dto/src/workout.ts
|
|
284
306
|
/** A single exercise prescription inside a block. */
|
|
@@ -345,6 +367,11 @@ function parseWorkoutDate(s) {
|
|
|
345
367
|
parts[2]
|
|
346
368
|
];
|
|
347
369
|
}
|
|
370
|
+
/** Body for `POST /v5/sessions/template` (library create, not save-from-session). */
|
|
371
|
+
const sessionTemplateCreateSchema = z.object({
|
|
372
|
+
title: z.string().min(1),
|
|
373
|
+
instruction: z.string().optional()
|
|
374
|
+
});
|
|
348
375
|
//#endregion
|
|
349
376
|
//#region ../core/src/context.ts
|
|
350
377
|
/** A tool argument that accepts a numeric id as a number or a string of digits. */
|
|
@@ -504,15 +531,18 @@ function errorResult(message) {
|
|
|
504
531
|
}]
|
|
505
532
|
};
|
|
506
533
|
}
|
|
534
|
+
/** Format an already-issued TrainHeroic response as a size-bounded tool result. */
|
|
535
|
+
function apiResponseResult(res, hint) {
|
|
536
|
+
if (!res.ok) {
|
|
537
|
+
const detail = hardCap(typeof res.data === "string" ? res.data : JSON.stringify(res.data) ?? "", resultBudget());
|
|
538
|
+
return errorResult(`TrainHeroic API error (HTTP ${res.status}): ${detail}`);
|
|
539
|
+
}
|
|
540
|
+
return jsonResult(res.data, { hint });
|
|
541
|
+
}
|
|
507
542
|
/** Issue a TrainHeroic request and format the outcome as a tool result. */
|
|
508
543
|
async function apiCall(ctx, method, path, options, hint) {
|
|
509
544
|
return attempt(async () => {
|
|
510
|
-
|
|
511
|
-
if (!res.ok) {
|
|
512
|
-
const detail = hardCap(typeof res.data === "string" ? res.data : JSON.stringify(res.data) ?? "", resultBudget());
|
|
513
|
-
return errorResult(`TrainHeroic API error (HTTP ${res.status}): ${detail}`);
|
|
514
|
-
}
|
|
515
|
-
return jsonResult(res.data, { hint });
|
|
545
|
+
return apiResponseResult(await ctx.client.request(method, path, options), hint);
|
|
516
546
|
});
|
|
517
547
|
}
|
|
518
548
|
//#endregion
|
|
@@ -722,7 +752,7 @@ var TrainHeroicClient = class {
|
|
|
722
752
|
session = await this.#ensureSession();
|
|
723
753
|
res = await this.#send(method, url, session, options.body);
|
|
724
754
|
}
|
|
725
|
-
if (!res.ok) notifyHttpError(this.#onHttpError, method, url, res.status);
|
|
755
|
+
if (!res.ok && !options.expectedStatuses?.includes(res.status)) notifyHttpError(this.#onHttpError, method, url, res.status);
|
|
726
756
|
const text = await res.text();
|
|
727
757
|
let data = text;
|
|
728
758
|
if (text.length > 0) try {
|
|
@@ -1881,6 +1911,22 @@ async function logSessionForAthlete(client, args) {
|
|
|
1881
1911
|
};
|
|
1882
1912
|
}
|
|
1883
1913
|
//#endregion
|
|
1914
|
+
//#region ../js/src/util.ts
|
|
1915
|
+
/**
|
|
1916
|
+
* Drop the keys whose value is `undefined`, so the result can be passed to a function or
|
|
1917
|
+
* spread into an object under `exactOptionalPropertyTypes` without the per-key
|
|
1918
|
+
* `...(x !== undefined ? { x } : {})` dance. Required keys stay required in the result type;
|
|
1919
|
+
* optional ones lose `undefined` from their value type.
|
|
1920
|
+
*
|
|
1921
|
+
* Example:
|
|
1922
|
+
* definedProps({ metric, teamId: maybeId, date }) // omits teamId/date if they're undefined
|
|
1923
|
+
*/
|
|
1924
|
+
function definedProps(obj) {
|
|
1925
|
+
const result = {};
|
|
1926
|
+
for (const [key, value] of Object.entries(obj)) if (value !== void 0) result[key] = value;
|
|
1927
|
+
return result;
|
|
1928
|
+
}
|
|
1929
|
+
//#endregion
|
|
1884
1930
|
//#region ../js/src/workout-encode.ts
|
|
1885
1931
|
const LEADERBOARD_TYPE = {
|
|
1886
1932
|
completion: 0,
|
|
@@ -2234,6 +2280,84 @@ function readExercise(ex) {
|
|
|
2234
2280
|
instruction: str(ex.instruction)
|
|
2235
2281
|
};
|
|
2236
2282
|
}
|
|
2283
|
+
const PROGRAM_KINDS = ["calendar", "fixed"];
|
|
2284
|
+
/**
|
|
2285
|
+
* Create a standalone ongoing calendar or fixed-length program.
|
|
2286
|
+
*
|
|
2287
|
+
* TrainHeroic returns both a container id and the underlying program id. They are deliberately
|
|
2288
|
+
* named separately here because `/3.0/coach/program/{containerId}` returns 401, while the
|
|
2289
|
+
* `programId` works. This write is not idempotent: callers must not blindly retry an uncertain
|
|
2290
|
+
* result. The live API currently accepts `name` but may generate its own title; `nameApplied`
|
|
2291
|
+
* reports what happened.
|
|
2292
|
+
*/
|
|
2293
|
+
async function createProgram(client, args) {
|
|
2294
|
+
if (!PROGRAM_KINDS.includes(args.kind)) throw new Error(`Unknown program kind: ${String(args.kind)}.`);
|
|
2295
|
+
if (typeof args.name !== "string" || args.name.trim() === "") throw new Error("Program name must not be blank.");
|
|
2296
|
+
const requestedName = args.name.trim();
|
|
2297
|
+
const res = await client.request("POST", "/1.0/coach/programs/create", { body: {
|
|
2298
|
+
finite: args.kind === "fixed",
|
|
2299
|
+
name: requestedName
|
|
2300
|
+
} });
|
|
2301
|
+
if (!res.ok) {
|
|
2302
|
+
const detail = typeof res.data === "string" ? res.data : JSON.stringify(res.data);
|
|
2303
|
+
throw new Error(`Program create failed (HTTP ${res.status}): ${detail}`);
|
|
2304
|
+
}
|
|
2305
|
+
checkResponse(programCreateResponseSchema, res.data, "program create");
|
|
2306
|
+
const rec = isRecord(res.data) ? res.data : {};
|
|
2307
|
+
const nested = isRecord(rec.program) ? rec.program : {};
|
|
2308
|
+
const containerId = coerceInt(rec.id);
|
|
2309
|
+
const programId = coerceInt(rec.programId) ?? coerceInt(rec.group_program) ?? coerceInt(nested.id);
|
|
2310
|
+
if (containerId === null || programId === null) throw new Error("Program create response is missing the container id or program id.");
|
|
2311
|
+
if (typeof rec.title !== "string" || rec.title.trim() === "") throw new Error("Program create response is missing the assigned title.");
|
|
2312
|
+
const title = rec.title;
|
|
2313
|
+
return {
|
|
2314
|
+
containerId,
|
|
2315
|
+
programId,
|
|
2316
|
+
title,
|
|
2317
|
+
kind: args.kind,
|
|
2318
|
+
requestedName,
|
|
2319
|
+
nameApplied: title === requestedName
|
|
2320
|
+
};
|
|
2321
|
+
}
|
|
2322
|
+
/**
|
|
2323
|
+
* Delete a standalone program (`DELETE /v5/programs/{programId}`).
|
|
2324
|
+
*
|
|
2325
|
+
* The live API 401s when the path id is a list_programs container id. Pass either id: this
|
|
2326
|
+
* resolves a container to its `group_program` first. Team calendars are not in that list; their
|
|
2327
|
+
* program id is deleted as given. This is not idempotent against an unknown failure.
|
|
2328
|
+
*/
|
|
2329
|
+
async function deleteProgram(client, programId) {
|
|
2330
|
+
if (!Number.isInteger(programId) || programId <= 0) throw new Error("Program id must be a positive integer.");
|
|
2331
|
+
const programs = await client.request("GET", "/1.0/coach/programs");
|
|
2332
|
+
if (!programs.ok || !Array.isArray(programs.data)) {
|
|
2333
|
+
const detail = typeof programs.data === "string" ? programs.data : JSON.stringify(programs.data);
|
|
2334
|
+
throw new Error(`GET /1.0/coach/programs failed (HTTP ${programs.status}): ${detail}`);
|
|
2335
|
+
}
|
|
2336
|
+
let targetId = programId;
|
|
2337
|
+
let containerId = null;
|
|
2338
|
+
for (const item of programs.data) {
|
|
2339
|
+
if (!isRecord(item)) continue;
|
|
2340
|
+
const groupProgram = coerceInt(item.group_program);
|
|
2341
|
+
if (coerceInt(item.id) === programId && groupProgram !== null) {
|
|
2342
|
+
containerId = programId;
|
|
2343
|
+
targetId = groupProgram;
|
|
2344
|
+
break;
|
|
2345
|
+
}
|
|
2346
|
+
}
|
|
2347
|
+
const res = await client.request("DELETE", `/v5/programs/${targetId}`, { expectedStatuses: [
|
|
2348
|
+
401,
|
|
2349
|
+
403,
|
|
2350
|
+
404
|
|
2351
|
+
] });
|
|
2352
|
+
if (!res.ok) {
|
|
2353
|
+
const detail = typeof res.data === "string" ? res.data : JSON.stringify(res.data);
|
|
2354
|
+
throw new Error(`Program delete failed (HTTP ${res.status}): ${detail}`);
|
|
2355
|
+
}
|
|
2356
|
+
return {
|
|
2357
|
+
programId: targetId,
|
|
2358
|
+
containerId
|
|
2359
|
+
};
|
|
2360
|
+
}
|
|
2237
2361
|
/** Normalize one-or-many emails into a deduped, trimmed list. */
|
|
2238
2362
|
function emailList(emails) {
|
|
2239
2363
|
return [...new Set(emails.map((e) => e.trim()).filter((e) => e.length > 0))];
|
|
@@ -2331,6 +2455,52 @@ async function updateTeam(client, args) {
|
|
|
2331
2455
|
}
|
|
2332
2456
|
return res.data;
|
|
2333
2457
|
}
|
|
2458
|
+
/** Collapse the MCP/CLI XOR flags into a single publish target. */
|
|
2459
|
+
function teamPublishTarget(ids) {
|
|
2460
|
+
if (ids.programId !== void 0 && ids.teamId !== void 0) throw new Error("Pass programId or teamId, not both.");
|
|
2461
|
+
if (ids.programId !== void 0) return { programId: ids.programId };
|
|
2462
|
+
if (ids.teamId !== void 0) return { teamId: ids.teamId };
|
|
2463
|
+
throw new Error("Pass programId or teamId.");
|
|
2464
|
+
}
|
|
2465
|
+
async function programIdForTeam(client, teamId) {
|
|
2466
|
+
if (teamId <= 0) throw new Error("teamId must be positive.");
|
|
2467
|
+
const team = await client.request("GET", `/v5/teams/${teamId}`);
|
|
2468
|
+
if (!team.ok || !isRecord(team.data)) {
|
|
2469
|
+
const detail = typeof team.data === "string" ? team.data : JSON.stringify(team.data);
|
|
2470
|
+
throw new Error(`GET /v5/teams/${teamId} failed (HTTP ${team.status}): ${detail}`);
|
|
2471
|
+
}
|
|
2472
|
+
const resolved = coerceInt(team.data.group_program) ?? coerceInt(team.data.programId);
|
|
2473
|
+
if (resolved === null || resolved <= 0) throw new Error(`Team ${teamId} has no group_program.`);
|
|
2474
|
+
return resolved;
|
|
2475
|
+
}
|
|
2476
|
+
async function resolvePublishProgramId(client, target) {
|
|
2477
|
+
if ("programId" in target) return target.programId;
|
|
2478
|
+
return programIdForTeam(client, target.teamId);
|
|
2479
|
+
}
|
|
2480
|
+
/**
|
|
2481
|
+
* Update a team's auto-publish settings (`POST /1.0/coach/team/updatePublishSettings`).
|
|
2482
|
+
* The live API 500s on a partial body; it wants the full program object from
|
|
2483
|
+
* `GET /3.0/coach/program/{programId}` with `pub_*` fields merged on top.
|
|
2484
|
+
*/
|
|
2485
|
+
async function updateTeamPublishSettings(client, args) {
|
|
2486
|
+
if (Object.keys(args.patch).length === 0) throw new Error("Provide at least one pub_* field to change.");
|
|
2487
|
+
const programId = await resolvePublishProgramId(client, args);
|
|
2488
|
+
if (programId <= 0) throw new Error("programId must be positive.");
|
|
2489
|
+
const current = await client.request("GET", `/3.0/coach/program/${programId}`);
|
|
2490
|
+
if (!current.ok || !isRecord(current.data)) {
|
|
2491
|
+
const detail = typeof current.data === "string" ? current.data : JSON.stringify(current.data);
|
|
2492
|
+
throw new Error(`GET /3.0/coach/program/${programId} failed (HTTP ${current.status}): ${detail}`);
|
|
2493
|
+
}
|
|
2494
|
+
const res = await client.request("POST", "/1.0/coach/team/updatePublishSettings", { body: {
|
|
2495
|
+
...current.data,
|
|
2496
|
+
...args.patch
|
|
2497
|
+
} });
|
|
2498
|
+
if (!res.ok) {
|
|
2499
|
+
const detail = typeof res.data === "string" ? res.data : JSON.stringify(res.data);
|
|
2500
|
+
throw new Error(`updatePublishSettings failed (HTTP ${res.status}): ${detail}`);
|
|
2501
|
+
}
|
|
2502
|
+
return res.data;
|
|
2503
|
+
}
|
|
2334
2504
|
/**
|
|
2335
2505
|
* Copy/repeat a session to a target date on a program (`POST /2.0/coach/calendar/copyProgramWorkout`).
|
|
2336
2506
|
* The API wants the target date as a structured object (with weekday and an isToday flag),
|
|
@@ -2563,6 +2733,23 @@ async function teamVolume(client, args) {
|
|
|
2563
2733
|
totals
|
|
2564
2734
|
};
|
|
2565
2735
|
}
|
|
2736
|
+
/** Create a reusable session template in the coach library (`POST /v5/sessions/template`). */
|
|
2737
|
+
async function createSessionTemplate(client, args) {
|
|
2738
|
+
const title = args.title.trim();
|
|
2739
|
+
if (title === "") throw new Error("Session template title must not be blank.");
|
|
2740
|
+
const res = await client.request("POST", "/v5/sessions/template", { body: definedProps({
|
|
2741
|
+
title,
|
|
2742
|
+
instruction: args.instruction
|
|
2743
|
+
}) });
|
|
2744
|
+
if (!res.ok) {
|
|
2745
|
+
const detail = typeof res.data === "string" ? res.data : JSON.stringify(res.data);
|
|
2746
|
+
throw new Error(`Session template create failed (HTTP ${res.status}): ${detail}`);
|
|
2747
|
+
}
|
|
2748
|
+
if (!isRecord(res.data) || coerceInt(res.data.id) === null) throw new Error("Session template create response is missing an id.");
|
|
2749
|
+
return res.data;
|
|
2750
|
+
}
|
|
2751
|
+
/** First page of the coach session-template library (`GET /1.0/coach/workouts`). */
|
|
2752
|
+
const SESSION_TEMPLATES_LIST_PATH = "/1.0/coach/workouts?page=1&pageSize=50";
|
|
2566
2753
|
//#endregion
|
|
2567
2754
|
//#region ../js/src/main-lifts.ts
|
|
2568
2755
|
/**
|
|
@@ -2771,22 +2958,6 @@ async function fetchRosterMainLiftPRs(client, opts = {}) {
|
|
|
2771
2958
|
});
|
|
2772
2959
|
}
|
|
2773
2960
|
//#endregion
|
|
2774
|
-
//#region ../js/src/util.ts
|
|
2775
|
-
/**
|
|
2776
|
-
* Drop the keys whose value is `undefined`, so the result can be passed to a function or
|
|
2777
|
-
* spread into an object under `exactOptionalPropertyTypes` without the per-key
|
|
2778
|
-
* `...(x !== undefined ? { x } : {})` dance. Required keys stay required in the result type;
|
|
2779
|
-
* optional ones lose `undefined` from their value type.
|
|
2780
|
-
*
|
|
2781
|
-
* Example:
|
|
2782
|
-
* definedProps({ metric, teamId: maybeId, date }) // omits teamId/date if they're undefined
|
|
2783
|
-
*/
|
|
2784
|
-
function definedProps(obj) {
|
|
2785
|
-
const result = {};
|
|
2786
|
-
for (const [key, value] of Object.entries(obj)) if (value !== void 0) result[key] = value;
|
|
2787
|
-
return result;
|
|
2788
|
-
}
|
|
2789
|
-
//#endregion
|
|
2790
2961
|
//#region ../js/src/messaging.ts
|
|
2791
2962
|
const BUCKETS = [
|
|
2792
2963
|
["team", "teams"],
|
|
@@ -2858,6 +3029,8 @@ var MemoryLibraryCache = class {
|
|
|
2858
3029
|
//#region ../js/src/exercise-index.ts
|
|
2859
3030
|
const LIBRARY_PATH = "/v5/exerciseLibrary/all";
|
|
2860
3031
|
const CREATE_PATH = "/2.0/coach/exercise/create";
|
|
3032
|
+
const UPDATE_PATH = (id) => `/2.0/coach/exercise/update/${id}`;
|
|
3033
|
+
const DELETE_PATH = (id) => `/v5/exercises/${id}`;
|
|
2861
3034
|
const TTL_MS = 6048e5;
|
|
2862
3035
|
function toStored(ex) {
|
|
2863
3036
|
const id = coerceInt(ex.id);
|
|
@@ -2986,12 +3159,18 @@ var ExerciseLibrary = class {
|
|
|
2986
3159
|
};
|
|
2987
3160
|
}
|
|
2988
3161
|
async create(body) {
|
|
3162
|
+
return this.#writeThrough(CREATE_PATH, body, "create");
|
|
3163
|
+
}
|
|
3164
|
+
async update(id, body) {
|
|
3165
|
+
return this.#writeThrough(UPDATE_PATH(id), body, "update");
|
|
3166
|
+
}
|
|
3167
|
+
async #writeThrough(path, body, label) {
|
|
2989
3168
|
await this.ensureFresh();
|
|
2990
|
-
const res = await this.#client.request("POST",
|
|
2991
|
-
if (!res.ok) throw new Error(`Exercise
|
|
3169
|
+
const res = await this.#client.request("POST", path, { body });
|
|
3170
|
+
if (!res.ok) throw new Error(`Exercise ${label} failed (HTTP ${res.status}).`);
|
|
2992
3171
|
const ex = unwrapEnvelope(res.data);
|
|
2993
3172
|
if (ex && typeof ex === "object") {
|
|
2994
|
-
checkResponse(exerciseResponseSchema, ex,
|
|
3173
|
+
checkResponse(exerciseResponseSchema, ex, `exercise ${label}`);
|
|
2995
3174
|
const s = toStored(ex);
|
|
2996
3175
|
if (s) {
|
|
2997
3176
|
this.#byId.set(s.id, s);
|
|
@@ -3000,6 +3179,15 @@ var ExerciseLibrary = class {
|
|
|
3000
3179
|
}
|
|
3001
3180
|
return ex;
|
|
3002
3181
|
}
|
|
3182
|
+
async remove(id) {
|
|
3183
|
+
const res = await this.#client.request("DELETE", DELETE_PATH(id), { expectedStatuses: [
|
|
3184
|
+
401,
|
|
3185
|
+
403,
|
|
3186
|
+
404
|
|
3187
|
+
] });
|
|
3188
|
+
if (!res.ok) throw new Error(`Exercise delete failed (HTTP ${res.status}).`);
|
|
3189
|
+
await this.recordDelete(id);
|
|
3190
|
+
}
|
|
3003
3191
|
async recordDelete(id) {
|
|
3004
3192
|
await this.ensureFresh();
|
|
3005
3193
|
if (this.#byId.delete(id)) await this.#persist();
|
|
@@ -3061,7 +3249,7 @@ const SIMPLE_GETS = [
|
|
|
3061
3249
|
{
|
|
3062
3250
|
name: "list_programs",
|
|
3063
3251
|
title: "List programs",
|
|
3064
|
-
description: "Coach programs (standalone only). This is often empty even for an active coach, because most programming lives as a team's group-program: if it returns [], call list_teams and read each team's group_program — do not conclude the coach has no programs.",
|
|
3252
|
+
description: "Coach programs (standalone only). This is often empty even for an active coach, because most programming lives as a team's group-program: if it returns [], call list_teams and read each team's group_program — do not conclude the coach has no programs. Each standalone row has two ids: id is its container/calendar id; group_program is the underlying program id used by workout writes. get_program accepts either one.",
|
|
3065
3253
|
path: "/1.0/coach/programs"
|
|
3066
3254
|
},
|
|
3067
3255
|
{
|
|
@@ -3070,11 +3258,35 @@ const SIMPLE_GETS = [
|
|
|
3070
3258
|
description: "Unread counts including countMessagingNotViewed (cheap 'anything new?' poll).",
|
|
3071
3259
|
path: "/v5/notifications/counts"
|
|
3072
3260
|
},
|
|
3261
|
+
{
|
|
3262
|
+
name: "list_notifications",
|
|
3263
|
+
title: "Notification list",
|
|
3264
|
+
description: "Full notification list (GET /v5/notifications). Distinct from `notifications`, which returns unread counts only. Empty when there are no notifications.",
|
|
3265
|
+
path: "/v5/notifications"
|
|
3266
|
+
},
|
|
3267
|
+
{
|
|
3268
|
+
name: "list_subscriptions",
|
|
3269
|
+
title: "Program subscriptions",
|
|
3270
|
+
description: "Program subscriptions and subscribed teams (GET /1.0/coach/subscriptions). Returns `{subscriptions, teams}`.",
|
|
3271
|
+
path: "/1.0/coach/subscriptions"
|
|
3272
|
+
},
|
|
3273
|
+
{
|
|
3274
|
+
name: "list_prescription_templates",
|
|
3275
|
+
title: "Prescription templates",
|
|
3276
|
+
description: "Saved sets/reps schemes (GET /2.0/coach/workoutSetExercise/template). Use when picking a named prescription like '4 x 3' rather than typing set counts by hand.",
|
|
3277
|
+
path: "/2.0/coach/workoutSetExercise/template"
|
|
3278
|
+
},
|
|
3073
3279
|
{
|
|
3074
3280
|
name: "analytics_categories",
|
|
3075
3281
|
title: "Analytics categories",
|
|
3076
3282
|
description: "TrainHeroic's raw analytics catalog. Its keys are the API's own names and do NOT match analytics_query's `metric` values — choose the metric straight from analytics_query's (self-describing) enum instead; you rarely need this tool.",
|
|
3077
3283
|
path: "/v5/analytics"
|
|
3284
|
+
},
|
|
3285
|
+
{
|
|
3286
|
+
name: "list_session_templates",
|
|
3287
|
+
title: "List session templates",
|
|
3288
|
+
description: "Session templates in the coach library (GET /1.0/coach/workouts). Use a template id with session_save_as_template's inverse: this lists saved templates; session_save_as_template writes one from an existing session. Empty when the library has no templates yet.",
|
|
3289
|
+
path: SESSION_TEMPLATES_LIST_PATH
|
|
3078
3290
|
}
|
|
3079
3291
|
];
|
|
3080
3292
|
/** Roster-level reads: the fixed GETs plus the filterable athlete and team lists. */
|
|
@@ -3188,10 +3400,29 @@ function registerEntityReads(server, ctx) {
|
|
|
3188
3400
|
}));
|
|
3189
3401
|
server.registerTool("get_program", {
|
|
3190
3402
|
title: "Get program detail",
|
|
3191
|
-
description: "
|
|
3403
|
+
description: "Program detail live from the API, by program id. Works for team calendars and athlete coach calendars (type 5 from /v5/calendars/athletes/{id}). For standalone rows from list_programs, accepts either id (the container id) or group_program (the underlying program id); container ids are resolved automatically. If neither detail endpoint is available, returns calendar metadata and next-step guidance instead.",
|
|
3192
3404
|
inputSchema: { programId: idParam },
|
|
3193
3405
|
annotations: READ
|
|
3194
|
-
}, ({ programId }) =>
|
|
3406
|
+
}, ({ programId }) => getProgram(ctx, toId(programId)));
|
|
3407
|
+
}
|
|
3408
|
+
async function getProgram(ctx, programId) {
|
|
3409
|
+
return attempt(async () => {
|
|
3410
|
+
const detail = await ctx.client.request("GET", `/3.0/coach/program/${enc(programId)}`, { expectedStatuses: [401, 403] });
|
|
3411
|
+
if (detail.ok || detail.status !== 401 && detail.status !== 403) return apiResponseResult(detail, "This is a large, deep object. If it is truncated, fetch a narrower view (a specific session) instead.");
|
|
3412
|
+
const programs = await ctx.client.request("GET", "/1.0/coach/programs");
|
|
3413
|
+
const program = Array.isArray(programs.data) ? programs.data.find((item) => isRecord(item) && coerceInt(item.id) === programId) : void 0;
|
|
3414
|
+
if (!programs.ok || !program) return apiResponseResult(detail);
|
|
3415
|
+
const actualProgramId = coerceInt(program.group_program);
|
|
3416
|
+
if (actualProgramId !== null && actualProgramId !== programId) {
|
|
3417
|
+
const actualDetail = await ctx.client.request("GET", `/3.0/coach/program/${enc(actualProgramId)}`, { expectedStatuses: [401, 403] });
|
|
3418
|
+
if (actualDetail.ok || actualDetail.status !== 401 && actualDetail.status !== 403) return apiResponseResult(actualDetail, "This is a large, deep object. If it is truncated, fetch a narrower view (a specific session) instead.");
|
|
3419
|
+
}
|
|
3420
|
+
return jsonResult({
|
|
3421
|
+
program,
|
|
3422
|
+
detailAvailable: false,
|
|
3423
|
+
note: "TrainHeroic recognizes this as a valid standalone calendar, but its nested program-detail endpoint does not expose this calendar type. Use calendar/session reads instead; on the hosted server, programming_sync then programming_stored can read its dated sessions."
|
|
3424
|
+
});
|
|
3425
|
+
});
|
|
3195
3426
|
}
|
|
3196
3427
|
/** Read-only coach/athlete queries. Exercise lookups live in the exercise store tools. */
|
|
3197
3428
|
/** The windowed team-volume read — its own function so registerEntityReads stays under the cap. */
|
|
@@ -3218,9 +3449,18 @@ function registerTeamVolume(server, ctx) {
|
|
|
3218
3449
|
}
|
|
3219
3450
|
function registerReadTools(server, ctx) {
|
|
3220
3451
|
registerRosterReads(server, ctx);
|
|
3452
|
+
registerCoachAthleteTeamCalendar(server, ctx);
|
|
3221
3453
|
registerEntityReads(server, ctx);
|
|
3222
3454
|
registerTeamVolume(server, ctx);
|
|
3223
3455
|
}
|
|
3456
|
+
function registerCoachAthleteTeamCalendar(server, ctx) {
|
|
3457
|
+
server.registerTool("coach_athlete_team_calendar", {
|
|
3458
|
+
title: "Coach-athlete team calendar",
|
|
3459
|
+
description: "Companion calendar for a roster athlete (GET /v5/calendars/athletes/{id}/coachAthleteTeam). Distinct from workout_build's type-5 individual calendar. Returns title, logo, id, athlete_id, owner_user_id.",
|
|
3460
|
+
inputSchema: { athleteId: idParam },
|
|
3461
|
+
annotations: READ
|
|
3462
|
+
}, ({ athleteId }) => apiCall(ctx, "GET", `/v5/calendars/athletes/${toId(athleteId)}/coachAthleteTeam`));
|
|
3463
|
+
}
|
|
3224
3464
|
//#endregion
|
|
3225
3465
|
//#region ../core/src/tools/main-lifts.ts
|
|
3226
3466
|
const monthsParam = z.number().int().positive().max(36).optional();
|
|
@@ -3462,7 +3702,7 @@ function registerAthletePrescribeTool(server, ctx) {
|
|
|
3462
3702
|
}
|
|
3463
3703
|
//#endregion
|
|
3464
3704
|
//#region ../core/src/tools/teams.ts
|
|
3465
|
-
const ADDITIVE = {
|
|
3705
|
+
const ADDITIVE$1 = {
|
|
3466
3706
|
readOnlyHint: false,
|
|
3467
3707
|
destructiveHint: false,
|
|
3468
3708
|
openWorldHint: true
|
|
@@ -3476,7 +3716,7 @@ function registerTeamTools(server, ctx) {
|
|
|
3476
3716
|
title: "Create a team",
|
|
3477
3717
|
description: "Create a team (POST /1.0/coach/team/createWithTitleAndCode). Also creates the team's calendar/program. Returns the new team including its calendar id. Use the team id with athlete_invite. To point a new team at an existing calendar instead of its auto-created one, follow up with team_update groupProgram.",
|
|
3478
3718
|
inputSchema: { title: z.string().min(1) },
|
|
3479
|
-
annotations: ADDITIVE
|
|
3719
|
+
annotations: ADDITIVE$1
|
|
3480
3720
|
}, ({ title }) => apiCall(ctx, "POST", "/1.0/coach/team/createWithTitleAndCode", { body: { title } }));
|
|
3481
3721
|
server.registerTool("team_update", {
|
|
3482
3722
|
title: "Update a team",
|
|
@@ -3486,7 +3726,7 @@ function registerTeamTools(server, ctx) {
|
|
|
3486
3726
|
title: z.string().min(1).optional(),
|
|
3487
3727
|
groupProgram: idParam.optional()
|
|
3488
3728
|
},
|
|
3489
|
-
annotations: ADDITIVE
|
|
3729
|
+
annotations: ADDITIVE$1
|
|
3490
3730
|
}, ({ teamId, title, groupProgram }) => attempt(async () => {
|
|
3491
3731
|
const args = { teamId: toId(teamId) };
|
|
3492
3732
|
if (title !== void 0) args.title = title;
|
|
@@ -3514,7 +3754,7 @@ function registerTeamTools(server, ctx) {
|
|
|
3514
3754
|
teamId: idParam,
|
|
3515
3755
|
type: z.number().int().optional()
|
|
3516
3756
|
},
|
|
3517
|
-
annotations: ADDITIVE
|
|
3757
|
+
annotations: ADDITIVE$1
|
|
3518
3758
|
}, ({ teamId, type }) => apiCall(ctx, "POST", `/v5/teams/${toId(teamId)}/teamCodes`, { body: { type: type ?? 2 } }));
|
|
3519
3759
|
server.registerTool("team_code_delete", {
|
|
3520
3760
|
title: "Delete a team join code",
|
|
@@ -3530,6 +3770,73 @@ function registerTeamTools(server, ctx) {
|
|
|
3530
3770
|
if (blocked) return blocked;
|
|
3531
3771
|
return apiCall(ctx, "DELETE", `/v5/teamCodes/${id}`);
|
|
3532
3772
|
}));
|
|
3773
|
+
registerTeamPublishSettings(server, ctx);
|
|
3774
|
+
}
|
|
3775
|
+
function registerTeamPublishSettings(server, ctx) {
|
|
3776
|
+
server.registerTool("team_publish_settings", {
|
|
3777
|
+
title: "Update team auto-publish",
|
|
3778
|
+
description: "Update a team's auto-publish settings (POST /1.0/coach/team/updatePublishSettings). Pass teamId or programId (the team's group_program). At least one of pub_enabled, pub_days, pub_time, pub_timezone is required. Athlete-facing — requires confirmation.",
|
|
3779
|
+
inputSchema: {
|
|
3780
|
+
teamId: idParam.optional(),
|
|
3781
|
+
programId: idParam.optional(),
|
|
3782
|
+
...teamPublishPatchObject.shape,
|
|
3783
|
+
confirm: z.boolean().optional()
|
|
3784
|
+
},
|
|
3785
|
+
annotations: DESTRUCTIVE
|
|
3786
|
+
}, ({ teamId, programId, pub_enabled, pub_days, pub_time, pub_timezone, confirm }, extra) => attempt(async () => {
|
|
3787
|
+
const blocked = confirmGate(extra, "Change auto-publish settings? This controls when athletes see programmed sessions.", confirm);
|
|
3788
|
+
if (blocked) return blocked;
|
|
3789
|
+
const patch = teamPublishPatchSchema.parse(definedProps({
|
|
3790
|
+
pub_enabled,
|
|
3791
|
+
pub_days,
|
|
3792
|
+
pub_time,
|
|
3793
|
+
pub_timezone
|
|
3794
|
+
}));
|
|
3795
|
+
const target = teamPublishTarget(definedProps({
|
|
3796
|
+
programId: programId !== void 0 ? toId(programId) : void 0,
|
|
3797
|
+
teamId: teamId !== void 0 ? toId(teamId) : void 0
|
|
3798
|
+
}));
|
|
3799
|
+
return jsonResult(await updateTeamPublishSettings(ctx.client, {
|
|
3800
|
+
...target,
|
|
3801
|
+
patch
|
|
3802
|
+
}));
|
|
3803
|
+
}));
|
|
3804
|
+
}
|
|
3805
|
+
//#endregion
|
|
3806
|
+
//#region ../core/src/tools/programs.ts
|
|
3807
|
+
const ADDITIVE = {
|
|
3808
|
+
readOnlyHint: false,
|
|
3809
|
+
destructiveHint: false,
|
|
3810
|
+
openWorldHint: true
|
|
3811
|
+
};
|
|
3812
|
+
/** Standalone program writes. Program reads live in reads.ts. */
|
|
3813
|
+
function registerProgramTools(server, ctx) {
|
|
3814
|
+
server.registerTool("program_create", {
|
|
3815
|
+
title: "Create a standalone program",
|
|
3816
|
+
description: "Create either an ongoing calendar or a fixed-length standalone program (POST /1.0/coach/programs/create). Returns both containerId (the id shown by list_programs and used by calendar edit/sync reads) and programId (the id used by get_program and workout writes). TrainHeroic may generate a different title; inspect title and nameApplied. This write is not idempotent, so do not retry an uncertain result.",
|
|
3817
|
+
inputSchema: {
|
|
3818
|
+
kind: z.enum(PROGRAM_KINDS),
|
|
3819
|
+
name: z.string().trim().min(1)
|
|
3820
|
+
},
|
|
3821
|
+
annotations: ADDITIVE
|
|
3822
|
+
}, ({ kind, name }) => attempt(async () => jsonResult(await createProgram(ctx.client, {
|
|
3823
|
+
kind,
|
|
3824
|
+
name
|
|
3825
|
+
}))));
|
|
3826
|
+
server.registerTool("program_delete", {
|
|
3827
|
+
title: "Delete a standalone program",
|
|
3828
|
+
description: "Delete a standalone calendar or fixed program (DELETE /v5/programs/{programId}). Accepts either list_programs id (container) or group_program (the underlying program id); container ids 401 if sent raw and are resolved automatically. Removes the calendar from the live account. Requires confirmation (elicitation, or confirm:true).",
|
|
3829
|
+
inputSchema: {
|
|
3830
|
+
programId: idParam,
|
|
3831
|
+
confirm: z.boolean().optional()
|
|
3832
|
+
},
|
|
3833
|
+
annotations: DESTRUCTIVE
|
|
3834
|
+
}, ({ programId, confirm }, extra) => attempt(async () => {
|
|
3835
|
+
const id = toId(programId);
|
|
3836
|
+
const blocked = confirmGate(extra, `Delete standalone program ${id}? This removes the calendar from the live account.`, confirm);
|
|
3837
|
+
if (blocked) return blocked;
|
|
3838
|
+
return jsonResult(await deleteProgram(ctx.client, id));
|
|
3839
|
+
}));
|
|
3533
3840
|
}
|
|
3534
3841
|
//#endregion
|
|
3535
3842
|
//#region ../core/src/tools/analytics.ts
|
|
@@ -3563,6 +3870,38 @@ function registerAnalyticsTools(server, ctx) {
|
|
|
3563
3870
|
}
|
|
3564
3871
|
//#endregion
|
|
3565
3872
|
//#region ../core/src/tools/exercises.ts
|
|
3873
|
+
function registerExerciseUpdate(server, index) {
|
|
3874
|
+
server.registerTool("exercise_update", {
|
|
3875
|
+
title: "Update custom exercise",
|
|
3876
|
+
description: "Update a custom exercise (POST /2.0/coach/exercise/update/{id}) and write it through to the mirror. Same body as exercise_create. Only works for exercises with can_edit:1.",
|
|
3877
|
+
inputSchema: {
|
|
3878
|
+
id: idParam,
|
|
3879
|
+
exercise: exerciseCreateSchema
|
|
3880
|
+
},
|
|
3881
|
+
annotations: {
|
|
3882
|
+
readOnlyHint: false,
|
|
3883
|
+
destructiveHint: false,
|
|
3884
|
+
openWorldHint: true
|
|
3885
|
+
}
|
|
3886
|
+
}, ({ id, exercise }) => attempt(async () => jsonResult(await index.update(toId(id), exercise))));
|
|
3887
|
+
}
|
|
3888
|
+
function registerExerciseDelete(server, index) {
|
|
3889
|
+
server.registerTool("exercise_delete", {
|
|
3890
|
+
title: "Delete custom exercise",
|
|
3891
|
+
description: "Delete a custom exercise on TrainHeroic (DELETE /v5/exercises/{id}) and drop it from the local mirror. Only works for exercises with can_edit:1. Built-in library exercises cannot be deleted. Requires confirmation (elicitation, or confirm:true). exercise_forget only clears the cache — use this to delete the live exercise.",
|
|
3892
|
+
inputSchema: {
|
|
3893
|
+
id: idParam,
|
|
3894
|
+
confirm: z.boolean().optional()
|
|
3895
|
+
},
|
|
3896
|
+
annotations: DESTRUCTIVE
|
|
3897
|
+
}, ({ id, confirm }, extra) => attempt(async () => {
|
|
3898
|
+
const exerciseId = toId(id);
|
|
3899
|
+
const blocked = confirmGate(extra, `Delete custom exercise ${exerciseId} from the live TrainHeroic library?`, confirm);
|
|
3900
|
+
if (blocked) return blocked;
|
|
3901
|
+
await index.remove(exerciseId);
|
|
3902
|
+
return jsonResult({ deleted: exerciseId });
|
|
3903
|
+
}));
|
|
3904
|
+
}
|
|
3566
3905
|
/**
|
|
3567
3906
|
* Exercise library tools over the ExerciseIndex — a D1 mirror on the hosted server, an
|
|
3568
3907
|
* on-disk/in-memory cache locally. The descriptions stay at the interface level so they
|
|
@@ -3614,9 +3953,11 @@ function registerExerciseTools(server, ctx) {
|
|
|
3614
3953
|
openWorldHint: true
|
|
3615
3954
|
}
|
|
3616
3955
|
}, ({ exercise }) => attempt(async () => jsonResult(await index.create(exercise))));
|
|
3956
|
+
registerExerciseUpdate(server, index);
|
|
3957
|
+
registerExerciseDelete(server, index);
|
|
3617
3958
|
server.registerTool("exercise_forget", {
|
|
3618
3959
|
title: "Forget exercise (cache only)",
|
|
3619
|
-
description: "Remove an exercise from the local mirror only.
|
|
3960
|
+
description: "Remove an exercise from the local mirror only. Does not call TrainHeroic — use exercise_delete to delete the live custom exercise.",
|
|
3620
3961
|
inputSchema: { id: idParam },
|
|
3621
3962
|
annotations: {
|
|
3622
3963
|
readOnlyHint: false,
|
|
@@ -3790,11 +4131,41 @@ function registerLifecycle(server, ctx) {
|
|
|
3790
4131
|
}
|
|
3791
4132
|
}, ({ workoutId }) => apiCall(ctx, "POST", `/2.0/coach/calendar/programWorkout/saveWorkoutAsTemplate/${workoutId}`));
|
|
3792
4133
|
}
|
|
4134
|
+
function registerTemplateLibrary(server, ctx) {
|
|
4135
|
+
server.registerTool("session_template_create", {
|
|
4136
|
+
title: "Create a session template",
|
|
4137
|
+
description: "Create an empty reusable session template in the library (POST /v5/sessions/template). Distinct from session_save_as_template, which copies an existing session. Pass title and optional instruction.",
|
|
4138
|
+
inputSchema: sessionTemplateCreateSchema,
|
|
4139
|
+
annotations: {
|
|
4140
|
+
readOnlyHint: false,
|
|
4141
|
+
destructiveHint: false,
|
|
4142
|
+
openWorldHint: true
|
|
4143
|
+
}
|
|
4144
|
+
}, ({ title, instruction }) => attempt(async () => jsonResult(await createSessionTemplate(ctx.client, definedProps({
|
|
4145
|
+
title,
|
|
4146
|
+
instruction
|
|
4147
|
+
})))));
|
|
4148
|
+
server.registerTool("session_template_delete", {
|
|
4149
|
+
title: "Delete a session template",
|
|
4150
|
+
description: "Delete a library session template (DELETE /v5/sessions/template/{id}). Requires confirmation (elicitation, or confirm:true).",
|
|
4151
|
+
inputSchema: {
|
|
4152
|
+
id: idParam,
|
|
4153
|
+
confirm: z.boolean().optional()
|
|
4154
|
+
},
|
|
4155
|
+
annotations: DESTRUCTIVE
|
|
4156
|
+
}, ({ id, confirm }, extra) => attempt(async () => {
|
|
4157
|
+
const templateId = toId(id);
|
|
4158
|
+
const blocked = confirmGate(extra, `Delete session template ${templateId} from the library?`, confirm);
|
|
4159
|
+
if (blocked) return blocked;
|
|
4160
|
+
return apiCall(ctx, "DELETE", `/v5/sessions/template/${templateId}`);
|
|
4161
|
+
}));
|
|
4162
|
+
}
|
|
3793
4163
|
/** Workout building, read-back, publishing, and the session calendar lifecycle. */
|
|
3794
4164
|
function registerWorkoutTools(server, ctx) {
|
|
3795
4165
|
registerBuild(server, ctx);
|
|
3796
4166
|
registerReadPublish(server, ctx);
|
|
3797
4167
|
registerLifecycle(server, ctx);
|
|
4168
|
+
registerTemplateLibrary(server, ctx);
|
|
3798
4169
|
}
|
|
3799
4170
|
//#endregion
|
|
3800
4171
|
//#region ../core/src/tools/messaging.ts
|
|
@@ -3887,6 +4258,7 @@ function registerCoachTools(server, ctx) {
|
|
|
3887
4258
|
registerMainLiftTools(server, ctx);
|
|
3888
4259
|
registerAthleteTools(server, ctx);
|
|
3889
4260
|
registerTeamTools(server, ctx);
|
|
4261
|
+
registerProgramTools(server, ctx);
|
|
3890
4262
|
registerAnalyticsTools(server, ctx);
|
|
3891
4263
|
registerExerciseTools(server, ctx);
|
|
3892
4264
|
registerWorkoutTools(server, ctx);
|
|
@@ -3918,7 +4290,7 @@ var JsonFileLibraryCache = class {
|
|
|
3918
4290
|
};
|
|
3919
4291
|
//#endregion
|
|
3920
4292
|
//#region package.json
|
|
3921
|
-
var version = "3.
|
|
4293
|
+
var version = "3.2.0";
|
|
3922
4294
|
//#endregion
|
|
3923
4295
|
//#region src/server.ts
|
|
3924
4296
|
function main() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trainheroic-unofficial/coach-mcp",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@modelcontextprotocol/server": "2.0.0",
|
|
23
23
|
"zod": "^4.4.3",
|
|
24
|
-
"@trainheroic-unofficial/core": "3.
|
|
25
|
-
"@trainheroic-unofficial/js": "3.
|
|
24
|
+
"@trainheroic-unofficial/core": "3.2.0",
|
|
25
|
+
"@trainheroic-unofficial/js": "3.2.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/node": "^26.2.0",
|