@trainheroic-unofficial/core 1.7.4 → 2.0.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/README.md +15 -13
- package/dist/index.d.mts +38 -11
- package/dist/index.mjs +106 -48
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -26,12 +26,12 @@ D1-backed store).
|
|
|
26
26
|
Install it alongside the MCP SDK and the `js` client (both peers you construct from):
|
|
27
27
|
|
|
28
28
|
```bash
|
|
29
|
-
npm install @trainheroic-unofficial/core @trainheroic-unofficial/js @modelcontextprotocol/
|
|
29
|
+
npm install @trainheroic-unofficial/core @trainheroic-unofficial/js @modelcontextprotocol/server@2.0.0
|
|
30
30
|
```
|
|
31
31
|
|
|
32
32
|
```ts
|
|
33
|
-
import { McpServer } from "@modelcontextprotocol/
|
|
34
|
-
import {
|
|
33
|
+
import { McpServer } from "@modelcontextprotocol/server";
|
|
34
|
+
import { serveStdio } from "@modelcontextprotocol/server/stdio";
|
|
35
35
|
import { TrainHeroicClient, ExerciseLibrary } from "@trainheroic-unofficial/js";
|
|
36
36
|
import {
|
|
37
37
|
registerReadTools,
|
|
@@ -46,14 +46,15 @@ const client = new TrainHeroicClient(
|
|
|
46
46
|
process.env.TRAINHEROIC_PASSWORD!,
|
|
47
47
|
);
|
|
48
48
|
const index = new ExerciseLibrary(client);
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
49
|
+
|
|
50
|
+
serveStdio(() => {
|
|
51
|
+
const server = new McpServer({ name: "trainheroic", version: "1.0.0" });
|
|
52
|
+
const ctx: ToolContext = { client, index };
|
|
53
|
+
registerReadTools(server, ctx);
|
|
54
|
+
registerExerciseTools(server, ctx);
|
|
55
|
+
registerWorkoutTools(server, ctx);
|
|
56
|
+
return server;
|
|
57
|
+
});
|
|
57
58
|
```
|
|
58
59
|
|
|
59
60
|
Because the context depends on the `ExerciseIndex` interface rather than a concrete store, the
|
|
@@ -80,8 +81,9 @@ training tools that the athlete server registers.)
|
|
|
80
81
|
Tools return their result in-band. A failure comes back as an error result the model can read
|
|
81
82
|
and self-correct from. Reads are annotated read-only. Athlete-facing or
|
|
82
83
|
destructive actions (publish, unpublish, remove, send, delete, archive, team/code delete) pass
|
|
83
|
-
through a confirmation gate. The gate prefers MCP elicitation
|
|
84
|
-
|
|
84
|
+
through a confirmation gate. The gate prefers MCP multi-round-trip elicitation
|
|
85
|
+
(`input_required`); when the client already confirmed, it accepts an explicit
|
|
86
|
+
`confirm: true` argument. It fails closed if neither condition is met.
|
|
85
87
|
|
|
86
88
|
The D1-backed warehouse sync tools live in the `cloudflare` package because they depend on its storage.
|
|
87
89
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { CallToolResult, InputRequiredResult, McpServer, ServerContext } from "@modelcontextprotocol/server";
|
|
1
2
|
import { ExerciseIndex, RequestOptions, SessionExercise, TrainHeroicClient } from "@trainheroic-unofficial/js";
|
|
2
|
-
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
3
|
-
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
4
|
-
|
|
5
3
|
//#region src/context.d.ts
|
|
4
|
+
/** What a tool handler may return: a finished result or an MRTR input round. */
|
|
5
|
+
type ToolHandlerResult = CallToolResult | InputRequiredResult;
|
|
6
6
|
/** A tool argument that accepts a numeric id as a number or a string of digits. */
|
|
7
7
|
declare const idParam: import("zod").ZodUnion<readonly [import("zod").ZodNumber, import("zod").ZodString]>;
|
|
8
8
|
declare function toId(value: string | number): number;
|
|
@@ -26,8 +26,12 @@ type ToolContext = {
|
|
|
26
26
|
client: TrainHeroicClient;
|
|
27
27
|
index: ExerciseIndex;
|
|
28
28
|
};
|
|
29
|
-
/**
|
|
30
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Run a tool body, converting thrown errors into an in-band tool error. Generic so a caller that
|
|
31
|
+
* only ever produces a `CallToolResult` keeps that narrower type instead of widening to the
|
|
32
|
+
* MRTR union — that is what lets `apiCall` delegate here rather than repeat this catch.
|
|
33
|
+
*/
|
|
34
|
+
declare function attempt<T extends ToolHandlerResult>(fn: () => Promise<T>): Promise<T | CallToolResult>;
|
|
31
35
|
/** Conservative per-result character cap, below the smallest host cap. */
|
|
32
36
|
declare const DEFAULT_RESULT_BUDGET = 60000;
|
|
33
37
|
/**
|
|
@@ -66,13 +70,32 @@ declare function errorResult(message: string): CallToolResult;
|
|
|
66
70
|
declare function apiCall(ctx: ToolContext, method: string, path: string, options?: RequestOptions, hint?: string): Promise<CallToolResult>;
|
|
67
71
|
//#endregion
|
|
68
72
|
//#region src/confirm.d.ts
|
|
69
|
-
declare const NOT_CONFIRMED = "Not confirmed. Re-run with confirm:true, or connect a client that supports MCP elicitation.";
|
|
70
73
|
/**
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
+
* Returned when the user was asked and said no. It must not tell the model how to retry: the
|
|
75
|
+
* refusal is the answer. (The `confirm: true` fallback for clients that cannot elicit is
|
|
76
|
+
* advertised in each gated tool's description, which is where a model looks before calling.)
|
|
74
77
|
*/
|
|
75
|
-
declare
|
|
78
|
+
declare const NOT_CONFIRMED = "Not confirmed — the user declined. Nothing was changed.";
|
|
79
|
+
/**
|
|
80
|
+
* Confirm a destructive/athlete-facing action.
|
|
81
|
+
*
|
|
82
|
+
* Prefers MCP multi-round-trip elicitation (`input_required`); falls back to an explicit
|
|
83
|
+
* `confirm:true` argument when the client already confirmed. Never proceeds without one of the two.
|
|
84
|
+
*
|
|
85
|
+
* Returns `undefined` when the action may proceed, otherwise the result to return to the client
|
|
86
|
+
* (`input_required` or an in-band denial).
|
|
87
|
+
*
|
|
88
|
+
* **Call this before any read or write.** MRTR is re-entrant: the client answers by re-sending
|
|
89
|
+
* the whole `tools/call`, and the stateless handler builds a fresh server and runs the handler
|
|
90
|
+
* from the top. Anything above the gate therefore executes twice on a confirmed action. If a
|
|
91
|
+
* confirmation message ever needs data fetched first, that fetch must be idempotent.
|
|
92
|
+
*
|
|
93
|
+
* Written once in the 2026 `inputRequired` style: modern clients retry with `inputResponses`.
|
|
94
|
+
* A client that cannot elicit at all never reaches the denial below — the SDK rejects the
|
|
95
|
+
* request before the retry — so it must pass `confirm: true`, which is why the hint rides inside
|
|
96
|
+
* the prompt text itself.
|
|
97
|
+
*/
|
|
98
|
+
declare function confirmGate(ctx: ServerContext, message: string, confirmArg: boolean | undefined): ToolHandlerResult | undefined;
|
|
76
99
|
//#endregion
|
|
77
100
|
//#region src/instructions.d.ts
|
|
78
101
|
/**
|
|
@@ -154,4 +177,8 @@ declare function registerWorkoutTools(server: McpServer, ctx: ToolContext): void
|
|
|
154
177
|
/** Live messaging: list/read conversations, draft a message, and the gated send/delete. */
|
|
155
178
|
declare function registerMessagingTools(server: McpServer, ctx: ToolContext): void;
|
|
156
179
|
//#endregion
|
|
157
|
-
|
|
180
|
+
//#region src/tools/coach.d.ts
|
|
181
|
+
/** Register the full coach tool surface (roster, teams, programs, exercises, messaging). */
|
|
182
|
+
declare function registerCoachTools(server: McpServer, ctx: ToolContext): void;
|
|
183
|
+
//#endregion
|
|
184
|
+
export { AthleteContext, BudgetHint, DEFAULT_RESULT_BUDGET, DESTRUCTIVE, NOT_CONFIRMED, READ, SERVER_INSTRUCTIONS, SYNC, ToolContext, ToolHandlerResult, apiCall, attempt, boundedSerialize, clipArray, confirmGate, errorResult, idParam, jsonResult, mapSessionExercises, registerAnalyticsTools, registerAthleteTools, registerAthleteTrainingTools, registerCoachTools, registerExerciseTools, registerMainLiftTools, registerMessagingTools, registerReadTools, registerTeamTools, registerWorkoutTools, resultBudget, toId };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { athleteSessionRemoveArgsSchema, blockSpecSchema, coachLogSessionArgsSchema, coachLogSetArgsSchema, coachPrescribeSetArgsSchema, commentDraftSchema, dateString, exerciseCreateSchema, idArgSchema, logSessionArgsSchema, logSetArgsSchema, parseWorkoutDate, swapAthleteExerciseArgsSchema } from "@trainheroic-unofficial/dto";
|
|
2
|
+
import { acceptedContent, inputRequired, inputResponse } from "@modelcontextprotocol/server";
|
|
2
3
|
import { z } from "zod";
|
|
3
4
|
import { ANALYTICS_METRIC_KEYS, addExercisesToWorkout, buildCommentPayload, buildSession, coerceInt, collectAdvisories, copySession, createPersonalWorkout, definedProps, deleteComment, exerciseUnits, fetchAthleteMainLiftPRs, fetchAthletePrefs, fetchAthleteProfileSummary, fetchAthleteUser, fetchAthleteWorkouts, fetchCoachAthleteCalendarSummary, fetchCoachAthleteWorkouts, fetchExerciseHistoryDetail, fetchExerciseHistoryList, fetchExerciseStats, fetchLeaderboard, fetchPersonalRecords, fetchRosterActivity, fetchRosterMainLiftPRs, fetchStreams, fetchTeamAthleteIds, fetchWorkingMaxes, inviteAthletes, isRecord, logAdHocSession, logAthleteSet, logForAthlete, logSessionForAthlete, prescribeForAthlete, presentAthleteWorkouts, presentCoachAthleteTraining, presentExerciseHistory, presentLogTargets, publishSession, queryAnalytics, readLive, readSession, removePersonalWorkout, removeSession, searchExerciseHistory, selectWorkouts, selectWorkoutsByProgram, sendComment, summarizeAthleteWorkouts, swapAthleteExercise, teamVolume, toSetResults } from "@trainheroic-unofficial/js";
|
|
4
5
|
//#region src/context.ts
|
|
@@ -22,7 +23,11 @@ const DESTRUCTIVE = {
|
|
|
22
23
|
destructiveHint: true,
|
|
23
24
|
openWorldHint: true
|
|
24
25
|
};
|
|
25
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* Run a tool body, converting thrown errors into an in-band tool error. Generic so a caller that
|
|
28
|
+
* only ever produces a `CallToolResult` keeps that narrower type instead of widening to the
|
|
29
|
+
* MRTR union — that is what lets `apiCall` delegate here rather than repeat this catch.
|
|
30
|
+
*/
|
|
26
31
|
async function attempt(fn) {
|
|
27
32
|
try {
|
|
28
33
|
return await fn();
|
|
@@ -168,32 +173,50 @@ async function apiCall(ctx, method, path, options, hint) {
|
|
|
168
173
|
}
|
|
169
174
|
//#endregion
|
|
170
175
|
//#region src/confirm.ts
|
|
171
|
-
const NOT_CONFIRMED = "Not confirmed. Re-run with confirm:true, or connect a client that supports MCP elicitation.";
|
|
172
176
|
/**
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
177
|
+
* Returned when the user was asked and said no. It must not tell the model how to retry: the
|
|
178
|
+
* refusal is the answer. (The `confirm: true` fallback for clients that cannot elicit is
|
|
179
|
+
* advertised in each gated tool's description, which is where a model looks before calling.)
|
|
176
180
|
*/
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
181
|
+
const NOT_CONFIRMED = "Not confirmed — the user declined. Nothing was changed.";
|
|
182
|
+
/** Appended to the prompt so the fallback survives whichever way a client surfaces the request. */
|
|
183
|
+
const FALLBACK_HINT = " (If you cannot show this prompt, re-run the tool with confirm:true once the user has agreed.)";
|
|
184
|
+
/**
|
|
185
|
+
* Confirm a destructive/athlete-facing action.
|
|
186
|
+
*
|
|
187
|
+
* Prefers MCP multi-round-trip elicitation (`input_required`); falls back to an explicit
|
|
188
|
+
* `confirm:true` argument when the client already confirmed. Never proceeds without one of the two.
|
|
189
|
+
*
|
|
190
|
+
* Returns `undefined` when the action may proceed, otherwise the result to return to the client
|
|
191
|
+
* (`input_required` or an in-band denial).
|
|
192
|
+
*
|
|
193
|
+
* **Call this before any read or write.** MRTR is re-entrant: the client answers by re-sending
|
|
194
|
+
* the whole `tools/call`, and the stateless handler builds a fresh server and runs the handler
|
|
195
|
+
* from the top. Anything above the gate therefore executes twice on a confirmed action. If a
|
|
196
|
+
* confirmation message ever needs data fetched first, that fetch must be idempotent.
|
|
197
|
+
*
|
|
198
|
+
* Written once in the 2026 `inputRequired` style: modern clients retry with `inputResponses`.
|
|
199
|
+
* A client that cannot elicit at all never reaches the denial below — the SDK rejects the
|
|
200
|
+
* request before the retry — so it must pass `confirm: true`, which is why the hint rides inside
|
|
201
|
+
* the prompt text itself.
|
|
202
|
+
*/
|
|
203
|
+
function confirmGate(ctx, message, confirmArg) {
|
|
204
|
+
if (confirmArg === true) return void 0;
|
|
205
|
+
if (acceptedContent(ctx.mcpReq.inputResponses, "confirm")?.confirm === true) return void 0;
|
|
206
|
+
if (inputResponse(ctx.mcpReq.inputResponses, "confirm").kind !== "missing") return errorResult(NOT_CONFIRMED);
|
|
207
|
+
const prompt = message + FALLBACK_HINT;
|
|
208
|
+
return inputRequired({ inputRequests: { confirm: inputRequired.elicit({
|
|
209
|
+
message: prompt,
|
|
210
|
+
requestedSchema: {
|
|
211
|
+
type: "object",
|
|
212
|
+
properties: { confirm: {
|
|
213
|
+
type: "boolean",
|
|
214
|
+
title: "Confirm",
|
|
215
|
+
description: prompt
|
|
216
|
+
} },
|
|
217
|
+
required: ["confirm"]
|
|
218
|
+
}
|
|
219
|
+
}) } });
|
|
197
220
|
}
|
|
198
221
|
//#endregion
|
|
199
222
|
//#region src/instructions.ts
|
|
@@ -375,7 +398,8 @@ function registerEntityReads(server, ctx) {
|
|
|
375
398
|
},
|
|
376
399
|
annotations: READ
|
|
377
400
|
}, ({ athleteId, year, month }) => attempt(async () => {
|
|
378
|
-
|
|
401
|
+
const raw = await fetchCoachAthleteCalendarSummary(ctx.client, toId(athleteId), year, month);
|
|
402
|
+
return jsonResult(presentCoachAthleteTraining(raw, toId(athleteId), year, month), { hint: "One session per row for the month. Use the exercise titles to pick lifts, then athlete_lift_history for their PRs." });
|
|
379
403
|
}));
|
|
380
404
|
server.registerTool("get_program", {
|
|
381
405
|
title: "Get program detail",
|
|
@@ -600,11 +624,13 @@ function registerLogTargetsTool(server, ctx) {
|
|
|
600
624
|
},
|
|
601
625
|
annotations: READ
|
|
602
626
|
}, ({ startDate, endDate, program, programId, teamId, raw }) => attempt(async () => {
|
|
603
|
-
const
|
|
627
|
+
const all = await fetchAthleteWorkouts(ctx.client, startDate, endDate);
|
|
628
|
+
const filter = definedProps({
|
|
604
629
|
programTitle: program,
|
|
605
630
|
programId: programId === void 0 ? void 0 : toId(programId),
|
|
606
631
|
teamId: teamId === void 0 ? void 0 : toId(teamId)
|
|
607
|
-
})
|
|
632
|
+
});
|
|
633
|
+
const workouts = selectWorkoutsByProgram(all, filter);
|
|
608
634
|
if (raw === true) return jsonResult(workouts, { hint: "Each set's id is the savedWorkoutSetId; each savedWorkoutSetExercises[].id is the savedWorkoutSetExerciseId. Large — if truncated, pass program (a title substring) or use the default compact view." });
|
|
609
635
|
return jsonResult(presentLogTargets(workouts), { hint: "One row per saved set: savedWorkoutSetId plus each savedWorkoutSetExerciseId, with the program it belongs to. Pass both to athlete_log_set. Filter with program (title substring), programId, or teamId if you're on several programs." });
|
|
610
636
|
}));
|
|
@@ -653,7 +679,8 @@ function registerSessionTools(server, ctx) {
|
|
|
653
679
|
annotations: DESTRUCTIVE
|
|
654
680
|
}, ({ programWorkoutId, date, confirm }, extra) => attempt(async () => {
|
|
655
681
|
const id = toId(programWorkoutId);
|
|
656
|
-
|
|
682
|
+
const blocked = confirmGate(extra, `Permanently remove personal session ${id} on ${date}? This deletes the session and anything logged in it.`, confirm);
|
|
683
|
+
if (blocked) return blocked;
|
|
657
684
|
await removePersonalWorkout(ctx.client, {
|
|
658
685
|
programWorkoutId: id,
|
|
659
686
|
date
|
|
@@ -693,7 +720,8 @@ function registerLogTool(server, ctx) {
|
|
|
693
720
|
},
|
|
694
721
|
annotations: DESTRUCTIVE
|
|
695
722
|
}, ({ date, exercises, confirm }, extra) => attempt(async () => {
|
|
696
|
-
|
|
723
|
+
const blocked = confirmGate(extra, `Log a session of ${exercises.length} exercise(s) on ${date}? This writes to your coach-visible training log.`, confirm);
|
|
724
|
+
if (blocked) return blocked;
|
|
697
725
|
const res = await logAdHocSession(ctx.client, {
|
|
698
726
|
date,
|
|
699
727
|
exercises: mapSessionExercises(exercises)
|
|
@@ -710,7 +738,8 @@ function registerLogTool(server, ctx) {
|
|
|
710
738
|
},
|
|
711
739
|
annotations: DESTRUCTIVE
|
|
712
740
|
}, ({ date, savedWorkoutSetId, results, confirm }, extra) => attempt(async () => {
|
|
713
|
-
|
|
741
|
+
const blocked = confirmGate(extra, `Log results to saved workout set ${toId(savedWorkoutSetId)} on ${date}? This writes to your coach-visible training log.`, confirm);
|
|
742
|
+
if (blocked) return blocked;
|
|
714
743
|
return jsonResult(await logAthleteSet(ctx.client, {
|
|
715
744
|
date,
|
|
716
745
|
savedWorkoutSetId: toId(savedWorkoutSetId),
|
|
@@ -736,7 +765,8 @@ function registerSwapTool(server, ctx) {
|
|
|
736
765
|
}, ({ savedWorkoutSetExerciseId, exerciseId, confirm }, extra) => attempt(async () => {
|
|
737
766
|
const sweId = toId(savedWorkoutSetExerciseId);
|
|
738
767
|
const exId = toId(exerciseId);
|
|
739
|
-
|
|
768
|
+
const blocked = confirmGate(extra, `Swap the exercise in your saved workout slot ${sweId} to exercise ${exId}? This changes what that slot is prescribed (your copy only).`, confirm);
|
|
769
|
+
if (blocked) return blocked;
|
|
740
770
|
return jsonResult(await swapAthleteExercise(ctx.client, {
|
|
741
771
|
savedWorkoutSetExerciseId: sweId,
|
|
742
772
|
exerciseId: exId
|
|
@@ -798,7 +828,8 @@ function registerAthleteTools(server, ctx) {
|
|
|
798
828
|
const list = asEmailList(emails);
|
|
799
829
|
if (list.length === 0) return errorResult("Provide at least one email address to invite.");
|
|
800
830
|
const id = toId(teamId);
|
|
801
|
-
|
|
831
|
+
const blocked = confirmGate(extra, `Invite ${list.join(", ")} to team ${id}? This emails them a real TrainHeroic invitation.`, confirm);
|
|
832
|
+
if (blocked) return blocked;
|
|
802
833
|
return jsonResult({
|
|
803
834
|
invited: true,
|
|
804
835
|
teamId: id,
|
|
@@ -819,7 +850,8 @@ function registerAthleteTools(server, ctx) {
|
|
|
819
850
|
annotations: DESTRUCTIVE
|
|
820
851
|
}, ({ athleteIds, confirm }, extra) => attempt(async () => {
|
|
821
852
|
const ids = athleteIds.map(toId);
|
|
822
|
-
|
|
853
|
+
const blocked = confirmGate(extra, `Archive athlete(s) ${ids.join(", ")}? They leave the active roster (data is kept and restorable).`, confirm);
|
|
854
|
+
if (blocked) return blocked;
|
|
823
855
|
return apiCall(ctx, "PUT", "/v5/athletes/archive", { body: { athleteIds: ids } });
|
|
824
856
|
}));
|
|
825
857
|
server.registerTool("athlete_restore", {
|
|
@@ -858,11 +890,13 @@ function registerAthleteSavedWorkouts(server, ctx) {
|
|
|
858
890
|
},
|
|
859
891
|
annotations: READ
|
|
860
892
|
}, ({ athleteId, startDate, endDate, program, programId, teamId, raw }) => attempt(async () => {
|
|
861
|
-
const
|
|
893
|
+
const all = await fetchCoachAthleteWorkouts(ctx.client, toId(athleteId), startDate, endDate);
|
|
894
|
+
const filter = definedProps({
|
|
862
895
|
programTitle: program,
|
|
863
896
|
programId: programId === void 0 ? void 0 : toId(programId),
|
|
864
897
|
teamId: teamId === void 0 ? void 0 : toId(teamId)
|
|
865
|
-
})
|
|
898
|
+
});
|
|
899
|
+
const workouts = selectWorkoutsByProgram(all, filter);
|
|
866
900
|
if (raw === true) return jsonResult(workouts, { hint: "Each set's id is the savedWorkoutSetId; each savedWorkoutSetExercises[].id is the savedWorkoutSetExerciseId. This raw blob is large — if truncated, pass program (a title substring) to target one program, or use the default (compact) view which carries the same ids." });
|
|
867
901
|
return jsonResult(presentLogTargets(workouts), { hint: "One row per saved set: savedWorkoutSetId plus each savedWorkoutSetExerciseId, with the program it belongs to. Pass both ids to log_athlete_set / prescribe_athlete_set. Filter with program (title substring), programId, or teamId if the athlete is on several programs." });
|
|
868
902
|
}));
|
|
@@ -879,7 +913,8 @@ function registerAthleteLogTools(server, ctx) {
|
|
|
879
913
|
annotations: DESTRUCTIVE
|
|
880
914
|
}, ({ athleteId, date, savedWorkoutSetId, results, confirm }, extra) => attempt(async () => {
|
|
881
915
|
const aId = toId(athleteId);
|
|
882
|
-
|
|
916
|
+
const blocked = confirmGate(extra, `Log results to athlete ${aId}'s saved workout set ${toId(savedWorkoutSetId)} on ${date}? This writes to their coach-visible training log.`, confirm);
|
|
917
|
+
if (blocked) return blocked;
|
|
883
918
|
return jsonResult(await logForAthlete(ctx.client, {
|
|
884
919
|
athleteId: aId,
|
|
885
920
|
date,
|
|
@@ -897,7 +932,8 @@ function registerAthleteLogTools(server, ctx) {
|
|
|
897
932
|
annotations: DESTRUCTIVE
|
|
898
933
|
}, ({ athleteId, date, exercises, confirm }, extra) => attempt(async () => {
|
|
899
934
|
const aId = toId(athleteId);
|
|
900
|
-
|
|
935
|
+
const blocked = confirmGate(extra, `Log a session of ${exercises.length} exercise(s) for athlete ${aId} on ${date}? This writes to their coach-visible training log.`, confirm);
|
|
936
|
+
if (blocked) return blocked;
|
|
901
937
|
return jsonResult(await logSessionForAthlete(ctx.client, {
|
|
902
938
|
athleteId: aId,
|
|
903
939
|
date,
|
|
@@ -921,7 +957,8 @@ function registerAthleteSwapTool(server, ctx) {
|
|
|
921
957
|
}, ({ savedWorkoutSetExerciseId, exerciseId, confirm }, extra) => attempt(async () => {
|
|
922
958
|
const sweId = toId(savedWorkoutSetExerciseId);
|
|
923
959
|
const exId = toId(exerciseId);
|
|
924
|
-
|
|
960
|
+
const blocked = confirmGate(extra, `Swap the exercise in saved workout slot ${sweId} to exercise ${exId}? This changes what this athlete is prescribed (their copy only).`, confirm);
|
|
961
|
+
if (blocked) return blocked;
|
|
925
962
|
return jsonResult(await swapAthleteExercise(ctx.client, {
|
|
926
963
|
savedWorkoutSetExerciseId: sweId,
|
|
927
964
|
exerciseId: exId
|
|
@@ -944,7 +981,8 @@ function registerAthletePrescribeTool(server, ctx) {
|
|
|
944
981
|
annotations: DESTRUCTIVE
|
|
945
982
|
}, ({ athleteId, date, savedWorkoutSetId, results, confirm }, extra) => attempt(async () => {
|
|
946
983
|
const aId = toId(athleteId);
|
|
947
|
-
|
|
984
|
+
const blocked = confirmGate(extra, `Set prescribed values on athlete ${aId}'s saved workout set ${toId(savedWorkoutSetId)} on ${date}? This changes what this athlete is prescribed (their copy only); it does not mark the set done.`, confirm);
|
|
985
|
+
if (blocked) return blocked;
|
|
948
986
|
return jsonResult(await prescribeForAthlete(ctx.client, {
|
|
949
987
|
athleteId: aId,
|
|
950
988
|
date,
|
|
@@ -990,7 +1028,8 @@ function registerTeamTools(server, ctx) {
|
|
|
990
1028
|
annotations: DESTRUCTIVE
|
|
991
1029
|
}, ({ teamId, confirm }, extra) => attempt(async () => {
|
|
992
1030
|
const id = toId(teamId);
|
|
993
|
-
|
|
1031
|
+
const blocked = confirmGate(extra, `Delete team ${id}? This removes the team and its calendar from the live account.`, confirm);
|
|
1032
|
+
if (blocked) return blocked;
|
|
994
1033
|
return apiCall(ctx, "DELETE", `/v5/teams/${id}`);
|
|
995
1034
|
}));
|
|
996
1035
|
server.registerTool("team_code_create", {
|
|
@@ -1012,7 +1051,8 @@ function registerTeamTools(server, ctx) {
|
|
|
1012
1051
|
annotations: DESTRUCTIVE
|
|
1013
1052
|
}, ({ codeId, confirm }, extra) => attempt(async () => {
|
|
1014
1053
|
const id = toId(codeId);
|
|
1015
|
-
|
|
1054
|
+
const blocked = confirmGate(extra, `Delete team join code ${id}? Athletes can no longer use it to join.`, confirm);
|
|
1055
|
+
if (blocked) return blocked;
|
|
1016
1056
|
return apiCall(ctx, "DELETE", `/v5/teamCodes/${id}`);
|
|
1017
1057
|
}));
|
|
1018
1058
|
}
|
|
@@ -1188,7 +1228,8 @@ function registerBuild(server, ctx) {
|
|
|
1188
1228
|
openWorldHint: true
|
|
1189
1229
|
}
|
|
1190
1230
|
}, ({ programId, date, pwId, confirm }, extra) => attempt(async () => {
|
|
1191
|
-
|
|
1231
|
+
const blocked = confirmGate(extra, `Publish session ${pwId} on ${date}? This is athlete-facing and immediate.`, confirm);
|
|
1232
|
+
if (blocked) return blocked;
|
|
1192
1233
|
await publishSession(ctx.client, pwId);
|
|
1193
1234
|
return jsonResult({
|
|
1194
1235
|
published: pwId,
|
|
@@ -1212,7 +1253,8 @@ function registerLifecycle(server, ctx) {
|
|
|
1212
1253
|
openWorldHint: true
|
|
1213
1254
|
}
|
|
1214
1255
|
}, ({ programId, pwId, confirm }, extra) => attempt(async () => {
|
|
1215
|
-
|
|
1256
|
+
const blocked = confirmGate(extra, `Delete session ${pwId}? This removes it from the live calendar and is hard to undo.`, confirm);
|
|
1257
|
+
if (blocked) return blocked;
|
|
1216
1258
|
await removeSession(ctx.client, programId, pwId);
|
|
1217
1259
|
return jsonResult({ removed: pwId });
|
|
1218
1260
|
}));
|
|
@@ -1229,7 +1271,8 @@ function registerLifecycle(server, ctx) {
|
|
|
1229
1271
|
openWorldHint: true
|
|
1230
1272
|
}
|
|
1231
1273
|
}, ({ pwId, confirm }, extra) => attempt(async () => {
|
|
1232
|
-
|
|
1274
|
+
const blocked = confirmGate(extra, `Unpublish session ${pwId}? Athletes will no longer see it.`, confirm);
|
|
1275
|
+
if (blocked) return blocked;
|
|
1233
1276
|
return apiCall(ctx, "POST", `/2.0/coach/calendar/programWorkout/unPublish/${pwId}`);
|
|
1234
1277
|
}));
|
|
1235
1278
|
server.registerTool("session_copy", {
|
|
@@ -1318,7 +1361,8 @@ function registerWrites(server, ctx) {
|
|
|
1318
1361
|
annotations: DESTRUCTIVE
|
|
1319
1362
|
}, ({ streamId, text, replyTo, confirm }, extra) => attempt(async () => {
|
|
1320
1363
|
const id = toId(streamId);
|
|
1321
|
-
|
|
1364
|
+
const blocked = confirmGate(extra, `Send this message to stream ${id}? It is athlete-facing and immediate.`, confirm);
|
|
1365
|
+
if (blocked) return blocked;
|
|
1322
1366
|
return jsonResult({
|
|
1323
1367
|
sent: true,
|
|
1324
1368
|
comment: await sendComment(ctx.client, id, text, replyTo === void 0 ? null : toId(replyTo))
|
|
@@ -1334,7 +1378,8 @@ function registerWrites(server, ctx) {
|
|
|
1334
1378
|
},
|
|
1335
1379
|
annotations: DESTRUCTIVE
|
|
1336
1380
|
}, ({ streamId, commentId, confirm }, extra) => attempt(async () => {
|
|
1337
|
-
|
|
1381
|
+
const blocked = confirmGate(extra, `Delete comment ${toId(commentId)} from stream ${toId(streamId)}? Acts on the live account.`, confirm);
|
|
1382
|
+
if (blocked) return blocked;
|
|
1338
1383
|
return jsonResult({
|
|
1339
1384
|
deleted: true,
|
|
1340
1385
|
response: await deleteComment(ctx.client, toId(streamId), toId(commentId))
|
|
@@ -1347,4 +1392,17 @@ function registerMessagingTools(server, ctx) {
|
|
|
1347
1392
|
registerWrites(server, ctx);
|
|
1348
1393
|
}
|
|
1349
1394
|
//#endregion
|
|
1350
|
-
|
|
1395
|
+
//#region src/tools/coach.ts
|
|
1396
|
+
/** Register the full coach tool surface (roster, teams, programs, exercises, messaging). */
|
|
1397
|
+
function registerCoachTools(server, ctx) {
|
|
1398
|
+
registerReadTools(server, ctx);
|
|
1399
|
+
registerMainLiftTools(server, ctx);
|
|
1400
|
+
registerAthleteTools(server, ctx);
|
|
1401
|
+
registerTeamTools(server, ctx);
|
|
1402
|
+
registerAnalyticsTools(server, ctx);
|
|
1403
|
+
registerExerciseTools(server, ctx);
|
|
1404
|
+
registerWorkoutTools(server, ctx);
|
|
1405
|
+
registerMessagingTools(server, ctx);
|
|
1406
|
+
}
|
|
1407
|
+
//#endregion
|
|
1408
|
+
export { DEFAULT_RESULT_BUDGET, DESTRUCTIVE, NOT_CONFIRMED, READ, SERVER_INSTRUCTIONS, SYNC, apiCall, attempt, boundedSerialize, clipArray, confirmGate, errorResult, idParam, jsonResult, mapSessionExercises, registerAnalyticsTools, registerAthleteTools, registerAthleteTrainingTools, registerCoachTools, registerExerciseTools, registerMainLiftTools, registerMessagingTools, registerReadTools, registerTeamTools, registerWorkoutTools, resultBudget, toId };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trainheroic-unofficial/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,15 +23,15 @@
|
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@cfworker/json-schema": "^4.1.1",
|
|
26
|
-
"@modelcontextprotocol/
|
|
26
|
+
"@modelcontextprotocol/server": "2.0.0",
|
|
27
27
|
"zod": "^4.4.3",
|
|
28
|
-
"@trainheroic-unofficial/dto": "
|
|
29
|
-
"@trainheroic-unofficial/js": "
|
|
28
|
+
"@trainheroic-unofficial/dto": "2.0.0",
|
|
29
|
+
"@trainheroic-unofficial/js": "2.0.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@types/node": "^26.1.
|
|
33
|
-
"tsdown": "^0.22.
|
|
34
|
-
"typescript": "^
|
|
32
|
+
"@types/node": "^26.1.2",
|
|
33
|
+
"tsdown": "^0.22.14",
|
|
34
|
+
"typescript": "^7.0.2",
|
|
35
35
|
"vitest": "^4.1.10"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|