@trainheroic-unofficial/coach-mcp 3.1.1 → 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 +297 -21
- package/package.json +3 -3
package/dist/server.mjs
CHANGED
|
@@ -292,6 +292,16 @@ const programCreateResponseSchema = z.looseObject({
|
|
|
292
292
|
}).optional()
|
|
293
293
|
});
|
|
294
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" });
|
|
304
|
+
//#endregion
|
|
295
305
|
//#region ../dto/src/workout.ts
|
|
296
306
|
/** A single exercise prescription inside a block. */
|
|
297
307
|
const exerciseSpecSchema = z.object({
|
|
@@ -357,6 +367,11 @@ function parseWorkoutDate(s) {
|
|
|
357
367
|
parts[2]
|
|
358
368
|
];
|
|
359
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
|
+
});
|
|
360
375
|
//#endregion
|
|
361
376
|
//#region ../core/src/context.ts
|
|
362
377
|
/** A tool argument that accepts a numeric id as a number or a string of digits. */
|
|
@@ -1896,6 +1911,22 @@ async function logSessionForAthlete(client, args) {
|
|
|
1896
1911
|
};
|
|
1897
1912
|
}
|
|
1898
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
|
|
1899
1930
|
//#region ../js/src/workout-encode.ts
|
|
1900
1931
|
const LEADERBOARD_TYPE = {
|
|
1901
1932
|
completion: 0,
|
|
@@ -2288,6 +2319,45 @@ async function createProgram(client, args) {
|
|
|
2288
2319
|
nameApplied: title === requestedName
|
|
2289
2320
|
};
|
|
2290
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
|
+
}
|
|
2291
2361
|
/** Normalize one-or-many emails into a deduped, trimmed list. */
|
|
2292
2362
|
function emailList(emails) {
|
|
2293
2363
|
return [...new Set(emails.map((e) => e.trim()).filter((e) => e.length > 0))];
|
|
@@ -2385,6 +2455,52 @@ async function updateTeam(client, args) {
|
|
|
2385
2455
|
}
|
|
2386
2456
|
return res.data;
|
|
2387
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
|
+
}
|
|
2388
2504
|
/**
|
|
2389
2505
|
* Copy/repeat a session to a target date on a program (`POST /2.0/coach/calendar/copyProgramWorkout`).
|
|
2390
2506
|
* The API wants the target date as a structured object (with weekday and an isToday flag),
|
|
@@ -2617,6 +2733,23 @@ async function teamVolume(client, args) {
|
|
|
2617
2733
|
totals
|
|
2618
2734
|
};
|
|
2619
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";
|
|
2620
2753
|
//#endregion
|
|
2621
2754
|
//#region ../js/src/main-lifts.ts
|
|
2622
2755
|
/**
|
|
@@ -2825,22 +2958,6 @@ async function fetchRosterMainLiftPRs(client, opts = {}) {
|
|
|
2825
2958
|
});
|
|
2826
2959
|
}
|
|
2827
2960
|
//#endregion
|
|
2828
|
-
//#region ../js/src/util.ts
|
|
2829
|
-
/**
|
|
2830
|
-
* Drop the keys whose value is `undefined`, so the result can be passed to a function or
|
|
2831
|
-
* spread into an object under `exactOptionalPropertyTypes` without the per-key
|
|
2832
|
-
* `...(x !== undefined ? { x } : {})` dance. Required keys stay required in the result type;
|
|
2833
|
-
* optional ones lose `undefined` from their value type.
|
|
2834
|
-
*
|
|
2835
|
-
* Example:
|
|
2836
|
-
* definedProps({ metric, teamId: maybeId, date }) // omits teamId/date if they're undefined
|
|
2837
|
-
*/
|
|
2838
|
-
function definedProps(obj) {
|
|
2839
|
-
const result = {};
|
|
2840
|
-
for (const [key, value] of Object.entries(obj)) if (value !== void 0) result[key] = value;
|
|
2841
|
-
return result;
|
|
2842
|
-
}
|
|
2843
|
-
//#endregion
|
|
2844
2961
|
//#region ../js/src/messaging.ts
|
|
2845
2962
|
const BUCKETS = [
|
|
2846
2963
|
["team", "teams"],
|
|
@@ -2912,6 +3029,8 @@ var MemoryLibraryCache = class {
|
|
|
2912
3029
|
//#region ../js/src/exercise-index.ts
|
|
2913
3030
|
const LIBRARY_PATH = "/v5/exerciseLibrary/all";
|
|
2914
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}`;
|
|
2915
3034
|
const TTL_MS = 6048e5;
|
|
2916
3035
|
function toStored(ex) {
|
|
2917
3036
|
const id = coerceInt(ex.id);
|
|
@@ -3040,12 +3159,18 @@ var ExerciseLibrary = class {
|
|
|
3040
3159
|
};
|
|
3041
3160
|
}
|
|
3042
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) {
|
|
3043
3168
|
await this.ensureFresh();
|
|
3044
|
-
const res = await this.#client.request("POST",
|
|
3045
|
-
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}).`);
|
|
3046
3171
|
const ex = unwrapEnvelope(res.data);
|
|
3047
3172
|
if (ex && typeof ex === "object") {
|
|
3048
|
-
checkResponse(exerciseResponseSchema, ex,
|
|
3173
|
+
checkResponse(exerciseResponseSchema, ex, `exercise ${label}`);
|
|
3049
3174
|
const s = toStored(ex);
|
|
3050
3175
|
if (s) {
|
|
3051
3176
|
this.#byId.set(s.id, s);
|
|
@@ -3054,6 +3179,15 @@ var ExerciseLibrary = class {
|
|
|
3054
3179
|
}
|
|
3055
3180
|
return ex;
|
|
3056
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
|
+
}
|
|
3057
3191
|
async recordDelete(id) {
|
|
3058
3192
|
await this.ensureFresh();
|
|
3059
3193
|
if (this.#byId.delete(id)) await this.#persist();
|
|
@@ -3124,11 +3258,35 @@ const SIMPLE_GETS = [
|
|
|
3124
3258
|
description: "Unread counts including countMessagingNotViewed (cheap 'anything new?' poll).",
|
|
3125
3259
|
path: "/v5/notifications/counts"
|
|
3126
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
|
+
},
|
|
3127
3279
|
{
|
|
3128
3280
|
name: "analytics_categories",
|
|
3129
3281
|
title: "Analytics categories",
|
|
3130
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.",
|
|
3131
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
|
|
3132
3290
|
}
|
|
3133
3291
|
];
|
|
3134
3292
|
/** Roster-level reads: the fixed GETs plus the filterable athlete and team lists. */
|
|
@@ -3291,9 +3449,18 @@ function registerTeamVolume(server, ctx) {
|
|
|
3291
3449
|
}
|
|
3292
3450
|
function registerReadTools(server, ctx) {
|
|
3293
3451
|
registerRosterReads(server, ctx);
|
|
3452
|
+
registerCoachAthleteTeamCalendar(server, ctx);
|
|
3294
3453
|
registerEntityReads(server, ctx);
|
|
3295
3454
|
registerTeamVolume(server, ctx);
|
|
3296
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
|
+
}
|
|
3297
3464
|
//#endregion
|
|
3298
3465
|
//#region ../core/src/tools/main-lifts.ts
|
|
3299
3466
|
const monthsParam = z.number().int().positive().max(36).optional();
|
|
@@ -3603,6 +3770,37 @@ function registerTeamTools(server, ctx) {
|
|
|
3603
3770
|
if (blocked) return blocked;
|
|
3604
3771
|
return apiCall(ctx, "DELETE", `/v5/teamCodes/${id}`);
|
|
3605
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
|
+
}));
|
|
3606
3804
|
}
|
|
3607
3805
|
//#endregion
|
|
3608
3806
|
//#region ../core/src/tools/programs.ts
|
|
@@ -3625,6 +3823,20 @@ function registerProgramTools(server, ctx) {
|
|
|
3625
3823
|
kind,
|
|
3626
3824
|
name
|
|
3627
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
|
+
}));
|
|
3628
3840
|
}
|
|
3629
3841
|
//#endregion
|
|
3630
3842
|
//#region ../core/src/tools/analytics.ts
|
|
@@ -3658,6 +3870,38 @@ function registerAnalyticsTools(server, ctx) {
|
|
|
3658
3870
|
}
|
|
3659
3871
|
//#endregion
|
|
3660
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
|
+
}
|
|
3661
3905
|
/**
|
|
3662
3906
|
* Exercise library tools over the ExerciseIndex — a D1 mirror on the hosted server, an
|
|
3663
3907
|
* on-disk/in-memory cache locally. The descriptions stay at the interface level so they
|
|
@@ -3709,9 +3953,11 @@ function registerExerciseTools(server, ctx) {
|
|
|
3709
3953
|
openWorldHint: true
|
|
3710
3954
|
}
|
|
3711
3955
|
}, ({ exercise }) => attempt(async () => jsonResult(await index.create(exercise))));
|
|
3956
|
+
registerExerciseUpdate(server, index);
|
|
3957
|
+
registerExerciseDelete(server, index);
|
|
3712
3958
|
server.registerTool("exercise_forget", {
|
|
3713
3959
|
title: "Forget exercise (cache only)",
|
|
3714
|
-
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.",
|
|
3715
3961
|
inputSchema: { id: idParam },
|
|
3716
3962
|
annotations: {
|
|
3717
3963
|
readOnlyHint: false,
|
|
@@ -3885,11 +4131,41 @@ function registerLifecycle(server, ctx) {
|
|
|
3885
4131
|
}
|
|
3886
4132
|
}, ({ workoutId }) => apiCall(ctx, "POST", `/2.0/coach/calendar/programWorkout/saveWorkoutAsTemplate/${workoutId}`));
|
|
3887
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
|
+
}
|
|
3888
4163
|
/** Workout building, read-back, publishing, and the session calendar lifecycle. */
|
|
3889
4164
|
function registerWorkoutTools(server, ctx) {
|
|
3890
4165
|
registerBuild(server, ctx);
|
|
3891
4166
|
registerReadPublish(server, ctx);
|
|
3892
4167
|
registerLifecycle(server, ctx);
|
|
4168
|
+
registerTemplateLibrary(server, ctx);
|
|
3893
4169
|
}
|
|
3894
4170
|
//#endregion
|
|
3895
4171
|
//#region ../core/src/tools/messaging.ts
|
|
@@ -4014,7 +4290,7 @@ var JsonFileLibraryCache = class {
|
|
|
4014
4290
|
};
|
|
4015
4291
|
//#endregion
|
|
4016
4292
|
//#region package.json
|
|
4017
|
-
var version = "3.
|
|
4293
|
+
var version = "3.2.0";
|
|
4018
4294
|
//#endregion
|
|
4019
4295
|
//#region src/server.ts
|
|
4020
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",
|