@trainheroic-unofficial/coach-mcp 3.5.2 → 3.6.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 +191 -16
- package/package.json +3 -3
package/dist/server.mjs
CHANGED
|
@@ -1033,30 +1033,200 @@ function confirmGate(ctx, message, confirmArg) {
|
|
|
1033
1033
|
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.";
|
|
1034
1034
|
//#endregion
|
|
1035
1035
|
//#region ../js/src/http-error.ts
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1036
|
+
const MAX_REQUEST_KEYS = 50;
|
|
1037
|
+
const MAX_RESPONSE_DEPTH = 4;
|
|
1038
|
+
const MAX_RESPONSE_KEYS = 20;
|
|
1039
|
+
const MAX_RESPONSE_ITEMS = 10;
|
|
1040
|
+
const MAX_RESPONSE_NODES = 50;
|
|
1041
|
+
const RESPONSE_DIAGNOSTIC_KEYS = /* @__PURE__ */ new Set([
|
|
1042
|
+
"code",
|
|
1043
|
+
"detail",
|
|
1044
|
+
"details",
|
|
1045
|
+
"error",
|
|
1046
|
+
"error_code",
|
|
1047
|
+
"errors",
|
|
1048
|
+
"message",
|
|
1049
|
+
"reason",
|
|
1050
|
+
"status",
|
|
1051
|
+
"status_code",
|
|
1052
|
+
"success"
|
|
1053
|
+
]);
|
|
1054
|
+
const RESPONSE_CONTAINER_KEYS = /* @__PURE__ */ new Set([
|
|
1055
|
+
"data",
|
|
1056
|
+
"received",
|
|
1057
|
+
"response",
|
|
1058
|
+
"result"
|
|
1059
|
+
]);
|
|
1060
|
+
const RESPONSE_STATUS_KEYS = /* @__PURE__ */ new Set(["status", "status_code"]);
|
|
1061
|
+
const RESPONSE_BOOLEAN_KEYS = /* @__PURE__ */ new Set(["success"]);
|
|
1062
|
+
const PARAMETER_TYPES = /* @__PURE__ */ new Set([
|
|
1063
|
+
0,
|
|
1064
|
+
1,
|
|
1065
|
+
2,
|
|
1066
|
+
3,
|
|
1067
|
+
4,
|
|
1068
|
+
5,
|
|
1069
|
+
6,
|
|
1070
|
+
7,
|
|
1071
|
+
10,
|
|
1072
|
+
11,
|
|
1073
|
+
12,
|
|
1074
|
+
13,
|
|
1075
|
+
14,
|
|
1076
|
+
18
|
|
1077
|
+
]);
|
|
1078
|
+
function safeFieldName(key) {
|
|
1079
|
+
if (key === "__proto__" || key === "constructor" || key === "prototype") return "[Redacted key]";
|
|
1080
|
+
if (!/^[A-Za-z_][A-Za-z0-9_.-]{0,79}$/.test(key)) return "[Redacted key]";
|
|
1081
|
+
return key;
|
|
1082
|
+
}
|
|
1083
|
+
function boundedEntries(object, limit) {
|
|
1084
|
+
const entries = [];
|
|
1085
|
+
for (const key of Object.keys(object)) {
|
|
1086
|
+
const descriptor = Object.getOwnPropertyDescriptor(object, key);
|
|
1087
|
+
entries.push([key, descriptor && "value" in descriptor ? descriptor.value : void 0]);
|
|
1088
|
+
if (entries.length >= limit) break;
|
|
1089
|
+
}
|
|
1090
|
+
return entries;
|
|
1091
|
+
}
|
|
1092
|
+
function safeRequestValue(key, value) {
|
|
1093
|
+
if (key === "is_circuit" && typeof value === "boolean") return value;
|
|
1094
|
+
if (["param_1_type", "param_2_type"].includes(key) && typeof value === "number" && PARAMETER_TYPES.has(value)) return value;
|
|
1095
|
+
}
|
|
1096
|
+
function requestBodySummary(body) {
|
|
1097
|
+
if (Array.isArray(body)) return {
|
|
1098
|
+
type: "array",
|
|
1099
|
+
length: body.length
|
|
1100
|
+
};
|
|
1101
|
+
if (body && typeof body === "object") {
|
|
1102
|
+
const entries = boundedEntries(body, MAX_REQUEST_KEYS).sort(([left], [right]) => left.localeCompare(right));
|
|
1103
|
+
const keys = entries.map(([key]) => safeFieldName(key));
|
|
1104
|
+
const values = {};
|
|
1105
|
+
for (const [key, value] of entries) {
|
|
1106
|
+
const safeValue = safeRequestValue(key, value);
|
|
1107
|
+
if (safeValue !== void 0) values[safeFieldName(key)] = safeValue;
|
|
1108
|
+
}
|
|
1109
|
+
return Object.keys(values).length > 0 ? {
|
|
1110
|
+
type: "object",
|
|
1111
|
+
keys,
|
|
1112
|
+
values
|
|
1113
|
+
} : {
|
|
1114
|
+
type: "object",
|
|
1115
|
+
keys
|
|
1116
|
+
};
|
|
1117
|
+
}
|
|
1118
|
+
const primitive = typeof body;
|
|
1119
|
+
return primitive === "boolean" || primitive === "number" || primitive === "string" ? { type: primitive } : { type: "other" };
|
|
1120
|
+
}
|
|
1121
|
+
function sanitizedDiagnosticValue(value, depth, budget, field) {
|
|
1122
|
+
if (budget.nodes <= 0) return "[Truncated]";
|
|
1123
|
+
budget.nodes -= 1;
|
|
1124
|
+
if (value === null) return null;
|
|
1125
|
+
if (typeof value === "boolean") return field && RESPONSE_BOOLEAN_KEYS.has(field) ? value : "[Redacted]";
|
|
1126
|
+
if (typeof value === "number") return field && RESPONSE_STATUS_KEYS.has(field) && Number.isInteger(value) && value >= 100 && value <= 599 ? value : "[Redacted]";
|
|
1127
|
+
if (typeof value === "string") return "[Redacted]";
|
|
1128
|
+
if (depth >= MAX_RESPONSE_DEPTH) return "[Truncated]";
|
|
1129
|
+
if (Array.isArray(value)) {
|
|
1130
|
+
const result = [];
|
|
1131
|
+
for (const item of value.slice(0, MAX_RESPONSE_ITEMS)) {
|
|
1132
|
+
if (budget.nodes <= 0) {
|
|
1133
|
+
result.push("[Truncated]");
|
|
1134
|
+
break;
|
|
1135
|
+
}
|
|
1136
|
+
result.push(sanitizedDiagnosticValue(item, depth + 1, budget));
|
|
1137
|
+
}
|
|
1138
|
+
return result;
|
|
1139
|
+
}
|
|
1140
|
+
if (value && typeof value === "object") {
|
|
1141
|
+
const result = {};
|
|
1142
|
+
for (const [key, item] of boundedEntries(value, MAX_RESPONSE_KEYS)) {
|
|
1143
|
+
if (budget.nodes <= 0) {
|
|
1144
|
+
result.truncated = "[Truncated]";
|
|
1145
|
+
break;
|
|
1146
|
+
}
|
|
1147
|
+
const safeKey = safeFieldName(key);
|
|
1148
|
+
const safeValue = safeRequestValue(key, item);
|
|
1149
|
+
if (RESPONSE_DIAGNOSTIC_KEYS.has(key)) result[safeKey] = sanitizedDiagnosticValue(item, depth + 1, budget, key);
|
|
1150
|
+
else if (RESPONSE_CONTAINER_KEYS.has(key) && item && typeof item === "object") result[safeKey] = sanitizedDiagnosticValue(item, depth + 1, budget);
|
|
1151
|
+
else if (safeValue !== void 0) {
|
|
1152
|
+
budget.nodes -= 1;
|
|
1153
|
+
result[safeKey] = safeValue;
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
return result;
|
|
1157
|
+
}
|
|
1158
|
+
return `[${typeof value}]`;
|
|
1159
|
+
}
|
|
1160
|
+
function responseBodyDiagnostics(body, budget, depth = 0) {
|
|
1161
|
+
const activeBudget = budget ?? { nodes: MAX_RESPONSE_NODES };
|
|
1162
|
+
if (activeBudget.nodes <= 0 || depth >= MAX_RESPONSE_DEPTH) return "[Truncated]";
|
|
1163
|
+
if (!body || typeof body !== "object" || Array.isArray(body)) return sanitizedDiagnosticValue(body, depth, activeBudget);
|
|
1164
|
+
const object = body;
|
|
1165
|
+
const result = {};
|
|
1166
|
+
for (const [key, value] of boundedEntries(object, MAX_RESPONSE_KEYS)) {
|
|
1167
|
+
if (activeBudget.nodes <= 0) {
|
|
1168
|
+
result.truncated = "[Truncated]";
|
|
1169
|
+
break;
|
|
1170
|
+
}
|
|
1171
|
+
if (RESPONSE_DIAGNOSTIC_KEYS.has(key)) {
|
|
1172
|
+
result[safeFieldName(key)] = sanitizedDiagnosticValue(value, depth + 1, activeBudget, key);
|
|
1173
|
+
continue;
|
|
1174
|
+
}
|
|
1175
|
+
if (RESPONSE_CONTAINER_KEYS.has(key) && value && typeof value === "object") {
|
|
1176
|
+
activeBudget.nodes -= 1;
|
|
1177
|
+
const nested = responseBodyDiagnostics(value, activeBudget, depth + 1);
|
|
1178
|
+
if (nested === "[Truncated]" || nested && typeof nested === "object" && Object.keys(nested).length > 0) result[safeFieldName(key)] = nested;
|
|
1179
|
+
}
|
|
1180
|
+
}
|
|
1181
|
+
if (Object.keys(result).length > 0) return result;
|
|
1182
|
+
return { type: "object" };
|
|
1183
|
+
}
|
|
1184
|
+
function parseResponseText(text) {
|
|
1185
|
+
if (text.length === 0) return text;
|
|
1186
|
+
try {
|
|
1187
|
+
return JSON.parse(text);
|
|
1188
|
+
} catch {
|
|
1189
|
+
return text;
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
function safeRequestBodySummary(body) {
|
|
1193
|
+
try {
|
|
1194
|
+
return requestBodySummary(body);
|
|
1195
|
+
} catch {
|
|
1196
|
+
return { type: "other" };
|
|
1197
|
+
}
|
|
1198
|
+
}
|
|
1199
|
+
function safeResponseBodyDiagnostics(body) {
|
|
1200
|
+
try {
|
|
1201
|
+
return responseBodyDiagnostics(body);
|
|
1202
|
+
} catch {
|
|
1203
|
+
return "[Unavailable]";
|
|
1204
|
+
}
|
|
1205
|
+
}
|
|
1206
|
+
/** A final non-2xx response plus bounded, telemetry-safe request and response diagnostics. */
|
|
1041
1207
|
var TrainHeroicHttpError = class extends Error {
|
|
1042
1208
|
name = "TrainHeroicHttpError";
|
|
1043
1209
|
method;
|
|
1044
1210
|
status;
|
|
1045
1211
|
host;
|
|
1046
|
-
|
|
1212
|
+
requestBody;
|
|
1213
|
+
responseBody;
|
|
1214
|
+
constructor(method, url, status, diagnostics = {}) {
|
|
1047
1215
|
const parsed = new URL(url);
|
|
1048
1216
|
const normalizedMethod = method.toUpperCase();
|
|
1049
1217
|
super(`TrainHeroic ${normalizedMethod} request failed with HTTP ${status}`);
|
|
1050
1218
|
this.method = normalizedMethod;
|
|
1051
1219
|
this.status = status;
|
|
1052
1220
|
this.host = parsed.host;
|
|
1221
|
+
this.requestBody = diagnostics.requestBody === void 0 ? void 0 : safeRequestBodySummary(diagnostics.requestBody);
|
|
1222
|
+
this.responseBody = diagnostics.responseBody === void 0 ? void 0 : safeResponseBodyDiagnostics(diagnostics.responseBody);
|
|
1053
1223
|
}
|
|
1054
1224
|
};
|
|
1055
1225
|
/** Call observability hooks without allowing them to change SDK behavior. */
|
|
1056
|
-
function notifyHttpError(handler, method, url, status) {
|
|
1226
|
+
function notifyHttpError(handler, method, url, status, diagnostics = {}) {
|
|
1057
1227
|
if (!handler) return;
|
|
1058
1228
|
try {
|
|
1059
|
-
Promise.resolve(handler(new TrainHeroicHttpError(method, url, status))).catch(() => {});
|
|
1229
|
+
Promise.resolve(handler(new TrainHeroicHttpError(method, url, status, diagnostics))).catch(() => {});
|
|
1060
1230
|
} catch {}
|
|
1061
1231
|
}
|
|
1062
1232
|
//#endregion
|
|
@@ -1180,14 +1350,19 @@ var TrainHeroicClient = class {
|
|
|
1180
1350
|
session = await this.#ensureSession();
|
|
1181
1351
|
res = await this.#send(method, url, session, options.body);
|
|
1182
1352
|
}
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1353
|
+
const shouldReport = !res.ok && !options.expectedStatuses?.includes(res.status);
|
|
1354
|
+
let text;
|
|
1355
|
+
try {
|
|
1356
|
+
text = await res.text();
|
|
1357
|
+
} catch (error) {
|
|
1358
|
+
if (shouldReport) notifyHttpError(this.#onHttpError, method, url, res.status, { requestBody: options.body });
|
|
1359
|
+
throw error;
|
|
1190
1360
|
}
|
|
1361
|
+
const data = parseResponseText(text);
|
|
1362
|
+
if (shouldReport) notifyHttpError(this.#onHttpError, method, url, res.status, {
|
|
1363
|
+
requestBody: options.body,
|
|
1364
|
+
responseBody: data
|
|
1365
|
+
});
|
|
1191
1366
|
return {
|
|
1192
1367
|
status: res.status,
|
|
1193
1368
|
ok: res.ok,
|
|
@@ -4853,7 +5028,7 @@ var JsonFileLibraryCache = class {
|
|
|
4853
5028
|
};
|
|
4854
5029
|
//#endregion
|
|
4855
5030
|
//#region package.json
|
|
4856
|
-
var version = "3.
|
|
5031
|
+
var version = "3.6.0";
|
|
4857
5032
|
//#endregion
|
|
4858
5033
|
//#region src/server.ts
|
|
4859
5034
|
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.6.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/
|
|
25
|
-
"@trainheroic-unofficial/
|
|
24
|
+
"@trainheroic-unofficial/core": "3.6.0",
|
|
25
|
+
"@trainheroic-unofficial/js": "3.6.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/node": "^26.3.0",
|