@hoststack.dev/mcp 0.2.1 → 0.4.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 +2 -1
- package/dist/hoststack-mcp.js +335 -31
- package/dist/hoststack-mcp.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +335 -31
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ declare class ApiClient {
|
|
|
20
20
|
private handle;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
type ToolCategory = 'projects' | 'services' | 'deploys' | 'databases' | 'domains' | 'env-vars' | 'cron' | 'logs' | 'activity-log' | 'meta';
|
|
23
|
+
type ToolCategory = 'projects' | 'services' | 'deploys' | 'databases' | 'domains' | 'volumes' | 'env-vars' | 'environments' | 'cron' | 'logs' | 'activity-log' | 'meta';
|
|
24
24
|
interface ToolContext {
|
|
25
25
|
hoststack: HostStack;
|
|
26
26
|
api: ApiClient;
|
package/dist/index.js
CHANGED
|
@@ -324,6 +324,9 @@ function shapeUser(value) {
|
|
|
324
324
|
function shapeTeam(value) {
|
|
325
325
|
return isObject(value) ? dropNullsAndInternals(value) : {};
|
|
326
326
|
}
|
|
327
|
+
function shapeVolume(value) {
|
|
328
|
+
return isObject(value) ? dropNullsAndInternals(value) : {};
|
|
329
|
+
}
|
|
327
330
|
|
|
328
331
|
// src/resources/hoststack-resources.ts
|
|
329
332
|
defineResource({
|
|
@@ -993,6 +996,146 @@ defineTool({
|
|
|
993
996
|
}
|
|
994
997
|
});
|
|
995
998
|
|
|
999
|
+
// src/tools/environments.ts
|
|
1000
|
+
import { z as z8 } from "zod";
|
|
1001
|
+
defineTool({
|
|
1002
|
+
name: "list_environments",
|
|
1003
|
+
category: "environments",
|
|
1004
|
+
description: [
|
|
1005
|
+
"List every environment for a project (production / staging / development / preview).",
|
|
1006
|
+
"",
|
|
1007
|
+
"When to use: the user wants to see what envs exist before creating a service in one or promoting a deploy. Every project has at least Production.",
|
|
1008
|
+
"",
|
|
1009
|
+
"Inputs:",
|
|
1010
|
+
' - project_id: project publicId (e.g. "prj_abc123").',
|
|
1011
|
+
"",
|
|
1012
|
+
"Returns: { items: Environment[] } \u2014 id, publicId, name, type, isDefault, isProtected.",
|
|
1013
|
+
"",
|
|
1014
|
+
'Example: list_environments({ project_id: "prj_abc" }) \u2192 { items: [{ name: "Production", type: "production", isDefault: true }, { name: "Staging", type: "staging" }] }'
|
|
1015
|
+
].join("\n"),
|
|
1016
|
+
input: {
|
|
1017
|
+
project_id: z8.string().describe("Project publicId.")
|
|
1018
|
+
},
|
|
1019
|
+
handler: async (args, ctx) => {
|
|
1020
|
+
const teamId = await ctx.resolveTeamId();
|
|
1021
|
+
const response = await ctx.hoststack.environments.list(teamId, args.project_id);
|
|
1022
|
+
const data = shapeList(response, "environments", shape);
|
|
1023
|
+
const summary = data.items.length === 0 ? "No environments yet \u2014 every project should have Production by default." : `Found ${data.items.length} environment${data.items.length === 1 ? "" : "s"}.`;
|
|
1024
|
+
return respond({ summary, data });
|
|
1025
|
+
}
|
|
1026
|
+
});
|
|
1027
|
+
defineTool({
|
|
1028
|
+
name: "create_environment",
|
|
1029
|
+
category: "environments",
|
|
1030
|
+
description: [
|
|
1031
|
+
"Create a new environment in a project (e.g. Staging, QA, Preview).",
|
|
1032
|
+
"",
|
|
1033
|
+
"When to use: the user wants to add an env so they can run a sibling service alongside production for testing or staging before release.",
|
|
1034
|
+
"",
|
|
1035
|
+
"Inputs:",
|
|
1036
|
+
" - project_id: project publicId.",
|
|
1037
|
+
" - name: human-readable name (1\u201364 chars). Shown in the env switcher.",
|
|
1038
|
+
' - type: "production" | "staging" | "development" | "preview". Determines the hostname suffix on services in this env (production stays clean; others get -staging / -dev / -preview).',
|
|
1039
|
+
" - is_protected (optional): require admin role for destructive actions in this env. Default false.",
|
|
1040
|
+
"",
|
|
1041
|
+
"Returns: { environment: Environment }.",
|
|
1042
|
+
"",
|
|
1043
|
+
'Example: create_environment({ project_id: "prj_abc", name: "Staging", type: "staging" }) \u2192 { environment: { id: 7, publicId: "environment_\u2026", name: "Staging", type: "staging" } }'
|
|
1044
|
+
].join("\n"),
|
|
1045
|
+
input: {
|
|
1046
|
+
project_id: z8.string().describe("Project publicId."),
|
|
1047
|
+
name: z8.string().min(1).max(64).describe("Environment name (1\u201364 chars)."),
|
|
1048
|
+
type: z8.enum(["production", "staging", "development", "preview"]).describe("Environment type \u2014 drives the hostname suffix."),
|
|
1049
|
+
is_protected: z8.boolean().optional().describe("Require admin role for destructive actions. Default false.")
|
|
1050
|
+
},
|
|
1051
|
+
handler: async (args, ctx) => {
|
|
1052
|
+
const teamId = await ctx.resolveTeamId();
|
|
1053
|
+
const input = {
|
|
1054
|
+
name: args.name,
|
|
1055
|
+
type: args.type
|
|
1056
|
+
};
|
|
1057
|
+
if (args.is_protected !== void 0) input.isProtected = args.is_protected;
|
|
1058
|
+
const response = await ctx.hoststack.environments.create(teamId, args.project_id, input);
|
|
1059
|
+
const data = { environment: shape(response.environment) };
|
|
1060
|
+
return respond({
|
|
1061
|
+
summary: `Created environment "${args.name}" (${args.type}) in project ${args.project_id}.`,
|
|
1062
|
+
data
|
|
1063
|
+
});
|
|
1064
|
+
}
|
|
1065
|
+
});
|
|
1066
|
+
defineTool({
|
|
1067
|
+
name: "delete_environment",
|
|
1068
|
+
category: "environments",
|
|
1069
|
+
description: [
|
|
1070
|
+
"Delete an environment from a project.",
|
|
1071
|
+
"",
|
|
1072
|
+
"When to use: an env is no longer used (e.g. tearing down a feature branch staging). Blocked when the env still has live services or databases attached \u2014 destroy or move them first. The default env (usually Production) cannot be deleted.",
|
|
1073
|
+
"",
|
|
1074
|
+
"Inputs:",
|
|
1075
|
+
" - project_id: project publicId.",
|
|
1076
|
+
" - environment_id: environment publicId or numeric id.",
|
|
1077
|
+
"",
|
|
1078
|
+
"Returns: { success: true } on success.",
|
|
1079
|
+
"",
|
|
1080
|
+
'Example: delete_environment({ project_id: "prj_abc", environment_id: "environment_xyz" }) \u2192 { success: true }'
|
|
1081
|
+
].join("\n"),
|
|
1082
|
+
input: {
|
|
1083
|
+
project_id: z8.string().describe("Project publicId."),
|
|
1084
|
+
environment_id: z8.union([z8.string(), z8.number()]).describe("Environment publicId or numeric id.")
|
|
1085
|
+
},
|
|
1086
|
+
handler: async (args, ctx) => {
|
|
1087
|
+
const teamId = await ctx.resolveTeamId();
|
|
1088
|
+
await ctx.hoststack.environments.delete(teamId, args.project_id, args.environment_id);
|
|
1089
|
+
return respond({
|
|
1090
|
+
summary: `Deleted environment ${String(args.environment_id)} from project ${args.project_id}.`,
|
|
1091
|
+
data: { success: true }
|
|
1092
|
+
});
|
|
1093
|
+
}
|
|
1094
|
+
});
|
|
1095
|
+
defineTool({
|
|
1096
|
+
name: "promote_deploy",
|
|
1097
|
+
category: "environments",
|
|
1098
|
+
description: [
|
|
1099
|
+
"Promote a built deploy from one environment to another (build-once, run-many).",
|
|
1100
|
+
"",
|
|
1101
|
+
"When to use: the user has tested a deploy in staging and wants to ship that exact image to production without rebuilding. Atomic and image-based \u2014 same docker image runs on the sibling service in the target env.",
|
|
1102
|
+
"",
|
|
1103
|
+
"Inputs:",
|
|
1104
|
+
" - service_id: source service publicId (the one that owns the deploy).",
|
|
1105
|
+
" - deploy_id: source deploy publicId. Must have `dockerImageId` set (i.e. a successful build).",
|
|
1106
|
+
" - target_environment_id: env publicId or numeric id to promote into. Must be in the same project. Cannot be the source service's own env.",
|
|
1107
|
+
"",
|
|
1108
|
+
"Behaviour: if a sibling service with the same name already exists in the target env, the new deploy lands on it. Otherwise the API auto-clones the source service's build/runtime config into the target env first. Env-specific config (env vars, secret files, volumes, IP allowlists, custom domains) is NOT copied \u2014 those are per-env by design.",
|
|
1109
|
+
"",
|
|
1110
|
+
"Returns: { deploy: Deploy } \u2014 the new deploy on the target service.",
|
|
1111
|
+
"",
|
|
1112
|
+
'Example: promote_deploy({ service_id: "svc_staging", deploy_id: "dpl_built", target_environment_id: "environment_prod" }) \u2192 { deploy: { id: 99, status: "pending", trigger: "rollback", dockerImageId: "sha256:\u2026" } }'
|
|
1113
|
+
].join("\n"),
|
|
1114
|
+
input: {
|
|
1115
|
+
service_id: z8.string().describe("Source service publicId."),
|
|
1116
|
+
deploy_id: z8.string().describe("Source deploy publicId (must have a built image)."),
|
|
1117
|
+
target_environment_id: z8.union([z8.string(), z8.number()]).describe("Target environment publicId or numeric id.")
|
|
1118
|
+
},
|
|
1119
|
+
handler: async (args, ctx) => {
|
|
1120
|
+
const teamId = await ctx.resolveTeamId();
|
|
1121
|
+
const targetEnvId = await ctx.hoststack.resolveId(args.target_environment_id, {
|
|
1122
|
+
kind: "environment",
|
|
1123
|
+
teamId: await ctx.hoststack.resolveId(teamId, { kind: "team" })
|
|
1124
|
+
});
|
|
1125
|
+
const response = await ctx.hoststack.deploys.promote(
|
|
1126
|
+
teamId,
|
|
1127
|
+
args.service_id,
|
|
1128
|
+
args.deploy_id,
|
|
1129
|
+
targetEnvId
|
|
1130
|
+
);
|
|
1131
|
+
const data = { deploy: shape(response.deploy) };
|
|
1132
|
+
return respond({
|
|
1133
|
+
summary: `Promoted deploy ${args.deploy_id} from service ${args.service_id} to env ${String(args.target_environment_id)}.`,
|
|
1134
|
+
data
|
|
1135
|
+
});
|
|
1136
|
+
}
|
|
1137
|
+
});
|
|
1138
|
+
|
|
996
1139
|
// src/tools/meta.ts
|
|
997
1140
|
defineTool({
|
|
998
1141
|
name: "get_me",
|
|
@@ -1020,7 +1163,7 @@ defineTool({
|
|
|
1020
1163
|
});
|
|
1021
1164
|
|
|
1022
1165
|
// src/tools/projects.ts
|
|
1023
|
-
import { z as
|
|
1166
|
+
import { z as z9 } from "zod";
|
|
1024
1167
|
defineTool({
|
|
1025
1168
|
name: "list_projects",
|
|
1026
1169
|
category: "projects",
|
|
@@ -1060,9 +1203,9 @@ defineTool({
|
|
|
1060
1203
|
'Example: create_project({ name: "billing-api", description: "Stripe webhooks", region: "fsn1" }) \u2192 { project: { id: 12, publicId: "prj_\u2026", \u2026 } }'
|
|
1061
1204
|
].join("\n"),
|
|
1062
1205
|
input: {
|
|
1063
|
-
name:
|
|
1064
|
-
description:
|
|
1065
|
-
region:
|
|
1206
|
+
name: z9.string().min(1).max(60).describe("Project name (1\u201360 chars)."),
|
|
1207
|
+
description: z9.string().max(500).optional().describe("Short description (\u2264500 chars)."),
|
|
1208
|
+
region: z9.enum(["fsn1", "nbg1", "hel1"]).optional().describe("Hetzner region: fsn1 | nbg1 | hel1.")
|
|
1066
1209
|
},
|
|
1067
1210
|
handler: async (args, ctx) => {
|
|
1068
1211
|
const teamId = await ctx.resolveTeamId();
|
|
@@ -1093,9 +1236,9 @@ defineTool({
|
|
|
1093
1236
|
'Example: update_project({ project_id: "prj_abc", name: "billing-prod" }) \u2192 { project: { name: "billing-prod", \u2026 } }'
|
|
1094
1237
|
].join("\n"),
|
|
1095
1238
|
input: {
|
|
1096
|
-
project_id:
|
|
1097
|
-
name:
|
|
1098
|
-
description:
|
|
1239
|
+
project_id: z9.string().describe("Project publicId."),
|
|
1240
|
+
name: z9.string().min(1).max(60).optional().describe("New name (1\u201360 chars)."),
|
|
1241
|
+
description: z9.string().max(500).optional().describe("New description (\u2264500 chars).")
|
|
1099
1242
|
},
|
|
1100
1243
|
handler: async (args, ctx) => {
|
|
1101
1244
|
if (args.name === void 0 && args.description === void 0) {
|
|
@@ -1129,7 +1272,7 @@ defineTool({
|
|
|
1129
1272
|
'Example: get_project({ project_id: "prj_abc" }) \u2192 { project: { id: 12, name: "billing", \u2026 } }'
|
|
1130
1273
|
].join("\n"),
|
|
1131
1274
|
input: {
|
|
1132
|
-
project_id:
|
|
1275
|
+
project_id: z9.string().describe("Project publicId (e.g. prj_abc123).")
|
|
1133
1276
|
},
|
|
1134
1277
|
handler: async (args, ctx) => {
|
|
1135
1278
|
const teamId = await ctx.resolveTeamId();
|
|
@@ -1141,7 +1284,7 @@ defineTool({
|
|
|
1141
1284
|
});
|
|
1142
1285
|
|
|
1143
1286
|
// src/tools/services.ts
|
|
1144
|
-
import { z as
|
|
1287
|
+
import { z as z10 } from "zod";
|
|
1145
1288
|
defineTool({
|
|
1146
1289
|
name: "list_services",
|
|
1147
1290
|
category: "services",
|
|
@@ -1179,7 +1322,7 @@ defineTool({
|
|
|
1179
1322
|
'Example: get_service({ service_id: "svc_abc" }) \u2192 { service: { type: "web", status: "running", \u2026 } }'
|
|
1180
1323
|
].join("\n"),
|
|
1181
1324
|
input: {
|
|
1182
|
-
service_id:
|
|
1325
|
+
service_id: z10.string().describe("Service publicId (e.g. svc_abc123).")
|
|
1183
1326
|
},
|
|
1184
1327
|
handler: async (args, ctx) => {
|
|
1185
1328
|
const teamId = await ctx.resolveTeamId();
|
|
@@ -1205,7 +1348,7 @@ defineTool({
|
|
|
1205
1348
|
'Example: get_service_metrics({ service_id: "svc_abc" }) \u2192 { metrics: { cpu: 0.42, memory: 0.71, \u2026 } }'
|
|
1206
1349
|
].join("\n"),
|
|
1207
1350
|
input: {
|
|
1208
|
-
service_id:
|
|
1351
|
+
service_id: z10.string().describe("Service publicId.")
|
|
1209
1352
|
},
|
|
1210
1353
|
handler: async (args, ctx) => {
|
|
1211
1354
|
const teamId = await ctx.resolveTeamId();
|
|
@@ -1231,8 +1374,8 @@ defineTool({
|
|
|
1231
1374
|
'Example: update_service({ service_id: "svc_abc", name: "api-prod" }) \u2192 { service: { name: "api-prod", \u2026 } }'
|
|
1232
1375
|
].join("\n"),
|
|
1233
1376
|
input: {
|
|
1234
|
-
service_id:
|
|
1235
|
-
name:
|
|
1377
|
+
service_id: z10.string().describe("Service publicId."),
|
|
1378
|
+
name: z10.string().min(1).max(60).describe("New service name (1\u201360 chars).")
|
|
1236
1379
|
},
|
|
1237
1380
|
handler: async (args, ctx) => {
|
|
1238
1381
|
const teamId = await ctx.resolveTeamId();
|
|
@@ -1265,15 +1408,15 @@ defineTool({
|
|
|
1265
1408
|
'Example: update_service_config({ service_id: "svc_abc", start_command: "bun apps/api/src/index.ts" }) \u2192 { service: { startCommand: "bun apps/api/src/index.ts", \u2026 } }'
|
|
1266
1409
|
].join("\n"),
|
|
1267
1410
|
input: {
|
|
1268
|
-
service_id:
|
|
1269
|
-
install_command:
|
|
1270
|
-
build_command:
|
|
1271
|
-
start_command:
|
|
1272
|
-
branch:
|
|
1273
|
-
root_directory:
|
|
1274
|
-
dockerfile_path:
|
|
1275
|
-
auto_deploy:
|
|
1276
|
-
instance_count:
|
|
1411
|
+
service_id: z10.string().describe("Service publicId."),
|
|
1412
|
+
install_command: z10.string().nullable().optional().describe("Install shell command. Null clears."),
|
|
1413
|
+
build_command: z10.string().nullable().optional().describe("Build shell command. Null clears."),
|
|
1414
|
+
start_command: z10.string().nullable().optional().describe("Start shell command. Null clears."),
|
|
1415
|
+
branch: z10.string().optional().describe("Git branch to track."),
|
|
1416
|
+
root_directory: z10.string().optional().describe("Build context root."),
|
|
1417
|
+
dockerfile_path: z10.string().nullable().optional().describe("Path to Dockerfile relative to root. Null clears."),
|
|
1418
|
+
auto_deploy: z10.boolean().optional().describe("Auto-deploy on push."),
|
|
1419
|
+
instance_count: z10.number().int().positive().max(50).optional().describe("Pin min and max instances to this value (1\u201350).")
|
|
1277
1420
|
},
|
|
1278
1421
|
handler: async (args, ctx) => {
|
|
1279
1422
|
const teamId = await ctx.resolveTeamId();
|
|
@@ -1338,7 +1481,7 @@ defineTool({
|
|
|
1338
1481
|
'Example: suspend_service({ service_id: "svc_dev" }) \u2192 { ok: true }'
|
|
1339
1482
|
].join("\n"),
|
|
1340
1483
|
input: {
|
|
1341
|
-
service_id:
|
|
1484
|
+
service_id: z10.string().describe("Service publicId.")
|
|
1342
1485
|
},
|
|
1343
1486
|
handler: async (args, ctx) => {
|
|
1344
1487
|
const teamId = await ctx.resolveTeamId();
|
|
@@ -1362,7 +1505,7 @@ defineTool({
|
|
|
1362
1505
|
'Example: resume_service({ service_id: "svc_dev" }) \u2192 { ok: true }'
|
|
1363
1506
|
].join("\n"),
|
|
1364
1507
|
input: {
|
|
1365
|
-
service_id:
|
|
1508
|
+
service_id: z10.string().describe("Service publicId.")
|
|
1366
1509
|
},
|
|
1367
1510
|
handler: async (args, ctx) => {
|
|
1368
1511
|
const teamId = await ctx.resolveTeamId();
|
|
@@ -1381,18 +1524,29 @@ defineTool({
|
|
|
1381
1524
|
"Inputs:",
|
|
1382
1525
|
" - service_id: publicId of the service.",
|
|
1383
1526
|
" - lines (optional): tail size (default 200, max 1000).",
|
|
1384
|
-
|
|
1527
|
+
' - since/until (optional): ISO-8601 timestamp OR a relative offset like "-5m", "-1h", "-2d".',
|
|
1385
1528
|
' - stream (optional): "stdout" | "stderr". Omit to combine.',
|
|
1529
|
+
" - level (optional): friendly synonym \u2014 info/debug \u2192 stdout, warn/error \u2192 stderr.",
|
|
1530
|
+
" - search (optional): case-insensitive substring grep, \u2264100 chars.",
|
|
1531
|
+
' - count_only (optional): when true, returns { count } only \u2014 much cheaper for "how many error lines in last 5m" polling.',
|
|
1532
|
+
"",
|
|
1533
|
+
"Returns: { logs: LogEntry[] | string } when count_only is false (each entry has { timestamp, level?, stream?, message }), or { count: number } when count_only is true.",
|
|
1386
1534
|
"",
|
|
1387
|
-
|
|
1535
|
+
'Example: get_service_logs({ service_id: "svc_abc", search: "OOM", since: "-15m" }) \u2192 { logs: [...] }.',
|
|
1388
1536
|
"",
|
|
1389
|
-
|
|
1537
|
+
"More examples:",
|
|
1538
|
+
' - Last 50 stderr lines from the past hour: get_service_logs({ service_id: "svc_abc", lines: 50, stream: "stderr", since: "-1h" })',
|
|
1539
|
+
' - Just count error lines without fetching them: get_service_logs({ service_id: "svc_abc", level: "error", since: "-5m", count_only: true }) \u2192 { count: 47 }'
|
|
1390
1540
|
].join("\n"),
|
|
1391
1541
|
input: {
|
|
1392
|
-
service_id:
|
|
1393
|
-
lines:
|
|
1394
|
-
since:
|
|
1395
|
-
|
|
1542
|
+
service_id: z10.string().describe("Service publicId."),
|
|
1543
|
+
lines: z10.number().int().positive().max(1e3).optional().describe("Tail size; default 200, hard cap 1000."),
|
|
1544
|
+
since: z10.string().optional().describe('ISO-8601 timestamp or relative offset (e.g. "-5m", "-1h").'),
|
|
1545
|
+
until: z10.string().optional().describe("ISO-8601 timestamp or relative offset upper bound."),
|
|
1546
|
+
stream: z10.enum(["stdout", "stderr"]).optional().describe("Restrict to one stream."),
|
|
1547
|
+
level: z10.enum(["stdout", "stderr", "info", "warn", "error", "debug"]).optional().describe("Friendly stream alias: info/debug\u2192stdout, warn/error\u2192stderr."),
|
|
1548
|
+
search: z10.string().max(100).optional().describe("Case-insensitive substring filter."),
|
|
1549
|
+
count_only: z10.boolean().optional().describe("When true, return only { count } \u2014 skips the log payload.")
|
|
1396
1550
|
},
|
|
1397
1551
|
handler: async (args, ctx) => {
|
|
1398
1552
|
const teamId = await ctx.resolveTeamId();
|
|
@@ -1400,8 +1554,18 @@ defineTool({
|
|
|
1400
1554
|
lines: args.lines ?? 200
|
|
1401
1555
|
};
|
|
1402
1556
|
if (args.since) opts.since = args.since;
|
|
1557
|
+
if (args.until) opts.until = args.until;
|
|
1403
1558
|
if (args.stream) opts.stream = args.stream;
|
|
1559
|
+
if (args.level) opts.level = args.level;
|
|
1560
|
+
if (args.search) opts.search = args.search;
|
|
1561
|
+
if (args.count_only) opts.countOnly = args.count_only;
|
|
1404
1562
|
const response = await ctx.hoststack.services.getRuntimeLogs(teamId, args.service_id, opts);
|
|
1563
|
+
if ("count" in response) {
|
|
1564
|
+
return respond({
|
|
1565
|
+
summary: `${response.count} matching log line${response.count === 1 ? "" : "s"} for service ${args.service_id}.`,
|
|
1566
|
+
data: { count: response.count }
|
|
1567
|
+
});
|
|
1568
|
+
}
|
|
1405
1569
|
const count = Array.isArray(response.logs) ? response.logs.length : typeof response.logs === "string" ? response.logs.split("\n").length : 0;
|
|
1406
1570
|
return respond({
|
|
1407
1571
|
summary: `Fetched ${count} log line${count === 1 ? "" : "s"} for service ${args.service_id}.`,
|
|
@@ -1410,6 +1574,146 @@ defineTool({
|
|
|
1410
1574
|
}
|
|
1411
1575
|
});
|
|
1412
1576
|
|
|
1577
|
+
// src/tools/volumes.ts
|
|
1578
|
+
import { z as z11 } from "zod";
|
|
1579
|
+
defineTool({
|
|
1580
|
+
name: "list_volumes",
|
|
1581
|
+
category: "volumes",
|
|
1582
|
+
description: [
|
|
1583
|
+
"List persistent disks attached to a service. Volumes mount writable storage into the container at the path you choose, surviving redeploys and restarts.",
|
|
1584
|
+
"",
|
|
1585
|
+
"When to use: auditing what disks are attached, checking sizes before adding more, or confirming a volume took effect after creation. Note: storage is metered for billing \u2014 use this to spot oversized disks.",
|
|
1586
|
+
"",
|
|
1587
|
+
"Inputs:",
|
|
1588
|
+
" - service_id: publicId of the service.",
|
|
1589
|
+
"",
|
|
1590
|
+
"Returns: { items: Volume[] } \u2014 each entry has id, publicId, name, mountPath, sizeGb, status (pending|active|deleting), createdAt, updatedAt.",
|
|
1591
|
+
"",
|
|
1592
|
+
'Example: list_volumes({ service_id: "svc_abc" }) \u2192 { items: [{ name: "data", mountPath: "/var/data", sizeGb: 10, status: "active" }] }'
|
|
1593
|
+
].join("\n"),
|
|
1594
|
+
input: {
|
|
1595
|
+
service_id: z11.string().describe("Service publicId (e.g. svc_abc123).")
|
|
1596
|
+
},
|
|
1597
|
+
handler: async (args, ctx) => {
|
|
1598
|
+
const teamId = await ctx.resolveTeamId();
|
|
1599
|
+
const response = await ctx.hoststack.volumes.list(teamId, args.service_id);
|
|
1600
|
+
const data = shapeList(response, "volumes", shapeVolume);
|
|
1601
|
+
const summary = data.items.length === 0 ? `No volumes attached to service ${args.service_id}.` : `Found ${data.items.length} volume${data.items.length === 1 ? "" : "s"} on service ${args.service_id}.`;
|
|
1602
|
+
return respond({ summary, data });
|
|
1603
|
+
}
|
|
1604
|
+
});
|
|
1605
|
+
defineTool({
|
|
1606
|
+
name: "create_volume",
|
|
1607
|
+
category: "volumes",
|
|
1608
|
+
description: [
|
|
1609
|
+
"Attach a new persistent disk to a service. The disk gets provisioned on the host and bind-mounted into the container at `mount_path` on the next deploy. Use this when an app needs writable persistent storage \u2014 uploads, caches, SQLite databases, anything that must survive container restarts.",
|
|
1610
|
+
"",
|
|
1611
|
+
"When to use: the user mentions storing files, uploads, or any data that needs to outlive a container restart. For purely ephemeral scratch space, point the app at /tmp instead (already tmpfs-mounted, free, no provisioning needed) \u2014 see HOSTSTACK_TMP_DIR.",
|
|
1612
|
+
"",
|
|
1613
|
+
"Inputs:",
|
|
1614
|
+
" - service_id: publicId of the service to attach to.",
|
|
1615
|
+
" - name: lowercase alphanumeric + hyphens, \u226464 chars (used as the docker volume identifier \u2014 change with care once data is written).",
|
|
1616
|
+
' - mount_path: in-container absolute path (e.g. "/var/data").',
|
|
1617
|
+
" - size_gb: optional, 1\u2013100, default 1. Counts against your plan storage quota and is metered for billing.",
|
|
1618
|
+
"",
|
|
1619
|
+
"Returns: { volume: Volume } \u2014 the created record.",
|
|
1620
|
+
"",
|
|
1621
|
+
'Example: create_volume({ service_id: "svc_abc", name: "data", mount_path: "/var/data", size_gb: 10 }) \u2192 { volume: { name: "data", mountPath: "/var/data", sizeGb: 10, status: "active" } }'
|
|
1622
|
+
].join("\n"),
|
|
1623
|
+
input: {
|
|
1624
|
+
service_id: z11.string().describe("Service publicId."),
|
|
1625
|
+
name: z11.string().min(1).max(64).regex(/^[a-z0-9-]+$/).describe("Volume name (lowercase alphanumeric + hyphens)."),
|
|
1626
|
+
mount_path: z11.string().startsWith("/").max(500).describe("In-container mount path (absolute)."),
|
|
1627
|
+
size_gb: z11.number().int().min(1).max(100).optional().describe("Disk size in GB (default 1, max 100).")
|
|
1628
|
+
},
|
|
1629
|
+
handler: async (args, ctx) => {
|
|
1630
|
+
const teamId = await ctx.resolveTeamId();
|
|
1631
|
+
const input = {
|
|
1632
|
+
name: args.name,
|
|
1633
|
+
mountPath: args.mount_path
|
|
1634
|
+
};
|
|
1635
|
+
if (args.size_gb !== void 0) input.sizeGb = args.size_gb;
|
|
1636
|
+
const response = await ctx.hoststack.volumes.create(teamId, args.service_id, input);
|
|
1637
|
+
const data = { volume: shape(response.volume) };
|
|
1638
|
+
return respond({
|
|
1639
|
+
summary: `Attached volume "${args.name}" (${args.size_gb ?? 1}GB) at ${args.mount_path} on service ${args.service_id}.`,
|
|
1640
|
+
data
|
|
1641
|
+
});
|
|
1642
|
+
}
|
|
1643
|
+
});
|
|
1644
|
+
defineTool({
|
|
1645
|
+
name: "update_volume",
|
|
1646
|
+
category: "volumes",
|
|
1647
|
+
description: [
|
|
1648
|
+
"Update a volume's mountPath or sizeGb. Resizes take effect on the next deploy; shrinking is rejected at the storage layer (filesystems can't safely shrink under live data).",
|
|
1649
|
+
"",
|
|
1650
|
+
"When to use: the user wants to grow the disk for an existing volume, or move where it mounts inside the container.",
|
|
1651
|
+
"",
|
|
1652
|
+
"Inputs:",
|
|
1653
|
+
" - service_id: publicId of the service.",
|
|
1654
|
+
" - volume_id: publicId of the volume to update.",
|
|
1655
|
+
" - mount_path (optional): new in-container mount path.",
|
|
1656
|
+
" - size_gb (optional): new size in GB (must be \u2265 current).",
|
|
1657
|
+
"",
|
|
1658
|
+
"Returns: { volume: Volume } \u2014 the updated record.",
|
|
1659
|
+
"",
|
|
1660
|
+
'Example: update_volume({ service_id: "svc_abc", volume_id: "vol_xyz", size_gb: 20 }) \u2192 { volume: { sizeGb: 20, \u2026 } }'
|
|
1661
|
+
].join("\n"),
|
|
1662
|
+
input: {
|
|
1663
|
+
service_id: z11.string().describe("Service publicId."),
|
|
1664
|
+
volume_id: z11.string().describe("Volume publicId (e.g. vol_\u2026)."),
|
|
1665
|
+
mount_path: z11.string().startsWith("/").max(500).optional().describe("New mount path."),
|
|
1666
|
+
size_gb: z11.number().int().min(1).max(100).optional().describe("New size in GB.")
|
|
1667
|
+
},
|
|
1668
|
+
handler: async (args, ctx) => {
|
|
1669
|
+
const teamId = await ctx.resolveTeamId();
|
|
1670
|
+
const input = {};
|
|
1671
|
+
if (args.mount_path !== void 0) input.mountPath = args.mount_path;
|
|
1672
|
+
if (args.size_gb !== void 0) input.sizeGb = args.size_gb;
|
|
1673
|
+
if (Object.keys(input).length === 0) {
|
|
1674
|
+
return respond({ summary: "No fields to update.", data: {} });
|
|
1675
|
+
}
|
|
1676
|
+
const response = await ctx.hoststack.volumes.update(
|
|
1677
|
+
teamId,
|
|
1678
|
+
args.service_id,
|
|
1679
|
+
args.volume_id,
|
|
1680
|
+
input
|
|
1681
|
+
);
|
|
1682
|
+
const data = { volume: shape(response.volume) };
|
|
1683
|
+
const fields = Object.keys(input).join(", ");
|
|
1684
|
+
return respond({ summary: `Updated ${fields} on volume ${args.volume_id}.`, data });
|
|
1685
|
+
}
|
|
1686
|
+
});
|
|
1687
|
+
defineTool({
|
|
1688
|
+
name: "delete_volume",
|
|
1689
|
+
category: "volumes",
|
|
1690
|
+
description: [
|
|
1691
|
+
"Detach and deprovision a volume. The underlying disk is destroyed \u2014 back up any data first. Async: marks the row deleting, the host agent finalises removal once it acks. A periodic reaper retries if the agent was offline at delete time.",
|
|
1692
|
+
"",
|
|
1693
|
+
"When to use: the user explicitly says to remove a volume, or you're cleaning up after retiring a service. Confirm before calling on production data.",
|
|
1694
|
+
"",
|
|
1695
|
+
"Inputs:",
|
|
1696
|
+
" - service_id: publicId of the service.",
|
|
1697
|
+
" - volume_id: publicId of the volume.",
|
|
1698
|
+
"",
|
|
1699
|
+
"Returns: { ok: true }.",
|
|
1700
|
+
"",
|
|
1701
|
+
'Example: delete_volume({ service_id: "svc_abc", volume_id: "vol_xyz" }) \u2192 { ok: true }'
|
|
1702
|
+
].join("\n"),
|
|
1703
|
+
input: {
|
|
1704
|
+
service_id: z11.string().describe("Service publicId."),
|
|
1705
|
+
volume_id: z11.string().describe("Volume publicId.")
|
|
1706
|
+
},
|
|
1707
|
+
handler: async (args, ctx) => {
|
|
1708
|
+
const teamId = await ctx.resolveTeamId();
|
|
1709
|
+
await ctx.hoststack.volumes.delete(teamId, args.service_id, args.volume_id);
|
|
1710
|
+
return respond({
|
|
1711
|
+
summary: `Detached volume ${args.volume_id} from service ${args.service_id} (deprovisioning).`,
|
|
1712
|
+
data: { ok: true }
|
|
1713
|
+
});
|
|
1714
|
+
}
|
|
1715
|
+
});
|
|
1716
|
+
|
|
1413
1717
|
// src/server-factory.ts
|
|
1414
1718
|
var PACKAGE_NAME = "hoststack";
|
|
1415
1719
|
var PACKAGE_VERSION = "0.1.2";
|