@trainheroic-unofficial/coach-mcp 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -13
- package/dist/server.mjs +368 -40
- package/package.json +4 -8
package/README.md
CHANGED
|
@@ -8,10 +8,6 @@ For the hosted version (no install, OAuth login), see the [root README](../../RE
|
|
|
8
8
|
|
|
9
9
|
## Install
|
|
10
10
|
|
|
11
|
-
### Claude Desktop extension (easiest)
|
|
12
|
-
|
|
13
|
-
Download `trainheroic-coach-mcp.mcpb` from the [Releases page](https://github.com/alandotcom/trainheroic-skill/releases), drag it onto Claude Desktop, and enter your TrainHeroic email and password. Credentials are stored in the OS keychain. No Node toolchain needed.
|
|
14
|
-
|
|
15
11
|
### Claude Code
|
|
16
12
|
|
|
17
13
|
```bash
|
|
@@ -31,10 +27,10 @@ claude mcp add trainheroic \
|
|
|
31
27
|
"args": ["-y", "@trainheroic-unofficial/coach-mcp"],
|
|
32
28
|
"env": {
|
|
33
29
|
"TRAINHEROIC_EMAIL": "coach@example.com",
|
|
34
|
-
"TRAINHEROIC_PASSWORD": "yourpassword"
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
30
|
+
"TRAINHEROIC_PASSWORD": "yourpassword",
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
38
34
|
}
|
|
39
35
|
```
|
|
40
36
|
|
|
@@ -46,11 +42,6 @@ claude mcp add trainheroic \
|
|
|
46
42
|
pnpm start # run from source (needs TRAINHEROIC_EMAIL and TRAINHEROIC_PASSWORD)
|
|
47
43
|
pnpm inspect # MCP Inspector UI against the source server
|
|
48
44
|
pnpm build # tsdown → dist/server.mjs
|
|
49
|
-
pnpm build:mcpb # bundle + pack the Desktop extension → dist/trainheroic-coach-mcp.mcpb
|
|
50
45
|
pnpm typecheck
|
|
51
46
|
pnpm test
|
|
52
47
|
```
|
|
53
|
-
|
|
54
|
-
### Cut a release (maintainers)
|
|
55
|
-
|
|
56
|
-
Push a `coach-mcp-v*` tag. The `Release Coach MCPB` GitHub Actions workflow builds, signs, and attaches the `.mcpb` to the Release. Set `MCPB_CERT` / `MCPB_KEY` repo secrets to sign with a real certificate; omitting them produces a self-signed build.
|
package/dist/server.mjs
CHANGED
|
@@ -335,12 +335,12 @@ const SIMPLE_GETS = [
|
|
|
335
335
|
{
|
|
336
336
|
name: "analytics_categories",
|
|
337
337
|
title: "Analytics categories",
|
|
338
|
-
description: "Lists available analytics types. Pull
|
|
338
|
+
description: "Lists available analytics types. Pull a report with analytics_query (pick the matching metric).",
|
|
339
339
|
path: "/v5/analytics"
|
|
340
340
|
}
|
|
341
341
|
];
|
|
342
|
-
/**
|
|
343
|
-
function
|
|
342
|
+
/** Roster-level reads: the fixed GETs plus the filterable athlete and team lists. */
|
|
343
|
+
function registerRosterReads(server, ctx) {
|
|
344
344
|
for (const t of SIMPLE_GETS) server.registerTool(t.name, {
|
|
345
345
|
title: t.title,
|
|
346
346
|
description: t.description,
|
|
@@ -393,6 +393,9 @@ function registerReadTools(server, ctx) {
|
|
|
393
393
|
const query = qs.toString();
|
|
394
394
|
return apiCall(ctx, "GET", `/1.0/coach/teams${query ? `?${query}` : ""}`);
|
|
395
395
|
});
|
|
396
|
+
}
|
|
397
|
+
/** Reads scoped to a single entity (team, program, athlete) plus the activity feed. */
|
|
398
|
+
function registerEntityReads(server, ctx) {
|
|
396
399
|
server.registerTool("get_team", {
|
|
397
400
|
title: "Get team",
|
|
398
401
|
description: "Full team object by team id.",
|
|
@@ -411,39 +414,283 @@ function registerReadTools(server, ctx) {
|
|
|
411
414
|
inputSchema: { programId: idParam },
|
|
412
415
|
annotations: READ
|
|
413
416
|
}, ({ 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."));
|
|
417
|
+
server.registerTool("coach_activity_feed", {
|
|
418
|
+
title: "Coach activity feed",
|
|
419
|
+
description: "Recent athlete activity across the roster (GET /v5/coaches/activityFeed): completed workouts, PRs, and posts. Paginate with page/pageSize.",
|
|
420
|
+
inputSchema: {
|
|
421
|
+
page: z.number().int().positive().optional(),
|
|
422
|
+
pageSize: z.number().int().positive().optional()
|
|
423
|
+
},
|
|
424
|
+
annotations: READ
|
|
425
|
+
}, ({ page, pageSize }) => {
|
|
426
|
+
const qs = new URLSearchParams();
|
|
427
|
+
if (page !== void 0) qs.set("page", String(page));
|
|
428
|
+
if (pageSize !== void 0) qs.set("pageSize", String(pageSize));
|
|
429
|
+
const query = qs.toString();
|
|
430
|
+
return apiCall(ctx, "GET", `/v5/coaches/activityFeed${query ? `?${query}` : ""}`);
|
|
431
|
+
});
|
|
432
|
+
server.registerTool("athlete_workouts", {
|
|
433
|
+
title: "Athlete workout history",
|
|
434
|
+
description: "One athlete's workouts with their survey/readiness data (GET /v5/coaches/athletes/{athleteId}/workouts). Bound it with startDate/endDate (YYYY-MM-DD) to keep the response small.",
|
|
435
|
+
inputSchema: {
|
|
436
|
+
athleteId: idParam,
|
|
437
|
+
startDate: z.string().optional(),
|
|
438
|
+
endDate: z.string().optional()
|
|
439
|
+
},
|
|
440
|
+
annotations: READ
|
|
441
|
+
}, ({ athleteId, startDate, endDate }) => {
|
|
442
|
+
const qs = new URLSearchParams();
|
|
443
|
+
if (startDate !== void 0) qs.set("startDate", startDate);
|
|
444
|
+
if (endDate !== void 0) qs.set("endDate", endDate);
|
|
445
|
+
const query = qs.toString();
|
|
446
|
+
return apiCall(ctx, "GET", `/v5/coaches/athletes/${enc(athleteId)}/workouts${query ? `?${query}` : ""}`, void 0, "Narrow the date range to shrink this if it is truncated.");
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
/** Read-only coach/athlete queries. Exercise lookups live in the exercise store tools. */
|
|
450
|
+
function registerReadTools(server, ctx) {
|
|
451
|
+
registerRosterReads(server, ctx);
|
|
452
|
+
registerEntityReads(server, ctx);
|
|
414
453
|
}
|
|
415
454
|
//#endregion
|
|
416
|
-
//#region ../core/src/tools/
|
|
455
|
+
//#region ../core/src/tools/athletes.ts
|
|
456
|
+
const DEFAULT_INVITE_MESSAGE = "Follow these steps and you'll be set up and ready to go!";
|
|
457
|
+
/** Normalize one-or-many emails into a deduped, trimmed list. */
|
|
458
|
+
function asEmailList(emails) {
|
|
459
|
+
return [...new Set((Array.isArray(emails) ? emails : [emails]).map((e) => e.trim()).filter((e) => e.length > 0))];
|
|
460
|
+
}
|
|
417
461
|
/**
|
|
418
|
-
*
|
|
419
|
-
*
|
|
420
|
-
* the
|
|
462
|
+
* Athlete management. TrainHeroic has no "create athlete" primitive: a coach invites a
|
|
463
|
+
* person by email to a team, and the athlete record only exists once they accept and set
|
|
464
|
+
* their own name. So the create path is the two-step invite from the API reference:
|
|
465
|
+
* validate the address (POST /v5/emails/validate), then inviteToTeam
|
|
466
|
+
* (POST /v5/athletes/inviteToTeam). Both act on the live account, so the invite is gated.
|
|
421
467
|
*/
|
|
422
|
-
function
|
|
423
|
-
server.registerTool("
|
|
424
|
-
title: "
|
|
425
|
-
description: "
|
|
468
|
+
function registerAthleteTools(server, ctx) {
|
|
469
|
+
server.registerTool("athlete_invite", {
|
|
470
|
+
title: "Invite an athlete",
|
|
471
|
+
description: "Add athletes by emailing them a TrainHeroic team invitation — this is how you 'create' an athlete; there is no other create path, and no name is collected here (the athlete sets their own on accept). Targets a team by id, so list_teams first if you need one. Validates each address, then sends the invite. ATHLETE-FACING and immediate; requires confirmation (elicitation, or confirm:true).",
|
|
472
|
+
inputSchema: {
|
|
473
|
+
teamId: idParam,
|
|
474
|
+
emails: z.union([z.string(), z.array(z.string()).min(1)]),
|
|
475
|
+
message: z.string().optional(),
|
|
476
|
+
confirm: z.boolean().optional()
|
|
477
|
+
},
|
|
478
|
+
annotations: DESTRUCTIVE
|
|
479
|
+
}, ({ teamId, emails, message, confirm }, extra) => attempt(async () => {
|
|
480
|
+
const list = asEmailList(emails);
|
|
481
|
+
if (list.length === 0) return errorResult("Provide at least one email address to invite.");
|
|
482
|
+
const id = toId(teamId);
|
|
483
|
+
if (!await confirmGate(server, extra.requestId, `Invite ${list.join(", ")} to team ${id}? This emails them a real TrainHeroic invitation.`, confirm)) return errorResult(NOT_CONFIRMED);
|
|
484
|
+
const validation = await ctx.client.request("POST", "/v5/emails/validate", { body: { emails: list.join(",") } });
|
|
485
|
+
if (!validation.ok) {
|
|
486
|
+
const detail = typeof validation.data === "string" ? validation.data : JSON.stringify(validation.data);
|
|
487
|
+
return errorResult(`Email validation failed (HTTP ${validation.status}): ${detail}`);
|
|
488
|
+
}
|
|
489
|
+
const valid = Array.isArray(validation.data) ? validation.data : list;
|
|
490
|
+
if (valid.length === 0) return errorResult(`No valid addresses among: ${list.join(", ")}. They may be malformed or already on the team.`);
|
|
491
|
+
const invite = await ctx.client.request("POST", "/v5/athletes/inviteToTeam", { body: {
|
|
492
|
+
teamType: 0,
|
|
493
|
+
teamId: id,
|
|
494
|
+
orgId: null,
|
|
495
|
+
emails: valid,
|
|
496
|
+
message: message ?? DEFAULT_INVITE_MESSAGE
|
|
497
|
+
} });
|
|
498
|
+
if (!invite.ok) {
|
|
499
|
+
const detail = typeof invite.data === "string" ? invite.data : JSON.stringify(invite.data);
|
|
500
|
+
return errorResult(`Invite failed (HTTP ${invite.status}): ${detail}`);
|
|
501
|
+
}
|
|
502
|
+
return jsonResult({
|
|
503
|
+
invited: true,
|
|
504
|
+
teamId: id,
|
|
505
|
+
result: invite.data
|
|
506
|
+
});
|
|
507
|
+
}));
|
|
508
|
+
server.registerTool("athlete_archive", {
|
|
509
|
+
title: "Archive athletes",
|
|
510
|
+
description: "Remove one or more athletes from the active roster (PUT /v5/athletes/archive). Their data is preserved and they can be restored. Acts on the live account; requires confirmation (elicitation, or confirm:true).",
|
|
511
|
+
inputSchema: {
|
|
512
|
+
athleteIds: z.array(idParam).min(1),
|
|
513
|
+
confirm: z.boolean().optional()
|
|
514
|
+
},
|
|
515
|
+
annotations: DESTRUCTIVE
|
|
516
|
+
}, ({ athleteIds, confirm }, extra) => attempt(async () => {
|
|
517
|
+
const ids = athleteIds.map(toId);
|
|
518
|
+
if (!await confirmGate(server, extra.requestId, `Archive athlete(s) ${ids.join(", ")}? They leave the active roster (data is kept and restorable).`, confirm)) return errorResult(NOT_CONFIRMED);
|
|
519
|
+
return apiCall(ctx, "PUT", "/v5/athletes/archive", { body: { athleteIds: ids } });
|
|
520
|
+
}));
|
|
521
|
+
server.registerTool("athlete_restore", {
|
|
522
|
+
title: "Restore athletes",
|
|
523
|
+
description: "Restore previously archived athletes to the active roster (PUT /v5/athletes/restore).",
|
|
524
|
+
inputSchema: { athleteIds: z.array(idParam).min(1) },
|
|
525
|
+
annotations: {
|
|
526
|
+
readOnlyHint: false,
|
|
527
|
+
idempotentHint: true,
|
|
528
|
+
destructiveHint: false,
|
|
529
|
+
openWorldHint: true
|
|
530
|
+
}
|
|
531
|
+
}, ({ athleteIds }) => apiCall(ctx, "PUT", "/v5/athletes/restore", { body: { athleteIds: athleteIds.map(toId) } }));
|
|
532
|
+
}
|
|
533
|
+
//#endregion
|
|
534
|
+
//#region ../core/src/tools/teams.ts
|
|
535
|
+
const ADDITIVE = {
|
|
536
|
+
readOnlyHint: false,
|
|
537
|
+
destructiveHint: false,
|
|
538
|
+
openWorldHint: true
|
|
539
|
+
};
|
|
540
|
+
/**
|
|
541
|
+
* Team write tools. The team reads (list_teams, get_team, list_team_codes) live in
|
|
542
|
+
* reads.ts; this module covers create/rename/delete plus the join-code lifecycle.
|
|
543
|
+
*/
|
|
544
|
+
function registerTeamTools(server, ctx) {
|
|
545
|
+
server.registerTool("team_create", {
|
|
546
|
+
title: "Create a team",
|
|
547
|
+
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.",
|
|
548
|
+
inputSchema: { title: z.string().min(1) },
|
|
549
|
+
annotations: ADDITIVE
|
|
550
|
+
}, ({ title }) => apiCall(ctx, "POST", "/1.0/coach/team/createWithTitleAndCode", { body: { title } }));
|
|
551
|
+
server.registerTool("team_update", {
|
|
552
|
+
title: "Rename a team",
|
|
553
|
+
description: "Update a team's settings, e.g. its title (PUT /v5/teams/{teamId}).",
|
|
554
|
+
inputSchema: {
|
|
555
|
+
teamId: idParam,
|
|
556
|
+
title: z.string().min(1)
|
|
557
|
+
},
|
|
558
|
+
annotations: ADDITIVE
|
|
559
|
+
}, ({ teamId, title }) => apiCall(ctx, "PUT", `/v5/teams/${toId(teamId)}`, { body: { title } }));
|
|
560
|
+
server.registerTool("team_delete", {
|
|
561
|
+
title: "Delete a team",
|
|
562
|
+
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).",
|
|
563
|
+
inputSchema: {
|
|
564
|
+
teamId: idParam,
|
|
565
|
+
confirm: z.boolean().optional()
|
|
566
|
+
},
|
|
567
|
+
annotations: DESTRUCTIVE
|
|
568
|
+
}, ({ teamId, confirm }, extra) => attempt(async () => {
|
|
569
|
+
const id = toId(teamId);
|
|
570
|
+
if (!await confirmGate(server, extra.requestId, `Delete team ${id}? This removes the team and its calendar from the live account.`, confirm)) return errorResult(NOT_CONFIRMED);
|
|
571
|
+
return apiCall(ctx, "DELETE", `/v5/teams/${id}`);
|
|
572
|
+
}));
|
|
573
|
+
server.registerTool("team_code_create", {
|
|
574
|
+
title: "Create a team join code",
|
|
575
|
+
description: "Create an access code athletes use to self-join a team (POST /v5/teams/{teamId}/teamCodes). `type` defaults to 2, the standard join code.",
|
|
426
576
|
inputSchema: {
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
577
|
+
teamId: idParam,
|
|
578
|
+
type: z.number().int().optional()
|
|
579
|
+
},
|
|
580
|
+
annotations: ADDITIVE
|
|
581
|
+
}, ({ teamId, type }) => apiCall(ctx, "POST", `/v5/teams/${toId(teamId)}/teamCodes`, { body: { type: type ?? 2 } }));
|
|
582
|
+
server.registerTool("team_code_delete", {
|
|
583
|
+
title: "Delete a team join code",
|
|
584
|
+
description: "Delete a team access code by its id (DELETE /v5/teamCodes/{codeId}). Athletes can no longer use it to join. Requires confirmation (elicitation, or confirm:true).",
|
|
585
|
+
inputSchema: {
|
|
586
|
+
codeId: idParam,
|
|
436
587
|
confirm: z.boolean().optional()
|
|
437
588
|
},
|
|
438
589
|
annotations: DESTRUCTIVE
|
|
439
|
-
},
|
|
440
|
-
|
|
441
|
-
|
|
590
|
+
}, ({ codeId, confirm }, extra) => attempt(async () => {
|
|
591
|
+
const id = toId(codeId);
|
|
592
|
+
if (!await confirmGate(server, extra.requestId, `Delete team join code ${id}? Athletes can no longer use it to join.`, confirm)) return errorResult(NOT_CONFIRMED);
|
|
593
|
+
return apiCall(ctx, "DELETE", `/v5/teamCodes/${id}`);
|
|
594
|
+
}));
|
|
595
|
+
}
|
|
596
|
+
//#endregion
|
|
597
|
+
//#region ../core/src/tools/analytics.ts
|
|
598
|
+
const METRIC_KEYS = [
|
|
599
|
+
"readiness-team",
|
|
600
|
+
"readiness-athlete",
|
|
601
|
+
"lift-1rm-history",
|
|
602
|
+
"training-summary-athlete",
|
|
603
|
+
"training-summary-team",
|
|
604
|
+
"compliance-team",
|
|
605
|
+
"lift-progress-team",
|
|
606
|
+
"working-max-history"
|
|
607
|
+
];
|
|
608
|
+
const METRICS = {
|
|
609
|
+
"readiness-team": {
|
|
610
|
+
path: "/v5/analytics/readiness/teams",
|
|
611
|
+
scope: "team",
|
|
612
|
+
fields: ["date"]
|
|
613
|
+
},
|
|
614
|
+
"readiness-athlete": {
|
|
615
|
+
path: "/v5/analytics/readiness/users",
|
|
616
|
+
scope: "user",
|
|
617
|
+
fields: ["date"]
|
|
618
|
+
},
|
|
619
|
+
"lift-1rm-history": {
|
|
620
|
+
path: "/v5/analytics/lift-one-rep-max-history/users",
|
|
621
|
+
scope: "user",
|
|
622
|
+
fields: [
|
|
623
|
+
"date_start",
|
|
624
|
+
"date_end",
|
|
625
|
+
"exercise_id",
|
|
626
|
+
"use_metric"
|
|
627
|
+
]
|
|
628
|
+
},
|
|
629
|
+
"training-summary-athlete": {
|
|
630
|
+
path: "/v5/analytics/training-summary/users",
|
|
631
|
+
scope: "user",
|
|
632
|
+
fields: ["date_start", "date_end"]
|
|
633
|
+
},
|
|
634
|
+
"training-summary-team": {
|
|
635
|
+
path: "/v5/analytics/training-summary/teams",
|
|
636
|
+
scope: "team",
|
|
637
|
+
fields: ["date_start", "date_end"]
|
|
638
|
+
},
|
|
639
|
+
"compliance-team": {
|
|
640
|
+
path: "/v5/analytics/compliance",
|
|
641
|
+
scope: "team",
|
|
642
|
+
fields: ["date_start", "date_end"]
|
|
643
|
+
},
|
|
644
|
+
"lift-progress-team": {
|
|
645
|
+
path: "/v5/analytics/lift-progress/teams",
|
|
646
|
+
scope: "team",
|
|
647
|
+
fields: [
|
|
648
|
+
"exercise_id",
|
|
649
|
+
"date_start",
|
|
650
|
+
"date_end"
|
|
651
|
+
]
|
|
652
|
+
},
|
|
653
|
+
"working-max-history": {
|
|
654
|
+
path: "/v5/analytics/working-max-history/users",
|
|
655
|
+
scope: "user",
|
|
656
|
+
fields: ["date_start", "date_end"]
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
/** Analytics report pulls. Read-only despite the POST verb, so ungated. */
|
|
660
|
+
function registerAnalyticsTools(server, ctx) {
|
|
661
|
+
server.registerTool("analytics_query", {
|
|
662
|
+
title: "Pull an analytics report",
|
|
663
|
+
description: "Read a TrainHeroic analytics report. `metric` picks the report (run analytics_categories for the catalog). Team metrics need teamId; athlete metrics need userIds. Dates are YYYY-MM-DD: readiness takes a single `date`, history/summary metrics take dateStart/dateEnd. lift-1rm-history and lift-progress-team also take exerciseId.",
|
|
664
|
+
inputSchema: {
|
|
665
|
+
metric: z.enum(METRIC_KEYS),
|
|
666
|
+
teamId: idParam.optional(),
|
|
667
|
+
userIds: z.array(idParam).optional(),
|
|
668
|
+
exerciseId: idParam.optional(),
|
|
669
|
+
date: z.string().optional(),
|
|
670
|
+
dateStart: z.string().optional(),
|
|
671
|
+
dateEnd: z.string().optional(),
|
|
672
|
+
useMetric: z.boolean().optional()
|
|
673
|
+
},
|
|
674
|
+
annotations: READ
|
|
675
|
+
}, async ({ metric, teamId, userIds, exerciseId, date, dateStart, dateEnd, useMetric }) => {
|
|
676
|
+
const spec = METRICS[metric];
|
|
677
|
+
const body = {};
|
|
678
|
+
if (spec.scope === "team") {
|
|
679
|
+
if (teamId === void 0) return errorResult(`${metric} needs teamId.`);
|
|
680
|
+
body.teamId = toId(teamId);
|
|
681
|
+
} else {
|
|
682
|
+
if (userIds === void 0 || userIds.length === 0) return errorResult(`${metric} needs userIds (one or more athlete ids).`);
|
|
683
|
+
body.user_ids = userIds.map((u) => String(toId(u)));
|
|
442
684
|
}
|
|
443
|
-
const
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
685
|
+
const provided = {
|
|
686
|
+
date,
|
|
687
|
+
date_start: dateStart,
|
|
688
|
+
date_end: dateEnd,
|
|
689
|
+
exercise_id: exerciseId === void 0 ? void 0 : String(toId(exerciseId)),
|
|
690
|
+
use_metric: useMetric
|
|
691
|
+
};
|
|
692
|
+
for (const field of spec.fields) if (provided[field] !== void 0) body[field] = provided[field];
|
|
693
|
+
return apiCall(ctx, "POST", spec.path, { body }, "Narrow with a tighter date range or fewer athletes.");
|
|
447
694
|
});
|
|
448
695
|
}
|
|
449
696
|
//#endregion
|
|
@@ -457,7 +704,7 @@ function registerExerciseTools(server, ctx) {
|
|
|
457
704
|
const index = ctx.index;
|
|
458
705
|
server.registerTool("exercise_resolve", {
|
|
459
706
|
title: "Resolve exercise name",
|
|
460
|
-
description: "Map a name to an exercise id via the local mirror. Returns the match plus ranked candidates; when ambiguous, match is null and you should pick from candidates.
|
|
707
|
+
description: "Map a name to an exercise id via the local mirror. Returns the match plus ranked candidates; when ambiguous, match is null and you should pick from candidates. Each result's `units` array lists the fixed measurement units by entry slot; they are fixed per exercise — check them before prescribing.",
|
|
461
708
|
inputSchema: { name: z.string().min(1) },
|
|
462
709
|
annotations: READ
|
|
463
710
|
}, ({ name }) => attempt(async () => jsonResult(await index.resolve(name))));
|
|
@@ -682,12 +929,31 @@ function unitLabel(paramType) {
|
|
|
682
929
|
if (t === null) return null;
|
|
683
930
|
return PARAM_UNIT[t] ?? null;
|
|
684
931
|
}
|
|
685
|
-
/**
|
|
932
|
+
/**
|
|
933
|
+
* Fixed measurement units for an exercise, ordered by entry slot (param 1, then param 2).
|
|
934
|
+
* Positional, not semantic: some exercises reverse the slots, so the array is not labelled
|
|
935
|
+
* by role. A null entry is an unset slot.
|
|
936
|
+
*/
|
|
937
|
+
function exerciseUnits(param1, param2) {
|
|
938
|
+
return [unitLabel(param1), unitLabel(param2)];
|
|
939
|
+
}
|
|
940
|
+
/** Present a row for display: drop the raw param-type codes, surface units positionally. */
|
|
686
941
|
function withUnits(row) {
|
|
942
|
+
const { param_1_type, param_2_type, ...rest } = row;
|
|
687
943
|
return {
|
|
688
|
-
...
|
|
689
|
-
|
|
690
|
-
|
|
944
|
+
...rest,
|
|
945
|
+
units: exerciseUnits(param_1_type, param_2_type)
|
|
946
|
+
};
|
|
947
|
+
}
|
|
948
|
+
/**
|
|
949
|
+
* Present a full raw exercise object for display: drop the raw param-type codes and add the
|
|
950
|
+
* positional `units` array. Keeps every other field of the raw object intact.
|
|
951
|
+
*/
|
|
952
|
+
function presentExercise(raw) {
|
|
953
|
+
const { param_1_type, param_2_type, ...rest } = raw;
|
|
954
|
+
return {
|
|
955
|
+
...rest,
|
|
956
|
+
units: exerciseUnits(param_1_type, param_2_type)
|
|
691
957
|
};
|
|
692
958
|
}
|
|
693
959
|
function buildSearchText(title) {
|
|
@@ -1243,10 +1509,7 @@ var ExerciseLibrary = class {
|
|
|
1243
1509
|
await this.ensureFresh();
|
|
1244
1510
|
const s = this.#byId.get(id);
|
|
1245
1511
|
if (!s) return null;
|
|
1246
|
-
|
|
1247
|
-
full.param_1_unit = unitLabel(full.param_1_type);
|
|
1248
|
-
full.param_2_unit = unitLabel(full.param_2_type);
|
|
1249
|
-
return full;
|
|
1512
|
+
return presentExercise(s.raw);
|
|
1250
1513
|
}
|
|
1251
1514
|
async defaults(id) {
|
|
1252
1515
|
const s = this.#byId.get(id);
|
|
@@ -1327,8 +1590,8 @@ var ExerciseLibrary = class {
|
|
|
1327
1590
|
};
|
|
1328
1591
|
//#endregion
|
|
1329
1592
|
//#region ../core/src/tools/workout.ts
|
|
1330
|
-
/**
|
|
1331
|
-
function
|
|
1593
|
+
/** Build a draft, read it back, and publish it. */
|
|
1594
|
+
function registerBuild(server, ctx) {
|
|
1332
1595
|
server.registerTool("workout_build", {
|
|
1333
1596
|
title: "Build a workout session (draft)",
|
|
1334
1597
|
description: "Build an UNPUBLISHED session from a spec (program -> session -> blocks -> exercises). Two exercises in one block become a superset. 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.",
|
|
@@ -1401,6 +1664,9 @@ function registerWorkoutTools(server, ctx) {
|
|
|
1401
1664
|
readback: await readSession(ctx.client, programId, parseWorkoutDate(date), pwId)
|
|
1402
1665
|
});
|
|
1403
1666
|
}));
|
|
1667
|
+
}
|
|
1668
|
+
/** Calendar lifecycle for an existing session: remove, unpublish, copy, save to library. */
|
|
1669
|
+
function registerLifecycle(server, ctx) {
|
|
1404
1670
|
server.registerTool("session_remove", {
|
|
1405
1671
|
title: "Remove a session",
|
|
1406
1672
|
description: "Delete a session from the live calendar (also the way to replace a date: remove then build). Hard to undo. Requires confirmation (elicitation, or confirm:true).",
|
|
@@ -1419,6 +1685,66 @@ function registerWorkoutTools(server, ctx) {
|
|
|
1419
1685
|
await removeSession(ctx.client, programId, pwId);
|
|
1420
1686
|
return jsonResult({ removed: pwId });
|
|
1421
1687
|
}));
|
|
1688
|
+
server.registerTool("session_unpublish", {
|
|
1689
|
+
title: "Unpublish a session",
|
|
1690
|
+
description: "Unpublish a previously published session (POST .../programWorkout/unPublish/{pwId}). It is no longer athlete-facing. Requires confirmation (elicitation, or confirm:true).",
|
|
1691
|
+
inputSchema: {
|
|
1692
|
+
pwId: z.number(),
|
|
1693
|
+
confirm: z.boolean().optional()
|
|
1694
|
+
},
|
|
1695
|
+
annotations: {
|
|
1696
|
+
readOnlyHint: false,
|
|
1697
|
+
destructiveHint: true,
|
|
1698
|
+
openWorldHint: true
|
|
1699
|
+
}
|
|
1700
|
+
}, ({ pwId, confirm }, extra) => attempt(async () => {
|
|
1701
|
+
if (!await confirmGate(server, extra.requestId, `Unpublish session ${pwId}? Athletes will no longer see it.`, confirm)) return errorResult(NOT_CONFIRMED);
|
|
1702
|
+
return apiCall(ctx, "POST", `/2.0/coach/calendar/programWorkout/unPublish/${pwId}`);
|
|
1703
|
+
}));
|
|
1704
|
+
server.registerTool("session_copy", {
|
|
1705
|
+
title: "Copy a session to a date",
|
|
1706
|
+
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.",
|
|
1707
|
+
inputSchema: {
|
|
1708
|
+
toProgramId: z.number(),
|
|
1709
|
+
pwId: z.number(),
|
|
1710
|
+
toDate: z.string()
|
|
1711
|
+
},
|
|
1712
|
+
annotations: {
|
|
1713
|
+
readOnlyHint: false,
|
|
1714
|
+
destructiveHint: false,
|
|
1715
|
+
openWorldHint: true
|
|
1716
|
+
}
|
|
1717
|
+
}, ({ toProgramId, pwId, toDate }) => attempt(async () => {
|
|
1718
|
+
const [year, month, day] = parseWorkoutDate(toDate);
|
|
1719
|
+
const dayOfWeek = new Date(Date.UTC(year, month - 1, day)).getUTCDay();
|
|
1720
|
+
return apiCall(ctx, "POST", "/2.0/coach/calendar/copyProgramWorkout", { body: {
|
|
1721
|
+
toProgramId,
|
|
1722
|
+
pwId,
|
|
1723
|
+
toDate: {
|
|
1724
|
+
date: `${year}-${String(month).padStart(2, "0")}-${String(day).padStart(2, "0")}`,
|
|
1725
|
+
day,
|
|
1726
|
+
month,
|
|
1727
|
+
year,
|
|
1728
|
+
dayOfWeek,
|
|
1729
|
+
isToday: false
|
|
1730
|
+
}
|
|
1731
|
+
} });
|
|
1732
|
+
}));
|
|
1733
|
+
server.registerTool("session_save_as_template", {
|
|
1734
|
+
title: "Save a session to the library",
|
|
1735
|
+
description: "Save an existing session as a reusable template in the session library (POST .../programWorkout/saveWorkoutAsTemplate/{workoutId}). Pass the workout_id.",
|
|
1736
|
+
inputSchema: { workoutId: z.number() },
|
|
1737
|
+
annotations: {
|
|
1738
|
+
readOnlyHint: false,
|
|
1739
|
+
destructiveHint: false,
|
|
1740
|
+
openWorldHint: true
|
|
1741
|
+
}
|
|
1742
|
+
}, ({ workoutId }) => apiCall(ctx, "POST", `/2.0/coach/calendar/programWorkout/saveWorkoutAsTemplate/${workoutId}`));
|
|
1743
|
+
}
|
|
1744
|
+
/** Workout building, read-back, publishing, and the session calendar lifecycle. */
|
|
1745
|
+
function registerWorkoutTools(server, ctx) {
|
|
1746
|
+
registerBuild(server, ctx);
|
|
1747
|
+
registerLifecycle(server, ctx);
|
|
1422
1748
|
}
|
|
1423
1749
|
//#endregion
|
|
1424
1750
|
//#region ../core/src/tools/messaging.ts
|
|
@@ -1540,10 +1866,12 @@ async function main() {
|
|
|
1540
1866
|
};
|
|
1541
1867
|
const server = new McpServer({
|
|
1542
1868
|
name: "trainheroic-local",
|
|
1543
|
-
version: "0.
|
|
1869
|
+
version: "0.2.0"
|
|
1544
1870
|
});
|
|
1545
1871
|
registerReadTools(server, ctx);
|
|
1546
|
-
|
|
1872
|
+
registerAthleteTools(server, ctx);
|
|
1873
|
+
registerTeamTools(server, ctx);
|
|
1874
|
+
registerAnalyticsTools(server, ctx);
|
|
1547
1875
|
registerExerciseTools(server, ctx);
|
|
1548
1876
|
registerWorkoutTools(server, ctx);
|
|
1549
1877
|
registerMessagingTools(server, ctx);
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trainheroic-unofficial/coach-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "https://github.com/alandotcom/trainheroic-
|
|
7
|
+
"url": "https://github.com/alandotcom/trainheroic-unofficial.git",
|
|
8
8
|
"directory": "packages/coach-mcp"
|
|
9
9
|
},
|
|
10
10
|
"description": "Local single-user MCP server for a TrainHeroic coach. No database, no Cloudflare deps.",
|
|
@@ -21,11 +21,10 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
23
23
|
"zod": "^4.4.3",
|
|
24
|
-
"@trainheroic-unofficial/core": "0.
|
|
25
|
-
"@trainheroic-unofficial/js": "0.
|
|
24
|
+
"@trainheroic-unofficial/core": "0.3.0",
|
|
25
|
+
"@trainheroic-unofficial/js": "0.3.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@anthropic-ai/mcpb": "^2.1.2",
|
|
29
28
|
"@types/node": "^26.0.0",
|
|
30
29
|
"tsdown": "^0.22.3",
|
|
31
30
|
"tsx": "^4.22.4",
|
|
@@ -36,9 +35,6 @@
|
|
|
36
35
|
"start": "tsx src/server.ts",
|
|
37
36
|
"inspect": "npx @modelcontextprotocol/inspector -e TRAINHEROIC_EMAIL=\"$TRAINHEROIC_EMAIL\" -e TRAINHEROIC_PASSWORD=\"$TRAINHEROIC_PASSWORD\" tsx src/server.ts",
|
|
38
37
|
"build": "tsdown",
|
|
39
|
-
"build:mcpb": "tsdown --config tsdown.mcpb.config.ts && mcpb pack ./mcpb ./dist/trainheroic-coach-mcp.mcpb",
|
|
40
|
-
"mcpb:validate": "mcpb validate ./mcpb/manifest.json",
|
|
41
|
-
"mcpb:sign": "mcpb sign --self-signed ./dist/trainheroic-coach-mcp.mcpb",
|
|
42
38
|
"typecheck": "tsc --noEmit",
|
|
43
39
|
"test": "vitest run --passWithNoTests"
|
|
44
40
|
}
|