@trainheroic-unofficial/coach-mcp 2.0.2 → 2.1.1
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 +171 -41
- package/package.json +5 -5
package/dist/server.mjs
CHANGED
|
@@ -583,6 +583,34 @@ function confirmGate(ctx, message, confirmArg) {
|
|
|
583
583
|
*/
|
|
584
584
|
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.";
|
|
585
585
|
//#endregion
|
|
586
|
+
//#region ../js/src/http-error.ts
|
|
587
|
+
/**
|
|
588
|
+
* A final non-2xx response from TrainHeroic. The error deliberately carries only request
|
|
589
|
+
* metadata that is safe to send to telemetry: never the path, query string, request body,
|
|
590
|
+
* response body, credentials, or session token.
|
|
591
|
+
*/
|
|
592
|
+
var TrainHeroicHttpError = class extends Error {
|
|
593
|
+
name = "TrainHeroicHttpError";
|
|
594
|
+
method;
|
|
595
|
+
status;
|
|
596
|
+
host;
|
|
597
|
+
constructor(method, url, status) {
|
|
598
|
+
const parsed = new URL(url);
|
|
599
|
+
const normalizedMethod = method.toUpperCase();
|
|
600
|
+
super(`TrainHeroic ${normalizedMethod} request failed with HTTP ${status}`);
|
|
601
|
+
this.method = normalizedMethod;
|
|
602
|
+
this.status = status;
|
|
603
|
+
this.host = parsed.host;
|
|
604
|
+
}
|
|
605
|
+
};
|
|
606
|
+
/** Call observability hooks without allowing them to change SDK behavior. */
|
|
607
|
+
function notifyHttpError(handler, method, url, status) {
|
|
608
|
+
if (!handler) return;
|
|
609
|
+
try {
|
|
610
|
+
Promise.resolve(handler(new TrainHeroicHttpError(method, url, status))).catch(() => {});
|
|
611
|
+
} catch {}
|
|
612
|
+
}
|
|
613
|
+
//#endregion
|
|
586
614
|
//#region ../js/src/auth.ts
|
|
587
615
|
const DEFAULT_AUTH_URL = "https://apis.trainheroic.com/auth";
|
|
588
616
|
/**
|
|
@@ -604,8 +632,9 @@ function authUrl() {
|
|
|
604
632
|
* the Phase 0 spike: no refresh_token, no api_token, no TTL). The 48-char session_id
|
|
605
633
|
* is sent as the `session-token` header and works against both API hosts.
|
|
606
634
|
*/
|
|
607
|
-
async function loginTrainHeroic(email, password) {
|
|
608
|
-
const
|
|
635
|
+
async function loginTrainHeroic(email, password, options = {}) {
|
|
636
|
+
const url = authUrl();
|
|
637
|
+
const res = await fetch(url, {
|
|
609
638
|
method: "POST",
|
|
610
639
|
headers: {
|
|
611
640
|
"content-type": "application/x-www-form-urlencoded",
|
|
@@ -616,7 +645,10 @@ async function loginTrainHeroic(email, password) {
|
|
|
616
645
|
password
|
|
617
646
|
}).toString()
|
|
618
647
|
});
|
|
619
|
-
if (!res.ok)
|
|
648
|
+
if (!res.ok) {
|
|
649
|
+
notifyHttpError(options.onHttpError, "POST", url, res.status);
|
|
650
|
+
return null;
|
|
651
|
+
}
|
|
620
652
|
const data = await res.json().catch(() => null);
|
|
621
653
|
if (!data || typeof data.id !== "number" || !data.session_id) return null;
|
|
622
654
|
return {
|
|
@@ -659,6 +691,7 @@ var TrainHeroicClient = class {
|
|
|
659
691
|
#email;
|
|
660
692
|
#password;
|
|
661
693
|
#onSession;
|
|
694
|
+
#onHttpError;
|
|
662
695
|
#sessionId;
|
|
663
696
|
#loginInFlight = null;
|
|
664
697
|
constructor(email, password, sessionId = null, options = {}) {
|
|
@@ -666,6 +699,7 @@ var TrainHeroicClient = class {
|
|
|
666
699
|
this.#password = password;
|
|
667
700
|
this.#sessionId = sessionId;
|
|
668
701
|
this.#onSession = options.onSession;
|
|
702
|
+
this.#onHttpError = options.onHttpError;
|
|
669
703
|
}
|
|
670
704
|
get sessionId() {
|
|
671
705
|
return this.#sessionId;
|
|
@@ -680,7 +714,7 @@ var TrainHeroicClient = class {
|
|
|
680
714
|
}
|
|
681
715
|
}
|
|
682
716
|
async #login() {
|
|
683
|
-
const session = await loginTrainHeroic(this.#email, this.#password);
|
|
717
|
+
const session = await loginTrainHeroic(this.#email, this.#password, this.#onHttpError ? { onHttpError: this.#onHttpError } : {});
|
|
684
718
|
if (!session) throw new TrainHeroicAuthError("TrainHeroic login failed");
|
|
685
719
|
this.#sessionId = session.sessionId;
|
|
686
720
|
try {
|
|
@@ -697,6 +731,7 @@ var TrainHeroicClient = class {
|
|
|
697
731
|
session = await this.#ensureSession();
|
|
698
732
|
res = await this.#send(method, url, session, options.body);
|
|
699
733
|
}
|
|
734
|
+
if (!res.ok) notifyHttpError(this.#onHttpError, method, url, res.status);
|
|
700
735
|
const text = await res.text();
|
|
701
736
|
let data = text;
|
|
702
737
|
if (text.length > 0) try {
|
|
@@ -925,7 +960,7 @@ async function getJson(client, path, label) {
|
|
|
925
960
|
if (!res.ok) throw new Error(`${label} failed (HTTP ${res.status}).`);
|
|
926
961
|
return res.data;
|
|
927
962
|
}
|
|
928
|
-
async function getArray(client, path, label) {
|
|
963
|
+
async function getArray$1(client, path, label) {
|
|
929
964
|
const res = await client.request("GET", path);
|
|
930
965
|
if (!res.ok || !Array.isArray(res.data)) throw new Error(`${label} failed (HTTP ${res.status}).`);
|
|
931
966
|
return res.data;
|
|
@@ -995,25 +1030,7 @@ function fetchExerciseHistoryDetail(client, exerciseId, userId) {
|
|
|
995
1030
|
}
|
|
996
1031
|
/** Scheduled + completed workouts in an inclusive YYYY-MM-DD window. */
|
|
997
1032
|
function fetchAthleteWorkouts(client, startDate, endDate) {
|
|
998
|
-
return getArray(client, `/3.0/athlete/programworkout/range?startDate=${startDate}&endDate=${endDate}`, "athlete workouts");
|
|
999
|
-
}
|
|
1000
|
-
/**
|
|
1001
|
-
* A coach's view of a roster athlete's scheduled + completed workouts in an inclusive
|
|
1002
|
-
* YYYY-MM-DD window (`/3.0/coach/athlete/programworkout/range/{athleteId}`). Returns the same
|
|
1003
|
-
* `ProgramWorkout[]` shape as `fetchAthleteWorkouts`, so the same presenters and
|
|
1004
|
-
* `findSavedWorkoutSet` apply — it just reads another athlete's data through the coach surface.
|
|
1005
|
-
*/
|
|
1006
|
-
function fetchCoachAthleteWorkouts(client, athleteId, startDate, endDate) {
|
|
1007
|
-
return getArray(client, `/3.0/coach/athlete/programworkout/range/${athleteId}?startDate=${startDate}&endDate=${endDate}`, "coach athlete workouts");
|
|
1008
|
-
}
|
|
1009
|
-
/**
|
|
1010
|
-
* A coach's month view of a roster athlete's logged sessions
|
|
1011
|
-
* (`/2.0/coach/athlete/calendar/summary`). The trailing path segment is required by the API but
|
|
1012
|
-
* ignored (any value returns the whole month); it mirrors the coach web app, which sends 7. The
|
|
1013
|
-
* `userId` in each row is the roster athlete, not the calling coach.
|
|
1014
|
-
*/
|
|
1015
|
-
function fetchCoachAthleteCalendarSummary(client, athleteId, year, month) {
|
|
1016
|
-
return getArray(client, `/2.0/coach/athlete/calendar/summary/${athleteId}/${year}/${month}/7`, "coach athlete calendar summary");
|
|
1033
|
+
return getArray$1(client, `/3.0/athlete/programworkout/range?startDate=${startDate}&endDate=${endDate}`, "athlete workouts");
|
|
1017
1034
|
}
|
|
1018
1035
|
function nonEmpty(value) {
|
|
1019
1036
|
return value !== void 0 && value !== null && String(value).trim() !== "";
|
|
@@ -1371,6 +1388,70 @@ function presentExerciseHistory(detail) {
|
|
|
1371
1388
|
};
|
|
1372
1389
|
}
|
|
1373
1390
|
//#endregion
|
|
1391
|
+
//#region ../js/src/coach-athlete-calendar.ts
|
|
1392
|
+
async function getArray(client, path, label) {
|
|
1393
|
+
const res = await client.request("GET", path);
|
|
1394
|
+
if (!res.ok || !Array.isArray(res.data)) throw new Error(`${label} failed (HTTP ${res.status}).`);
|
|
1395
|
+
return res.data;
|
|
1396
|
+
}
|
|
1397
|
+
/**
|
|
1398
|
+
* A coach's view of a roster athlete's scheduled + completed workouts in an inclusive
|
|
1399
|
+
* YYYY-MM-DD window (`/3.0/coach/athlete/programworkout/range/{athleteId}`). Returns the same
|
|
1400
|
+
* `ProgramWorkout[]` shape as `fetchAthleteWorkouts`, so the same presenters and
|
|
1401
|
+
* `findSavedWorkoutSet` apply — it just reads another athlete's data through the coach surface.
|
|
1402
|
+
*/
|
|
1403
|
+
function fetchCoachAthleteWorkouts(client, athleteId, startDate, endDate) {
|
|
1404
|
+
return getArray(client, `/3.0/coach/athlete/programworkout/range/${athleteId}?startDate=${startDate}&endDate=${endDate}`, "coach athlete workouts");
|
|
1405
|
+
}
|
|
1406
|
+
/**
|
|
1407
|
+
* A coach's month view of a roster athlete's logged sessions
|
|
1408
|
+
* (`/2.0/coach/athlete/calendar/summary`). The trailing path segment is required by the API but
|
|
1409
|
+
* ignored (any value returns the whole month); it mirrors the coach web app, which sends 7. The
|
|
1410
|
+
* `userId` in each row is the roster athlete, not the calling coach.
|
|
1411
|
+
*/
|
|
1412
|
+
function fetchCoachAthleteCalendarSummary(client, athleteId, year, month) {
|
|
1413
|
+
return getArray(client, `/2.0/coach/athlete/calendar/summary/${athleteId}/${year}/${month}/7`, "coach athlete calendar summary");
|
|
1414
|
+
}
|
|
1415
|
+
/**
|
|
1416
|
+
* Resolve a roster athlete's coach-writable calendar program id
|
|
1417
|
+
* (`GET /v5/calendars/athletes/{athleteId}?year=&month=`).
|
|
1418
|
+
*
|
|
1419
|
+
* Year and month are required by the API (HTTP 400 without them); the returned `programId` is
|
|
1420
|
+
* stable for the athlete, so any month works. This is the calendar the coach web app writes
|
|
1421
|
+
* with `createWorkoutForDay` when you open an athlete from My Athletes → calendar — distinct
|
|
1422
|
+
* from athlete-created `personal_cal` ad-hoc sessions.
|
|
1423
|
+
*/
|
|
1424
|
+
async function fetchCoachAthleteCalendar(client, athleteId, year, month) {
|
|
1425
|
+
const path = `/v5/calendars/athletes/${athleteId}?year=${year}&month=${month}`;
|
|
1426
|
+
const res = await client.request("GET", path);
|
|
1427
|
+
if (!res.ok) {
|
|
1428
|
+
const detail = typeof res.data === "string" ? res.data : JSON.stringify(res.data);
|
|
1429
|
+
throw new Error(`GET ${path} failed (HTTP ${res.status}): ${detail}`);
|
|
1430
|
+
}
|
|
1431
|
+
if (!isRecord(res.data)) throw new Error("Unexpected athlete calendar response.");
|
|
1432
|
+
const programId = coerceInt(res.data.id);
|
|
1433
|
+
if (programId === null || programId <= 0) throw new Error(`Athlete calendar for ${athleteId} did not include a program id.`);
|
|
1434
|
+
return {
|
|
1435
|
+
programId,
|
|
1436
|
+
title: str$1(res.data.title) ?? "",
|
|
1437
|
+
type: coerceInt(res.data.type),
|
|
1438
|
+
groupId: coerceInt(res.data.group_id)
|
|
1439
|
+
};
|
|
1440
|
+
}
|
|
1441
|
+
/**
|
|
1442
|
+
* Resolve the calendar program id for `workout_build` / `coach workout build`: either an
|
|
1443
|
+
* explicit team/group `programId`, or a roster `athleteId` (+ date) via
|
|
1444
|
+
* `fetchCoachAthleteCalendar`. Exactly one of programId / athleteId is required.
|
|
1445
|
+
*/
|
|
1446
|
+
async function resolveBuildProgramId(client, args) {
|
|
1447
|
+
if (args.programId !== void 0 && args.athleteId !== void 0) throw new Error("Pass programId or athleteId, not both.");
|
|
1448
|
+
if (args.programId !== void 0) return args.programId;
|
|
1449
|
+
if (args.athleteId === void 0) throw new Error("Provide programId (team calendar) or athleteId (athlete calendar).");
|
|
1450
|
+
if (args.date === void 0) throw new Error("athleteId requires date (YYYY-M-D) to resolve the athlete calendar.");
|
|
1451
|
+
const [y, m] = parseWorkoutDate(args.date);
|
|
1452
|
+
return (await fetchCoachAthleteCalendar(client, args.athleteId, y, m)).programId;
|
|
1453
|
+
}
|
|
1454
|
+
//#endregion
|
|
1374
1455
|
//#region ../js/src/exercise-set-payload.ts
|
|
1375
1456
|
function slotData(exercise, key) {
|
|
1376
1457
|
const value = exercise?.[key];
|
|
@@ -2035,8 +2116,10 @@ function unitAdvisory(blockTitle, ex, defaults) {
|
|
|
2035
2116
|
if (ex.weight !== void 0 && ex.weight !== null) {
|
|
2036
2117
|
const sentP2 = Math.trunc(Number(ex.param_2_type ?? 1));
|
|
2037
2118
|
const effP2 = defaults.param2 === 0 || defaults.param2 === null ? 1 : defaults.param2;
|
|
2038
|
-
if (sentP2 !== effP2)
|
|
2039
|
-
|
|
2119
|
+
if (sentP2 !== effP2) {
|
|
2120
|
+
if (sentP2 === 2 || sentP2 === 14) warnings.push(`${label}: ${u(sentP2)} does not stick on this exercise — it renders as ${u(effP2)}. Put it in the exercise 'instr' text and leave load blank.`);
|
|
2121
|
+
else warnings.push(`${label}: load renders as ${u(effP2)}, not ${u(sentP2)} (this exercise's secondary unit is fixed).`);
|
|
2122
|
+
}
|
|
2040
2123
|
}
|
|
2041
2124
|
return {
|
|
2042
2125
|
notes,
|
|
@@ -2083,7 +2166,7 @@ async function collectAdvisories(blocks, index) {
|
|
|
2083
2166
|
function calendarWriteError(method, path, status, detail) {
|
|
2084
2167
|
const base = `${method} ${path} failed (HTTP ${status}): ${detail}`;
|
|
2085
2168
|
if (!(path.includes("/createWorkoutForDay/") || path.includes("/createWorkoutForTimelineDay/") || path.includes("/copyProgramWorkout")) || status !== 500 && status !== 401) return new Error(base);
|
|
2086
|
-
return /* @__PURE__ */ new Error(`${base}. This often means the
|
|
2169
|
+
return /* @__PURE__ */ new Error(`${base}. This often means the programId is not a coach-writable calendar — use a team/group programId (list_teams → group_program) or resolve a roster athlete's calendar via GET /v5/calendars/athletes/{athleteId}?year=&month= (workout_build athleteId). Athlete-created personal_cal ad-hoc sessions are a different surface.`);
|
|
2087
2170
|
}
|
|
2088
2171
|
async function req(client, method, path, body) {
|
|
2089
2172
|
const res = await client.request(method, path, body === void 0 ? void 0 : { body });
|
|
@@ -2270,6 +2353,36 @@ async function inviteAthletes(client, args) {
|
|
|
2270
2353
|
};
|
|
2271
2354
|
}
|
|
2272
2355
|
/**
|
|
2356
|
+
* Update a team's title and/or reassign its calendar (`PUT /v5/teams/{teamId}`).
|
|
2357
|
+
*
|
|
2358
|
+
* The live API accepts `group_program` to point the team at an existing parent program /
|
|
2359
|
+
* calendar (e.g. another team's `group_program` from `list_teams`), but rejects a body that
|
|
2360
|
+
* has only `group_program` (HTTP 400 "Invalid parameters"). When `title` is omitted we read
|
|
2361
|
+
* the current title first so callers can re-link without renaming.
|
|
2362
|
+
*/
|
|
2363
|
+
async function updateTeam(client, args) {
|
|
2364
|
+
if (args.title === void 0 && args.groupProgram === void 0) throw new Error("Provide title and/or groupProgram.");
|
|
2365
|
+
let title = args.title;
|
|
2366
|
+
if (title === void 0) {
|
|
2367
|
+
const existing = await client.request("GET", `/v5/teams/${args.teamId}`);
|
|
2368
|
+
if (!existing.ok) {
|
|
2369
|
+
const detail = typeof existing.data === "string" ? existing.data : JSON.stringify(existing.data);
|
|
2370
|
+
throw new Error(`GET /v5/teams/${args.teamId} failed (HTTP ${existing.status}): ${detail}`);
|
|
2371
|
+
}
|
|
2372
|
+
const rec = existing.data && typeof existing.data === "object" ? existing.data : null;
|
|
2373
|
+
title = typeof rec?.title === "string" ? rec.title : "";
|
|
2374
|
+
if (title.trim() === "") throw new Error(`Could not read current title for team ${args.teamId}; pass title explicitly.`);
|
|
2375
|
+
}
|
|
2376
|
+
const body = { title };
|
|
2377
|
+
if (args.groupProgram !== void 0) body.group_program = args.groupProgram;
|
|
2378
|
+
const res = await client.request("PUT", `/v5/teams/${args.teamId}`, { body });
|
|
2379
|
+
if (!res.ok) {
|
|
2380
|
+
const detail = typeof res.data === "string" ? res.data : JSON.stringify(res.data);
|
|
2381
|
+
throw new Error(`PUT /v5/teams/${args.teamId} failed (HTTP ${res.status}): ${detail}`);
|
|
2382
|
+
}
|
|
2383
|
+
return res.data;
|
|
2384
|
+
}
|
|
2385
|
+
/**
|
|
2273
2386
|
* Copy/repeat a session to a target date on a program (`POST /2.0/coach/calendar/copyProgramWorkout`).
|
|
2274
2387
|
* The API wants the target date as a structured object (with weekday and an isToday flag),
|
|
2275
2388
|
* which is computed here from `toDate` (YYYY-M-D). Creates a new (unpublished) session.
|
|
@@ -3128,7 +3241,7 @@ function registerEntityReads(server, ctx) {
|
|
|
3128
3241
|
}));
|
|
3129
3242
|
server.registerTool("get_program", {
|
|
3130
3243
|
title: "Get program detail",
|
|
3131
|
-
description: "Full nested program structure (blocks + sessions) live from the API, by program id.
|
|
3244
|
+
description: "Full nested program structure (blocks + sessions) live from the API, by program id. Works for team calendars and athlete coach calendars (type 5 from /v5/calendars/athletes/{id}). Some unrelated ids return HTTP 401 Cannot access program.",
|
|
3132
3245
|
inputSchema: { programId: idParam },
|
|
3133
3246
|
annotations: READ
|
|
3134
3247
|
}, ({ programId }) => apiCall(ctx, "GET", `/3.0/coach/program/${enc(programId)}`, void 0, "This is a large, deep object. If it is truncated, fetch a narrower view (a specific session) instead."));
|
|
@@ -3414,19 +3527,25 @@ const ADDITIVE = {
|
|
|
3414
3527
|
function registerTeamTools(server, ctx) {
|
|
3415
3528
|
server.registerTool("team_create", {
|
|
3416
3529
|
title: "Create a team",
|
|
3417
|
-
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.",
|
|
3530
|
+
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.",
|
|
3418
3531
|
inputSchema: { title: z.string().min(1) },
|
|
3419
3532
|
annotations: ADDITIVE
|
|
3420
3533
|
}, ({ title }) => apiCall(ctx, "POST", "/1.0/coach/team/createWithTitleAndCode", { body: { title } }));
|
|
3421
3534
|
server.registerTool("team_update", {
|
|
3422
|
-
title: "
|
|
3423
|
-
description: "Update a team's
|
|
3535
|
+
title: "Update a team",
|
|
3536
|
+
description: "Update a team's title and/or reassign its calendar (PUT /v5/teams/{teamId}). Pass groupProgram (a program/calendar id — typically another team's group_program from list_teams, or get_team) to point this team at an existing parent program. At least one of title or groupProgram is required; when only groupProgram is set the current title is preserved.",
|
|
3424
3537
|
inputSchema: {
|
|
3425
3538
|
teamId: idParam,
|
|
3426
|
-
title: z.string().min(1)
|
|
3539
|
+
title: z.string().min(1).optional(),
|
|
3540
|
+
groupProgram: idParam.optional()
|
|
3427
3541
|
},
|
|
3428
3542
|
annotations: ADDITIVE
|
|
3429
|
-
}, ({ teamId, title }) =>
|
|
3543
|
+
}, ({ teamId, title, groupProgram }) => attempt(async () => {
|
|
3544
|
+
const args = { teamId: toId(teamId) };
|
|
3545
|
+
if (title !== void 0) args.title = title;
|
|
3546
|
+
if (groupProgram !== void 0) args.groupProgram = toId(groupProgram);
|
|
3547
|
+
return jsonResult(await updateTeam(ctx.client, args));
|
|
3548
|
+
}));
|
|
3430
3549
|
server.registerTool("team_delete", {
|
|
3431
3550
|
title: "Delete a team",
|
|
3432
3551
|
description: "Delete a team (DELETE /v5/teams/{teamId}). Removes the team and its calendar from the live account; hard to undo. Requires confirmation (elicitation, or confirm:true).",
|
|
@@ -3570,13 +3689,14 @@ function registerExerciseTools(server, ctx) {
|
|
|
3570
3689
|
}
|
|
3571
3690
|
//#endregion
|
|
3572
3691
|
//#region ../core/src/tools/workout.ts
|
|
3573
|
-
/** Build a draft
|
|
3692
|
+
/** Build a draft session (workout_build). */
|
|
3574
3693
|
function registerBuild(server, ctx) {
|
|
3575
3694
|
server.registerTool("workout_build", {
|
|
3576
3695
|
title: "Build a workout session (draft)",
|
|
3577
|
-
description: "Build an UNPUBLISHED session from a spec (program -> session -> blocks -> exercises).
|
|
3696
|
+
description: "Build an UNPUBLISHED session from a spec (program -> session -> blocks -> exercises). Pass programId for a team/group calendar (list_teams → group_program), or athleteId to write on that roster athlete's coach calendar (resolved via /v5/calendars/athletes/{id} — the same calendar the coach web app opens from My Athletes). athleteId requires date. Two exercises in one block become a superset. A block with empty exercises and a non-empty block instruction is a text-only Circuit / Conditioning block (type 1). Add a block 'leaderboard' for a Red-Zone score, or a top-level 'instruction' for the session note (Coach Instructions). Returns the draft ids, a read-back, and unit advisories. Review, then workout_publish.",
|
|
3578
3697
|
inputSchema: {
|
|
3579
|
-
programId: z.number(),
|
|
3698
|
+
programId: z.number().optional(),
|
|
3699
|
+
athleteId: idParam.optional(),
|
|
3580
3700
|
date: z.string().optional(),
|
|
3581
3701
|
timelineDay: z.number().optional(),
|
|
3582
3702
|
blocks: z.array(blockSpecSchema),
|
|
@@ -3587,11 +3707,16 @@ function registerBuild(server, ctx) {
|
|
|
3587
3707
|
destructiveHint: false,
|
|
3588
3708
|
openWorldHint: true
|
|
3589
3709
|
}
|
|
3590
|
-
}, ({ programId, date, timelineDay, blocks, instruction }) => attempt(async () => {
|
|
3710
|
+
}, ({ programId, athleteId, date, timelineDay, blocks, instruction }) => attempt(async () => {
|
|
3591
3711
|
if (date === void 0 && timelineDay === void 0) return errorResult("Provide either date (YYYY-M-D) or timelineDay.");
|
|
3712
|
+
const resolveArgs = {};
|
|
3713
|
+
if (programId !== void 0) resolveArgs.programId = programId;
|
|
3714
|
+
if (athleteId !== void 0) resolveArgs.athleteId = toId(athleteId);
|
|
3715
|
+
if (date !== void 0) resolveArgs.date = date;
|
|
3716
|
+
const resolved = await resolveBuildProgramId(ctx.client, resolveArgs);
|
|
3592
3717
|
const typed = blocks;
|
|
3593
3718
|
const opts = {
|
|
3594
|
-
programId,
|
|
3719
|
+
programId: resolved,
|
|
3595
3720
|
blocks: typed,
|
|
3596
3721
|
publish: false
|
|
3597
3722
|
};
|
|
@@ -3600,15 +3725,19 @@ function registerBuild(server, ctx) {
|
|
|
3600
3725
|
if (instruction !== void 0) opts.instruction = instruction;
|
|
3601
3726
|
const advisories = await collectAdvisories(typed, ctx.index);
|
|
3602
3727
|
const built = await buildSession(ctx.client, opts);
|
|
3603
|
-
const readback = opts.date ? await readSession(ctx.client,
|
|
3728
|
+
const readback = opts.date ? await readSession(ctx.client, resolved, opts.date, built.pwId) : null;
|
|
3604
3729
|
return jsonResult({
|
|
3605
3730
|
...built,
|
|
3731
|
+
programId: resolved,
|
|
3606
3732
|
published: false,
|
|
3607
3733
|
advisories,
|
|
3608
3734
|
readback,
|
|
3609
3735
|
note: "Draft created (unpublished). Review, then call workout_publish to make it athlete-facing."
|
|
3610
3736
|
});
|
|
3611
3737
|
}));
|
|
3738
|
+
}
|
|
3739
|
+
/** Read-back and publish for a built session. */
|
|
3740
|
+
function registerReadPublish(server, ctx) {
|
|
3612
3741
|
server.registerTool("workout_read", {
|
|
3613
3742
|
title: "Read a built session",
|
|
3614
3743
|
description: "Read-back a session by programId, date (YYYY-M-D), and programWorkout id.",
|
|
@@ -3687,7 +3816,7 @@ function registerLifecycle(server, ctx) {
|
|
|
3687
3816
|
}));
|
|
3688
3817
|
server.registerTool("session_copy", {
|
|
3689
3818
|
title: "Copy a session to a date",
|
|
3690
|
-
description: "Copy/repeat a session to a target date on a program (POST .../copyProgramWorkout). toDate is YYYY-M-D. Creates a new session; review and publish it separately.
|
|
3819
|
+
description: "Copy/repeat a session to a target date on a program (POST .../copyProgramWorkout). toDate is YYYY-M-D. Creates a new session; review and publish it separately. toProgramId may be a team group_program or an athlete calendar program id (from /v5/calendars/athletes/{athleteId}?year=&month= / workout_build athleteId).",
|
|
3691
3820
|
inputSchema: {
|
|
3692
3821
|
toProgramId: z.number(),
|
|
3693
3822
|
pwId: z.number(),
|
|
@@ -3717,6 +3846,7 @@ function registerLifecycle(server, ctx) {
|
|
|
3717
3846
|
/** Workout building, read-back, publishing, and the session calendar lifecycle. */
|
|
3718
3847
|
function registerWorkoutTools(server, ctx) {
|
|
3719
3848
|
registerBuild(server, ctx);
|
|
3849
|
+
registerReadPublish(server, ctx);
|
|
3720
3850
|
registerLifecycle(server, ctx);
|
|
3721
3851
|
}
|
|
3722
3852
|
//#endregion
|
|
@@ -3840,7 +3970,7 @@ var JsonFileLibraryCache = class {
|
|
|
3840
3970
|
};
|
|
3841
3971
|
//#endregion
|
|
3842
3972
|
//#region package.json
|
|
3843
|
-
var version = "2.
|
|
3973
|
+
var version = "2.1.1";
|
|
3844
3974
|
//#endregion
|
|
3845
3975
|
//#region src/server.ts
|
|
3846
3976
|
function main() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trainheroic-unofficial/coach-mcp",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -21,13 +21,13 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@modelcontextprotocol/server": "2.0.0",
|
|
23
23
|
"zod": "^4.4.3",
|
|
24
|
-
"@trainheroic-unofficial/core": "2.
|
|
25
|
-
"@trainheroic-unofficial/js": "2.
|
|
24
|
+
"@trainheroic-unofficial/core": "2.1.1",
|
|
25
|
+
"@trainheroic-unofficial/js": "2.1.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@types/node": "^26.
|
|
28
|
+
"@types/node": "^26.2.0",
|
|
29
29
|
"tsdown": "^0.22.14",
|
|
30
|
-
"tsx": "^4.23.
|
|
30
|
+
"tsx": "^4.23.11",
|
|
31
31
|
"typescript": "^7.0.2",
|
|
32
32
|
"vitest": "^4.1.10"
|
|
33
33
|
},
|