constructor-research-mcp 0.6.1 → 0.6.3
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 +35 -21
- package/dist/deployment.d.ts +77 -1
- package/dist/deployment.js +226 -9
- package/dist/logs.d.ts +25 -5
- package/dist/logs.js +101 -24
- package/dist/schemas.d.ts +7 -0
- package/dist/schemas.js +21 -2
- package/dist/server.js +12 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Constructor Research MCP
|
|
2
2
|
|
|
3
|
+
> **0.6.3:** `delete_resources` deletes applications, services and images, after the user approves the list.
|
|
4
|
+
>
|
|
5
|
+
> **0.6.2:** a ready-made image works on a project with deployment off (it is switched on first); logs keep 2000 lines per build or service for 14 days, services are followed for two hours, and `watched` says when.
|
|
6
|
+
>
|
|
3
7
|
> **0.6.1:** inside a Constructor desk, a key saved for your Constructor works even when the desk names another address for it (`ROLOS_API_SERVER`, e.g. `constructor.app` in a desk opened on `acme.constructor.app`).
|
|
4
8
|
>
|
|
5
9
|
> **0.6:** a registry `image` the project does not have is added to it as an external image, with no desk and no build; Constructor refuses a bad one at once, with its reason.
|
|
@@ -89,24 +93,25 @@ When the MCP runs in VS Code inside a Constructor Research desk, it finds that d
|
|
|
89
93
|
|
|
90
94
|
`CONSTRUCTOR_LOCAL_DESK=0` turns this off.
|
|
91
95
|
|
|
92
|
-
##
|
|
93
|
-
|
|
94
|
-
| Tool | Agent's task
|
|
95
|
-
| ------------------------ |
|
|
96
|
-
| `deploy_app` | Describe all services in one request, or resume that deployment with overrides.
|
|
97
|
-
| `update_app` | Describe selected changes/additions; the MCP builds and restarts affected services.
|
|
98
|
-
| `start_app` / `stop_app` | Request lifecycle changes for all or selected services.
|
|
99
|
-
| `
|
|
100
|
-
| `
|
|
101
|
-
| `
|
|
102
|
-
| `
|
|
103
|
-
| `
|
|
104
|
-
| `
|
|
105
|
-
| `
|
|
106
|
-
| `
|
|
107
|
-
| `
|
|
108
|
-
|
|
109
|
-
|
|
96
|
+
## Fourteen tools
|
|
97
|
+
|
|
98
|
+
| Tool | Agent's task |
|
|
99
|
+
| ------------------------ | ---------------------------------------------------------------------------------------------- |
|
|
100
|
+
| `deploy_app` | Describe all services in one request, or resume that deployment with overrides. |
|
|
101
|
+
| `update_app` | Describe selected changes/additions; the MCP builds and restarts affected services. |
|
|
102
|
+
| `start_app` / `stop_app` | Request lifecycle changes for all or selected services. |
|
|
103
|
+
| `delete_resources` | Delete applications, single services or images; lists them first, deletes with `confirm:true`. |
|
|
104
|
+
| `get_deployment` | Map all deployments, inspect a project or app, or wait for background execution. |
|
|
105
|
+
| `get_logs` | Last 10–500 lines of a build or service log (see "Logs"). |
|
|
106
|
+
| `build_image` | Build an image independently when needed. |
|
|
107
|
+
| `list_images` | List image IDs, Dockerfiles and native build statuses. |
|
|
108
|
+
| `list_files` | List a disk's files and folders; `recursive:true` walks subfolders. |
|
|
109
|
+
| `create_folder` | Create a disk folder, including missing parents. |
|
|
110
|
+
| `sync_files` | Upload new and changed files; asks once before replacing existing files. |
|
|
111
|
+
| `move_path` | Rename or move files/folders in one batch, approved once; never overwrites. |
|
|
112
|
+
| `delete_path` | Delete files/folders in one batch; reports first, deletes only with `confirm:true`. |
|
|
113
|
+
|
|
114
|
+
No special clone/new-instance workflow is implemented. The fourteen tools use the same standard MCP transport across harnesses.
|
|
110
115
|
|
|
111
116
|
## Where to act: the desk link
|
|
112
117
|
|
|
@@ -226,6 +231,15 @@ Successful builds and unchanged service definitions are retained. Environment ov
|
|
|
226
231
|
|
|
227
232
|
A failed build returns `failure.stage`, `failure.service`, `failure.dockerfile` and `failure.image_id`. A service API failure includes the stage and service. The message is concise: **“Please check the logs in Constructor.”** Logs and browser access are not part of this workflow.
|
|
228
233
|
|
|
234
|
+
## Deleting applications, services and images
|
|
235
|
+
|
|
236
|
+
`delete_resources` takes `project_id` (or `desk_url`) and any of `application_ids` (each with all its services), `service_ids` (the rest of the application stays) and `image_ids`. Without `confirm` it changes nothing and returns `confirm_required` with what would go: services, public URLs, and volumes whose data would be lost. The agent asks the user once for the whole list and repeats the call with `confirm:true`. Then the MCP:
|
|
237
|
+
|
|
238
|
+
- ends unfinished deployments of the affected applications (`superseded`), so none of them recreates what is deleted;
|
|
239
|
+
- deletes services, then applications, then images (an image is free once its services are gone);
|
|
240
|
+
- keeps an image that a service not being deleted still uses (`kept_in_use`), and reports IDs that are not in the project (`not_found`);
|
|
241
|
+
- reports each item as `deleted`, `already_gone`, `failed` or `uncertain` (`status: partial` when any was not deleted).
|
|
242
|
+
|
|
229
243
|
## Service links and volumes
|
|
230
244
|
|
|
231
245
|
- An environment variable can be `{service, port}` instead of a string. The MCP turns it into the other service's internal address as a bare `host:port` (e.g. `svc-temporal.app-1234abcd.svc.cluster.local:7233`), which suits gRPC, databases and Temporal. Add `scheme: "http"` to get `http://host:port`. `{service, exposure: "public"}` gives the public https URL.
|
|
@@ -262,15 +276,15 @@ For `needs_reconciliation`, inspect the possible remote mutation before submitti
|
|
|
262
276
|
|
|
263
277
|
## Logs
|
|
264
278
|
|
|
265
|
-
Constructor serves logs only live, as a stream: a build log while the build runs, a service log for the service's current container. Each connection replays the log from the start, then streams. Nothing is kept afterwards: a finished build has no log, and a restarted container starts with an empty one, so a crash-looping service shows no log at all. The MCP therefore follows every build and service it starts and keeps
|
|
279
|
+
Constructor serves logs only live, as a stream: a build log while the build runs, a service log for the service's current container. Each connection replays the log from the start, then streams. Nothing is kept afterwards: a finished build has no log, and a restarted container starts with an empty one, so a crash-looping service shows no log at all. The MCP therefore follows every build and service it starts and keeps the last 2000 lines of each in `logs/` in the state directory, where other MCP processes, the wait command and a restarted agent read them too. Files untouched for 14 days are deleted, and the oldest go first when all of them pass 100 MB.
|
|
266
280
|
|
|
267
281
|
- A build is followed from its first status check until it ends; a dropped connection is reopened and replayed lines are skipped. When the stream closes, reopening it answers "not found" and the kept lines are final.
|
|
268
|
-
- A service is followed from its start request, or from when `get_deployment` shows it running, for
|
|
282
|
+
- A service is followed from its start request, or from when `get_deployment` shows it running, for two hours after anyone last asked for it. `watched` lists when the MCP followed it: a container that started and stopped outside those periods, or while no agent or wait command was running, left no lines, because Constructor keeps none.
|
|
269
283
|
- Restarts: Constructor reports no restart count, so the MCP detects them in the stream. When a new container starts (the platform's "Container is waiting to start" line after the container's own lines, or a reconnect that begins with newer lines than were kept), it inserts `--- new container (restart N) ---` and keeps the old container's last lines above it, which usually show why it stopped. `get_logs` and the services in `get_deployment` report `restarts_seen` and `restarted_at`.
|
|
270
284
|
- `get_deployment` services also carry `status_changes`: the native statuses this MCP process saw, with times, once a service has had more than one.
|
|
271
285
|
- Lines that are only a timestamp are dropped, and identical consecutive lines are collapsed into one with a count (`(×5)`).
|
|
272
286
|
- A failed build or start puts the last 20 lines into `failure.log_tail`.
|
|
273
|
-
- `get_logs` takes `image_id`, `service_id` or `deployment_id` (all its builds and services) and `lines` (10–
|
|
287
|
+
- `get_logs` takes `image_id`, `service_id` or `deployment_id` (all its builds and services) and `lines` (10–500, default 20). It also reads builds and services this MCP did not start, but only while they run.
|
|
274
288
|
|
|
275
289
|
## Waiting for long builds
|
|
276
290
|
|
package/dist/deployment.d.ts
CHANGED
|
@@ -65,7 +65,77 @@ export declare class DeploymentEngine {
|
|
|
65
65
|
* non-amd64 or malformed image with its reason. Undefined when this Constructor
|
|
66
66
|
* has no such endpoint yet (the caller then builds it from FROM).
|
|
67
67
|
*/
|
|
68
|
-
registerExternal(project: string, service: string, reference: string): Promise<any>;
|
|
68
|
+
registerExternal(project: string, service: string, reference: string, retried?: boolean): Promise<any>;
|
|
69
|
+
/**
|
|
70
|
+
* Deletes applications (with all their services), single services and images of one
|
|
71
|
+
* project. Without confirm it only reports what would go, including public URLs and
|
|
72
|
+
* volumes whose data is lost, for the user to approve once. An image that a service
|
|
73
|
+
* not being deleted still uses is kept. Unfinished deployments of affected
|
|
74
|
+
* applications are ended first, so they cannot recreate what was deleted.
|
|
75
|
+
*/
|
|
76
|
+
deleteResources(raw: unknown): Promise<{
|
|
77
|
+
status: string;
|
|
78
|
+
message: string;
|
|
79
|
+
kept_in_use: {
|
|
80
|
+
image_id: string;
|
|
81
|
+
name: string;
|
|
82
|
+
used_by: string[];
|
|
83
|
+
}[];
|
|
84
|
+
not_found: string[];
|
|
85
|
+
delete?: undefined;
|
|
86
|
+
results?: undefined;
|
|
87
|
+
ended_deployments?: undefined;
|
|
88
|
+
} | {
|
|
89
|
+
status: string;
|
|
90
|
+
message: string;
|
|
91
|
+
delete: {
|
|
92
|
+
applications: {
|
|
93
|
+
application_id: any;
|
|
94
|
+
name: any;
|
|
95
|
+
services: any;
|
|
96
|
+
}[];
|
|
97
|
+
services: {
|
|
98
|
+
service_id: any;
|
|
99
|
+
name: any;
|
|
100
|
+
application_id: any;
|
|
101
|
+
application_name: any;
|
|
102
|
+
public_url: any;
|
|
103
|
+
volumes: any;
|
|
104
|
+
}[];
|
|
105
|
+
images: {
|
|
106
|
+
image_id: string;
|
|
107
|
+
name: any;
|
|
108
|
+
source: any;
|
|
109
|
+
reference: any;
|
|
110
|
+
desk_name: any;
|
|
111
|
+
}[];
|
|
112
|
+
};
|
|
113
|
+
kept_in_use: {
|
|
114
|
+
image_id: string;
|
|
115
|
+
name: string;
|
|
116
|
+
used_by: string[];
|
|
117
|
+
}[];
|
|
118
|
+
not_found: string[];
|
|
119
|
+
results?: undefined;
|
|
120
|
+
ended_deployments?: undefined;
|
|
121
|
+
} | {
|
|
122
|
+
delete?: undefined;
|
|
123
|
+
status: string;
|
|
124
|
+
message: string;
|
|
125
|
+
results: {
|
|
126
|
+
kind: string;
|
|
127
|
+
id: string;
|
|
128
|
+
name: string;
|
|
129
|
+
result: string;
|
|
130
|
+
}[];
|
|
131
|
+
ended_deployments: string[];
|
|
132
|
+
kept_in_use: {
|
|
133
|
+
image_id: string;
|
|
134
|
+
name: string;
|
|
135
|
+
used_by: string[];
|
|
136
|
+
}[];
|
|
137
|
+
not_found: string[];
|
|
138
|
+
}>;
|
|
69
139
|
listImages(raw: unknown): Promise<{
|
|
70
140
|
results: any[];
|
|
71
141
|
total: number;
|
|
@@ -90,6 +160,12 @@ export declare class DeploymentEngine {
|
|
|
90
160
|
private advance;
|
|
91
161
|
/** Switches on deployment; when the key may not, the operation stops with what to do instead. */
|
|
92
162
|
private enableDeployment;
|
|
163
|
+
/**
|
|
164
|
+
* Switches on deployment for a project that has it off, before anything else is added to
|
|
165
|
+
* it: Constructor adds an external image only to a project with deployment on. Switching
|
|
166
|
+
* it on twice is harmless, so this runs outside a saved operation.
|
|
167
|
+
*/
|
|
168
|
+
ensureDeployment(project: string, known?: boolean): Promise<void>;
|
|
93
169
|
private advanceBuild;
|
|
94
170
|
private advanceLifecycle;
|
|
95
171
|
private advanceApp;
|
package/dist/deployment.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { randomUUID, createHash } from "node:crypto";
|
|
2
2
|
import { setTimeout as delay } from "node:timers/promises";
|
|
3
3
|
import { ToolError, segment as e } from "./api.js";
|
|
4
|
-
import { deployInput, updateInput, buildInput, listInput, lifecycleInput, getInput, } from "./schemas.js";
|
|
4
|
+
import { deployInput, updateInput, buildInput, listInput, lifecycleInput, getInput, deleteInput, } from "./schemas.js";
|
|
5
5
|
const NOTICE = "Start requested; application readiness is unverified. Initial small deployments usually take 1–2 minutes; updates often take tens of seconds. These are estimates.";
|
|
6
6
|
export const terminal = new Set([
|
|
7
7
|
"started",
|
|
@@ -144,6 +144,12 @@ function hardwareOptions(hardware) {
|
|
|
144
144
|
.sort((a, b) => +!!a.gpu - +!!b.gpu || a.cpu - b.cpu || a.ram_gb - b.ram_gb)
|
|
145
145
|
.filter((o) => !seen.has(JSON.stringify(o)) && !!seen.add(JSON.stringify(o)));
|
|
146
146
|
}
|
|
147
|
+
/** Only the project owner may switch deployment on (421, error 40005; older servers 403). */
|
|
148
|
+
function ownerOnly(err) {
|
|
149
|
+
if (err instanceof ToolError && (err.apiCode === 40005 || err.status === 403))
|
|
150
|
+
return new ToolError("deployment_disabled", "Deployment is switched off for this project, and only the project owner can switch it on. Ask the project owner to switch on deployment for the project in Constructor, then repeat the same call.", err.status, err.apiCode);
|
|
151
|
+
return err;
|
|
152
|
+
}
|
|
147
153
|
export class DeploymentEngine {
|
|
148
154
|
api;
|
|
149
155
|
store;
|
|
@@ -275,7 +281,7 @@ export class DeploymentEngine {
|
|
|
275
281
|
if (log)
|
|
276
282
|
op.failure.log_tail = log.lines;
|
|
277
283
|
op.message = `Image build${service ? ` for ${service}` : ""} failed${first ? ` twice (${first}, then ${image.name} after re-checking the files)` : ` (${image.name})`}. ${log
|
|
278
|
-
? "The last build log lines are in failure.log_tail (get_logs with the image ID shows up to
|
|
284
|
+
? "The last build log lines are in failure.log_tail (get_logs with the image ID shows up to 500)."
|
|
279
285
|
: `No build log was captured. To see the error, open the desk (${link}), rebuild ${dockerfile} from the UI and watch the live log.`} Fix the Dockerfile or source, then deploy again.`;
|
|
280
286
|
}
|
|
281
287
|
/** Poll public URLs after start until they answer or readinessSeconds pass. */
|
|
@@ -434,7 +440,7 @@ export class DeploymentEngine {
|
|
|
434
440
|
* non-amd64 or malformed image with its reason. Undefined when this Constructor
|
|
435
441
|
* has no such endpoint yet (the caller then builds it from FROM).
|
|
436
442
|
*/
|
|
437
|
-
async registerExternal(project, service, reference) {
|
|
443
|
+
async registerExternal(project, service, reference, retried = false) {
|
|
438
444
|
try {
|
|
439
445
|
return await this.api.request("POST", this.root(project) + "/images/external", { name: externalName(reference), reference });
|
|
440
446
|
}
|
|
@@ -443,6 +449,12 @@ export class DeploymentEngine {
|
|
|
443
449
|
throw err;
|
|
444
450
|
if (err.status === 404 || err.status === 405)
|
|
445
451
|
return undefined;
|
|
452
|
+
// The project's deployment is off (switched off meanwhile, or the caller did not
|
|
453
|
+
// check): switch it on and ask once more.
|
|
454
|
+
if (!retried && /deployment is not enabled/i.test(err.reason ?? "")) {
|
|
455
|
+
await this.ensureDeployment(project, false);
|
|
456
|
+
return this.registerExternal(project, service, reference, true);
|
|
457
|
+
}
|
|
446
458
|
if ([400, 421, 422].includes(err.status ?? 0)) {
|
|
447
459
|
const why = cleanReason(err.reason);
|
|
448
460
|
throw new ToolError("image_refused", `Service ${service}: Constructor refused image ${reference}${why ? `: ${why}` : ""}. Nothing was deployed. Only public images with a linux/amd64 variant can be used; check the name and tag (Docker Hub images as name:tag or user/name:tag). Tell the user, or use build with a Dockerfile instead.`, err.status, err.apiCode, { stage: "register", service, image: reference });
|
|
@@ -450,6 +462,198 @@ export class DeploymentEngine {
|
|
|
450
462
|
throw err;
|
|
451
463
|
}
|
|
452
464
|
}
|
|
465
|
+
/**
|
|
466
|
+
* Deletes applications (with all their services), single services and images of one
|
|
467
|
+
* project. Without confirm it only reports what would go, including public URLs and
|
|
468
|
+
* volumes whose data is lost, for the user to approve once. An image that a service
|
|
469
|
+
* not being deleted still uses is kept. Unfinished deployments of affected
|
|
470
|
+
* applications are ended first, so they cannot recreate what was deleted.
|
|
471
|
+
*/
|
|
472
|
+
async deleteResources(raw) {
|
|
473
|
+
const i = deleteInput.parse(raw);
|
|
474
|
+
if (!i.application_ids?.length &&
|
|
475
|
+
!i.service_ids?.length &&
|
|
476
|
+
!i.image_ids?.length)
|
|
477
|
+
bad("Name at least one application, service or image to delete.");
|
|
478
|
+
const project = i.project_id;
|
|
479
|
+
await this.project(project);
|
|
480
|
+
const apps = await this.apps(project);
|
|
481
|
+
const images = await this.images(project);
|
|
482
|
+
const not_found = [];
|
|
483
|
+
const describe = (sv, app) => {
|
|
484
|
+
const v = publicService(sv, project, app.id);
|
|
485
|
+
return {
|
|
486
|
+
service_id: sv.id,
|
|
487
|
+
name: sv.name,
|
|
488
|
+
application_id: app.id,
|
|
489
|
+
application_name: app.name,
|
|
490
|
+
public_url: v.public_url,
|
|
491
|
+
volumes: (sv.volumes ?? []).map((x) => `${x.mount_point ?? x.name}${x.size_gb ? ` (${x.size_gb} GB)` : ""}`),
|
|
492
|
+
};
|
|
493
|
+
};
|
|
494
|
+
const applications = [...new Set(i.application_ids ?? [])].flatMap((id) => {
|
|
495
|
+
const app = apps.find((a) => a.id === id);
|
|
496
|
+
if (!app) {
|
|
497
|
+
not_found.push(`application ${id}`);
|
|
498
|
+
return [];
|
|
499
|
+
}
|
|
500
|
+
return [
|
|
501
|
+
{
|
|
502
|
+
application_id: app.id,
|
|
503
|
+
name: app.name,
|
|
504
|
+
services: (app.services ?? []).map((sv) => describe(sv, app)),
|
|
505
|
+
},
|
|
506
|
+
];
|
|
507
|
+
});
|
|
508
|
+
const goingApps = new Set(applications.map((a) => a.application_id));
|
|
509
|
+
const services = [...new Set(i.service_ids ?? [])].flatMap((id) => {
|
|
510
|
+
const app = apps.find((a) => (a.services ?? []).some((sv) => sv.id === id));
|
|
511
|
+
if (!app) {
|
|
512
|
+
not_found.push(`service ${id}`);
|
|
513
|
+
return [];
|
|
514
|
+
}
|
|
515
|
+
// Goes with its application anyway.
|
|
516
|
+
if (goingApps.has(app.id))
|
|
517
|
+
return [];
|
|
518
|
+
return [
|
|
519
|
+
describe(app.services.find((sv) => sv.id === id), app),
|
|
520
|
+
];
|
|
521
|
+
});
|
|
522
|
+
const goingServices = new Set([
|
|
523
|
+
...services.map((sv) => sv.service_id),
|
|
524
|
+
...applications.flatMap((a) => a.services.map((sv) => sv.service_id)),
|
|
525
|
+
]);
|
|
526
|
+
const kept = [];
|
|
527
|
+
const imageRows = [...new Set(i.image_ids ?? [])].flatMap((id) => {
|
|
528
|
+
const im = images.find((x) => x.id === id);
|
|
529
|
+
if (!im) {
|
|
530
|
+
not_found.push(`image ${id}`);
|
|
531
|
+
return [];
|
|
532
|
+
}
|
|
533
|
+
const used_by = apps.flatMap((a) => (a.services ?? [])
|
|
534
|
+
.filter((sv) => sv.image_id === id && !goingServices.has(sv.id))
|
|
535
|
+
.map((sv) => `${a.name}/${sv.name}`));
|
|
536
|
+
if (used_by.length) {
|
|
537
|
+
kept.push({ image_id: id, name: im.name, used_by });
|
|
538
|
+
return [];
|
|
539
|
+
}
|
|
540
|
+
return [
|
|
541
|
+
{
|
|
542
|
+
image_id: id,
|
|
543
|
+
name: im.name,
|
|
544
|
+
source: im.source,
|
|
545
|
+
reference: im.reference,
|
|
546
|
+
desk_name: im.desk_name,
|
|
547
|
+
},
|
|
548
|
+
];
|
|
549
|
+
});
|
|
550
|
+
const plan = { applications, services, images: imageRows };
|
|
551
|
+
const count = applications.length + services.length + imageRows.length;
|
|
552
|
+
const notes = [
|
|
553
|
+
kept.length
|
|
554
|
+
? `Kept, still used by a service that stays: ${kept.map((k) => `${k.name} (${k.used_by.join(", ")})`).join("; ")}.`
|
|
555
|
+
: "",
|
|
556
|
+
not_found.length ? `Not in this project: ${not_found.join(", ")}.` : "",
|
|
557
|
+
].filter(Boolean);
|
|
558
|
+
if (!count)
|
|
559
|
+
return {
|
|
560
|
+
status: "nothing_to_delete",
|
|
561
|
+
message: ["Nothing was deleted.", ...notes].join(" "),
|
|
562
|
+
kept_in_use: kept,
|
|
563
|
+
not_found,
|
|
564
|
+
};
|
|
565
|
+
if (!i.confirm) {
|
|
566
|
+
const volumes = [
|
|
567
|
+
...applications.flatMap((a) => a.services),
|
|
568
|
+
...services,
|
|
569
|
+
].flatMap((sv) => sv.volumes.map((v) => `${sv.application_name}/${sv.name}: ${v}`));
|
|
570
|
+
return {
|
|
571
|
+
status: "confirm_required",
|
|
572
|
+
message: [
|
|
573
|
+
`${count} item${count > 1 ? "s" : ""} would be deleted. This cannot be undone; public URLs stop working${volumes.length ? ` and these volumes lose all their data: ${volumes.join("; ")}` : ""}. Nothing was changed: ask the user once to approve the whole list, then repeat the same call with confirm=true.`,
|
|
574
|
+
...notes,
|
|
575
|
+
].join(" "),
|
|
576
|
+
delete: plan,
|
|
577
|
+
kept_in_use: kept,
|
|
578
|
+
not_found,
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
// End unfinished deployments of these applications first, under the lock, so none of
|
|
582
|
+
// them recreates a service after it is deleted.
|
|
583
|
+
const touched = new Set([
|
|
584
|
+
...goingApps,
|
|
585
|
+
...services.map((sv) => sv.application_id),
|
|
586
|
+
]);
|
|
587
|
+
const ended = [];
|
|
588
|
+
await this.store.exclusive(async () => {
|
|
589
|
+
for (const id of await this.store.ids()) {
|
|
590
|
+
let op;
|
|
591
|
+
try {
|
|
592
|
+
op = await this.store.load(id);
|
|
593
|
+
}
|
|
594
|
+
catch {
|
|
595
|
+
continue;
|
|
596
|
+
}
|
|
597
|
+
if (!op?.application_id || !touched.has(op.application_id))
|
|
598
|
+
continue;
|
|
599
|
+
if (terminal.has(op.status))
|
|
600
|
+
continue;
|
|
601
|
+
op.status = "superseded";
|
|
602
|
+
delete op.pending;
|
|
603
|
+
op.message =
|
|
604
|
+
"Ended because its application or services were deleted (delete_resources).";
|
|
605
|
+
await this.store.save(op);
|
|
606
|
+
ended.push(op.id);
|
|
607
|
+
}
|
|
608
|
+
});
|
|
609
|
+
const results = [];
|
|
610
|
+
const remove = async (kind, path, id, name) => {
|
|
611
|
+
try {
|
|
612
|
+
await this.api.request("DELETE", path);
|
|
613
|
+
results.push({ kind, id, name, result: "deleted" });
|
|
614
|
+
}
|
|
615
|
+
catch (err) {
|
|
616
|
+
if (!(err instanceof ToolError) || err.code === "needs_key")
|
|
617
|
+
throw err;
|
|
618
|
+
const gone = err.status === 404 ||
|
|
619
|
+
(err.status === 421 && /not found/i.test(err.reason ?? ""));
|
|
620
|
+
results.push({
|
|
621
|
+
kind,
|
|
622
|
+
id,
|
|
623
|
+
name,
|
|
624
|
+
result: gone
|
|
625
|
+
? "already_gone"
|
|
626
|
+
: err.code === "api_error"
|
|
627
|
+
? `failed: ${err.message}`
|
|
628
|
+
: `uncertain: ${err.message} Check with get_deployment or list_images.`,
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
};
|
|
632
|
+
// Services, then applications, then images: an image is free once its services are gone.
|
|
633
|
+
for (const sv of services)
|
|
634
|
+
await remove("service", `/services/${e(sv.service_id)}`, sv.service_id, sv.name);
|
|
635
|
+
for (const a of applications)
|
|
636
|
+
await remove("application", `/applications/${e(a.application_id)}`, a.application_id, a.name);
|
|
637
|
+
for (const im of imageRows)
|
|
638
|
+
await remove("image", `/images/${e(im.image_id)}`, im.image_id, im.name);
|
|
639
|
+
const failed = results.filter((r) => !/^(deleted|already_gone)$/.test(r.result));
|
|
640
|
+
return {
|
|
641
|
+
status: failed.length ? "partial" : "deleted",
|
|
642
|
+
message: [
|
|
643
|
+
`Deleted ${results.length - failed.length} of ${results.length}${failed.length ? `; ${failed.length} not deleted (see results)` : ""}.`,
|
|
644
|
+
ended.length
|
|
645
|
+
? `Ended unfinished deployment${ended.length > 1 ? "s" : ""} ${ended.join(", ")}.`
|
|
646
|
+
: "",
|
|
647
|
+
...notes,
|
|
648
|
+
]
|
|
649
|
+
.filter(Boolean)
|
|
650
|
+
.join(" "),
|
|
651
|
+
results,
|
|
652
|
+
ended_deployments: ended,
|
|
653
|
+
kept_in_use: kept,
|
|
654
|
+
not_found,
|
|
655
|
+
};
|
|
656
|
+
}
|
|
453
657
|
async listImages(raw) {
|
|
454
658
|
const input = listInput.parse(raw);
|
|
455
659
|
await this.project(input.project_id);
|
|
@@ -861,7 +1065,7 @@ export class DeploymentEngine {
|
|
|
861
1065
|
const log = id && (await this.logs?.peek(id, "service", 20));
|
|
862
1066
|
if (log) {
|
|
863
1067
|
op.failure = { ...op.failure, log_tail: log.lines };
|
|
864
|
-
op.message = `${op.failure.stage} failed for ${op.failure.service}. The last service log lines are in failure.log_tail (get_logs with the service ID shows up to
|
|
1068
|
+
op.message = `${op.failure.stage} failed for ${op.failure.service}. The last service log lines are in failure.log_tail (get_logs with the service ID shows up to 500).`;
|
|
865
1069
|
}
|
|
866
1070
|
}
|
|
867
1071
|
await this.store.save(op);
|
|
@@ -876,11 +1080,24 @@ export class DeploymentEngine {
|
|
|
876
1080
|
});
|
|
877
1081
|
}
|
|
878
1082
|
catch (err) {
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
1083
|
+
throw ownerOnly(err);
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
/**
|
|
1087
|
+
* Switches on deployment for a project that has it off, before anything else is added to
|
|
1088
|
+
* it: Constructor adds an external image only to a project with deployment on. Switching
|
|
1089
|
+
* it on twice is harmless, so this runs outside a saved operation.
|
|
1090
|
+
*/
|
|
1091
|
+
async ensureDeployment(project, known) {
|
|
1092
|
+
if (known ?? (await this.project(project)).deployment_enabled)
|
|
1093
|
+
return;
|
|
1094
|
+
try {
|
|
1095
|
+
await this.api.request("POST", this.root(project) + "/deployment", {
|
|
1096
|
+
enabled: true,
|
|
1097
|
+
});
|
|
1098
|
+
}
|
|
1099
|
+
catch (err) {
|
|
1100
|
+
throw ownerOnly(err);
|
|
884
1101
|
}
|
|
885
1102
|
}
|
|
886
1103
|
async advanceBuild(op) {
|
package/dist/logs.d.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { PlatformApi } from "./api.js";
|
|
2
|
-
/** Lines kept per build
|
|
3
|
-
export declare const KEEP =
|
|
2
|
+
/** Lines kept per build or service, in memory and in its file. */
|
|
3
|
+
export declare const KEEP = 2000;
|
|
4
|
+
/** The most lines get_logs returns at once. */
|
|
5
|
+
export declare const SHOW = 500;
|
|
4
6
|
export type LogState = "live" | "finished" | "unavailable";
|
|
5
7
|
/** Every connection replays the log from the start (a service: its current container), then streams. */
|
|
6
8
|
export type LogKind = "build" | "service";
|
|
9
|
+
/** A stretch of time the MCP followed a log; `to` is missing while it still does. */
|
|
10
|
+
export interface Period {
|
|
11
|
+
from: string;
|
|
12
|
+
to?: string;
|
|
13
|
+
}
|
|
7
14
|
export interface LogView {
|
|
8
15
|
kind: LogKind;
|
|
9
16
|
id: string;
|
|
@@ -13,11 +20,13 @@ export interface LogView {
|
|
|
13
20
|
/** New containers seen starting while the MCP followed this service. */
|
|
14
21
|
restarts_seen?: number;
|
|
15
22
|
restarted_at?: string[];
|
|
23
|
+
/** When the MCP followed this log; lines printed outside these periods were never seen. */
|
|
24
|
+
watched?: Period[];
|
|
16
25
|
message?: string;
|
|
17
26
|
}
|
|
18
27
|
/**
|
|
19
|
-
* Follows build and service log streams and keeps
|
|
20
|
-
*
|
|
28
|
+
* Follows build and service log streams and keeps the last KEEP lines of each, in memory
|
|
29
|
+
* and in a file in the state directory; old files are deleted (rotate). The platform serves a build log only
|
|
21
30
|
* while the build runs, and every connection replays it from the start, so a dropped
|
|
22
31
|
* stream is reopened and already-seen lines are skipped. When the build ends the stream
|
|
23
32
|
* closes and reopening answers "not found"; the kept lines stay readable. A service log
|
|
@@ -35,6 +44,12 @@ export declare class LogFollower {
|
|
|
35
44
|
idleMs: number;
|
|
36
45
|
/** How long to follow after the last interest: builds until they end, services briefly. */
|
|
37
46
|
followMs: Record<LogKind, number>;
|
|
47
|
+
/** Kept files older than this are deleted. */
|
|
48
|
+
retainMs: number;
|
|
49
|
+
/** Beyond this many bytes of kept files, the oldest are deleted. */
|
|
50
|
+
maxBytes: number;
|
|
51
|
+
/** When old files were last looked for. */
|
|
52
|
+
private rotated;
|
|
38
53
|
constructor(api: PlatformApi, dir?: string);
|
|
39
54
|
/** Start following if nobody is; cheap to call on every poll. */
|
|
40
55
|
follow(id: string, kind?: LogKind): void;
|
|
@@ -54,6 +69,11 @@ export declare class LogFollower {
|
|
|
54
69
|
/** At most every few seconds while streaming, and once at the end. */
|
|
55
70
|
private save;
|
|
56
71
|
private load;
|
|
57
|
-
/** Forget the oldest finished
|
|
72
|
+
/** Forget the oldest finished logs; their files remain. */
|
|
58
73
|
private prune;
|
|
74
|
+
/**
|
|
75
|
+
* Deletes kept files older than retainMs, then the oldest until all of them fit in
|
|
76
|
+
* maxBytes. Logs being followed now are never deleted. Runs at most hourly, on save.
|
|
77
|
+
*/
|
|
78
|
+
rotate(): Promise<void>;
|
|
59
79
|
}
|
package/dist/logs.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import { mkdir, readFile, writeFile } from "node:fs/promises";
|
|
1
|
+
import { mkdir, readdir, readFile, rm, stat, writeFile, } from "node:fs/promises";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { setTimeout as delay } from "node:timers/promises";
|
|
4
4
|
import { ToolError, segment } from "./api.js";
|
|
5
|
-
/** Lines kept per build
|
|
6
|
-
export const KEEP =
|
|
5
|
+
/** Lines kept per build or service, in memory and in its file. */
|
|
6
|
+
export const KEEP = 2000;
|
|
7
|
+
/** The most lines get_logs returns at once. */
|
|
8
|
+
export const SHOW = 500;
|
|
9
|
+
/** Periods of watching kept per log. */
|
|
10
|
+
const PERIODS = 20;
|
|
7
11
|
/** Longer lines are cut, so one runaway line cannot fill memory. */
|
|
8
12
|
const WIDTH = 1000;
|
|
9
13
|
const ID = /^[a-zA-Z0-9_-]{4,128}$/;
|
|
@@ -18,8 +22,8 @@ const PATH = {
|
|
|
18
22
|
service: "services",
|
|
19
23
|
};
|
|
20
24
|
/**
|
|
21
|
-
* Follows build and service log streams and keeps
|
|
22
|
-
*
|
|
25
|
+
* Follows build and service log streams and keeps the last KEEP lines of each, in memory
|
|
26
|
+
* and in a file in the state directory; old files are deleted (rotate). The platform serves a build log only
|
|
23
27
|
* while the build runs, and every connection replays it from the start, so a dropped
|
|
24
28
|
* stream is reopened and already-seen lines are skipped. When the build ends the stream
|
|
25
29
|
* closes and reopening answers "not found"; the kept lines stay readable. A service log
|
|
@@ -38,8 +42,14 @@ export class LogFollower {
|
|
|
38
42
|
/** How long to follow after the last interest: builds until they end, services briefly. */
|
|
39
43
|
followMs = {
|
|
40
44
|
build: 2 * 60 * 60 * 1000,
|
|
41
|
-
service:
|
|
45
|
+
service: 2 * 60 * 60 * 1000,
|
|
42
46
|
};
|
|
47
|
+
/** Kept files older than this are deleted. */
|
|
48
|
+
retainMs = 14 * 24 * 60 * 60 * 1000;
|
|
49
|
+
/** Beyond this many bytes of kept files, the oldest are deleted. */
|
|
50
|
+
maxBytes = 100 * 1024 * 1024;
|
|
51
|
+
/** When old files were last looked for. */
|
|
52
|
+
rotated = 0;
|
|
43
53
|
constructor(api, dir = join(api.config.stateDir, "logs")) {
|
|
44
54
|
this.api = api;
|
|
45
55
|
this.dir = dir;
|
|
@@ -61,15 +71,22 @@ export class LogFollower {
|
|
|
61
71
|
restarts: [],
|
|
62
72
|
state: "live",
|
|
63
73
|
saved: 0,
|
|
74
|
+
watched: [],
|
|
64
75
|
};
|
|
65
76
|
this.logs.set(`${kind}:${id}`, log);
|
|
66
77
|
this.prune();
|
|
67
78
|
}
|
|
68
79
|
log.state = "live";
|
|
69
80
|
log.error = undefined;
|
|
81
|
+
log.watched.push({ from: new Date().toISOString() });
|
|
82
|
+
if (log.watched.length > PERIODS)
|
|
83
|
+
log.watched.shift();
|
|
70
84
|
const current = log;
|
|
71
85
|
current.reader = this.read(id, current).finally(() => {
|
|
72
86
|
current.reader = undefined;
|
|
87
|
+
const period = current.watched.at(-1);
|
|
88
|
+
if (period && !period.to)
|
|
89
|
+
period.to = new Date().toISOString();
|
|
73
90
|
if (current.state === "live")
|
|
74
91
|
current.state = current.lines.length ? "finished" : "unavailable";
|
|
75
92
|
return this.save(id, current, true);
|
|
@@ -109,30 +126,43 @@ export class LogFollower {
|
|
|
109
126
|
view(id, log, count) {
|
|
110
127
|
const service = log.kind === "service";
|
|
111
128
|
const restarts = log.restarts.length;
|
|
129
|
+
const lines = log.lines.slice(-Math.max(1, Math.min(KEEP, count)));
|
|
130
|
+
const said = log.error ??
|
|
131
|
+
(restarts
|
|
132
|
+
? `The container restarted ${restarts} time${restarts > 1 ? "s" : ""} while the MCP followed it (last at ${log.restarts.at(-1)}). Lines above each "--- new container" marker come from the container before it; its last lines usually show why it stopped.`
|
|
133
|
+
: undefined) ??
|
|
134
|
+
(log.state === "unavailable"
|
|
135
|
+
? service
|
|
136
|
+
? "No log: the service is not running, or its current container has printed nothing (a container that keeps crashing has no current log)."
|
|
137
|
+
: "No log: the build is not running and this MCP did not follow it while it ran. Constructor serves build logs only during the build."
|
|
138
|
+
: log.state === "finished"
|
|
139
|
+
? service
|
|
140
|
+
? "No longer following; these are the last lines kept."
|
|
141
|
+
: "The build is no longer running; these are the last lines it wrote."
|
|
142
|
+
: service
|
|
143
|
+
? "Following the log of the service's current container. No lines can mean the container keeps restarting (crash loop) or has printed nothing yet."
|
|
144
|
+
: undefined);
|
|
145
|
+
// Every connection replays the current container from its start, so only a container
|
|
146
|
+
// that started and stopped while nobody followed is lost: Constructor keeps no old logs.
|
|
147
|
+
const gaps = service && log.state !== "live" && log.watched.length
|
|
148
|
+
? `The MCP followed this service's log ${log.watched
|
|
149
|
+
.map((p) => `from ${p.from} to ${p.to ?? "now"}`)
|
|
150
|
+
.join(", ")}. A container that started and stopped outside ${log.watched.length > 1 ? "those periods" : "that period"} left no lines here, because Constructor serves logs only while they are live.`
|
|
151
|
+
: undefined;
|
|
152
|
+
const more = log.lines.length > lines.length
|
|
153
|
+
? `${log.lines.length} lines are kept; ask for more with lines (up to ${SHOW}).`
|
|
154
|
+
: undefined;
|
|
112
155
|
return {
|
|
113
156
|
kind: log.kind,
|
|
114
157
|
id,
|
|
115
158
|
state: log.state,
|
|
116
|
-
lines
|
|
159
|
+
lines,
|
|
117
160
|
last_received_at: log.received,
|
|
118
161
|
...(restarts
|
|
119
162
|
? { restarts_seen: restarts, restarted_at: log.restarts }
|
|
120
163
|
: {}),
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
? `The container restarted ${restarts} time${restarts > 1 ? "s" : ""} while the MCP followed it (last at ${log.restarts.at(-1)}). Lines above each "--- new container" marker come from the container before it; its last lines usually show why it stopped.`
|
|
124
|
-
: undefined) ??
|
|
125
|
-
(log.state === "unavailable"
|
|
126
|
-
? service
|
|
127
|
-
? "No log: the service is not running, or its current container has printed nothing (a container that keeps crashing has no current log)."
|
|
128
|
-
: "No log: the build is not running and this MCP did not follow it while it ran. Constructor serves build logs only during the build."
|
|
129
|
-
: log.state === "finished"
|
|
130
|
-
? service
|
|
131
|
-
? "No longer following; these are the last lines kept."
|
|
132
|
-
: "The build is no longer running; these are the last lines it wrote."
|
|
133
|
-
: service
|
|
134
|
-
? "Following the log of the service's current container. No lines can mean the container keeps restarting (crash loop) or has printed nothing yet."
|
|
135
|
-
: undefined),
|
|
164
|
+
...(log.watched.length ? { watched: log.watched } : {}),
|
|
165
|
+
message: [said, gaps, more].filter(Boolean).join(" ") || undefined,
|
|
136
166
|
};
|
|
137
167
|
}
|
|
138
168
|
async read(id, log) {
|
|
@@ -290,7 +320,10 @@ export class LogFollower {
|
|
|
290
320
|
restarts: log.restarts,
|
|
291
321
|
received: log.received,
|
|
292
322
|
error: log.error,
|
|
323
|
+
watched: log.watched,
|
|
293
324
|
}), { mode: 0o600 });
|
|
325
|
+
if (Date.now() - this.rotated > 60 * 60 * 1000)
|
|
326
|
+
await this.rotate();
|
|
294
327
|
}
|
|
295
328
|
catch {
|
|
296
329
|
/* Logs are a convenience; never fail a deployment over them. */
|
|
@@ -310,7 +343,14 @@ export class LogFollower {
|
|
|
310
343
|
received: kept.received,
|
|
311
344
|
error: kept.error,
|
|
312
345
|
saved: 0,
|
|
346
|
+
watched: Array.isArray(kept.watched)
|
|
347
|
+
? kept.watched.filter((p) => typeof p?.from === "string")
|
|
348
|
+
: [],
|
|
313
349
|
};
|
|
350
|
+
// A period another process left open ended when it last wrote the file, at the latest.
|
|
351
|
+
const open = log.watched.at(-1);
|
|
352
|
+
if (open && !open.to)
|
|
353
|
+
open.to = log.received ?? open.from;
|
|
314
354
|
this.logs.set(`${kind}:${id}`, log);
|
|
315
355
|
return log;
|
|
316
356
|
}
|
|
@@ -318,13 +358,50 @@ export class LogFollower {
|
|
|
318
358
|
return undefined;
|
|
319
359
|
}
|
|
320
360
|
}
|
|
321
|
-
/** Forget the oldest finished
|
|
361
|
+
/** Forget the oldest finished logs; their files remain. */
|
|
322
362
|
prune() {
|
|
323
363
|
for (const [id, log] of this.logs) {
|
|
324
|
-
if (this.logs.size <=
|
|
364
|
+
if (this.logs.size <= 30)
|
|
325
365
|
return;
|
|
326
366
|
if (!log.reader)
|
|
327
367
|
this.logs.delete(id);
|
|
328
368
|
}
|
|
329
369
|
}
|
|
370
|
+
/**
|
|
371
|
+
* Deletes kept files older than retainMs, then the oldest until all of them fit in
|
|
372
|
+
* maxBytes. Logs being followed now are never deleted. Runs at most hourly, on save.
|
|
373
|
+
*/
|
|
374
|
+
async rotate() {
|
|
375
|
+
this.rotated = Date.now();
|
|
376
|
+
try {
|
|
377
|
+
const live = new Set([...this.logs]
|
|
378
|
+
.filter(([, log]) => log.reader)
|
|
379
|
+
.map(([key]) => key.replace(":", "-") + ".json"));
|
|
380
|
+
const files = [];
|
|
381
|
+
for (const name of await readdir(this.dir)) {
|
|
382
|
+
if (!/^(build|service)-[a-zA-Z0-9_-]+\.json$/.test(name))
|
|
383
|
+
continue;
|
|
384
|
+
const info = await stat(join(this.dir, name)).catch(() => undefined);
|
|
385
|
+
if (info)
|
|
386
|
+
files.push({ name, at: info.mtimeMs, size: info.size });
|
|
387
|
+
}
|
|
388
|
+
files.sort((a, b) => b.at - a.at); // newest first
|
|
389
|
+
let total = 0;
|
|
390
|
+
for (const f of files) {
|
|
391
|
+
total += f.size;
|
|
392
|
+
const old = Date.now() - f.at > this.retainMs || total > this.maxBytes;
|
|
393
|
+
if (old && !live.has(f.name)) {
|
|
394
|
+
await rm(join(this.dir, f.name), { force: true });
|
|
395
|
+
total -= f.size;
|
|
396
|
+
const [kind, ...rest] = f.name.slice(0, -5).split("-");
|
|
397
|
+
const key = `${kind}:${rest.join("-")}`;
|
|
398
|
+
if (!this.logs.get(key)?.reader)
|
|
399
|
+
this.logs.delete(key);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
catch {
|
|
404
|
+
/* Logs are a convenience; never fail over them. */
|
|
405
|
+
}
|
|
406
|
+
}
|
|
330
407
|
}
|
package/dist/schemas.d.ts
CHANGED
|
@@ -204,6 +204,13 @@ export declare const createFolderInput: z.ZodObject<{
|
|
|
204
204
|
desk_id: z.ZodString;
|
|
205
205
|
path: z.ZodString;
|
|
206
206
|
}, z.core.$strict>;
|
|
207
|
+
export declare const deleteInput: z.ZodObject<{
|
|
208
|
+
project_id: z.ZodString;
|
|
209
|
+
application_ids: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
210
|
+
service_ids: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
211
|
+
image_ids: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
212
|
+
confirm: z.ZodDefault<z.ZodBoolean>;
|
|
213
|
+
}, z.core.$strict>;
|
|
207
214
|
export declare const movePathInput: z.ZodObject<{
|
|
208
215
|
project_id: z.ZodString;
|
|
209
216
|
desk_id: z.ZodString;
|
package/dist/schemas.js
CHANGED
|
@@ -205,9 +205,9 @@ export const logsInput = z
|
|
|
205
205
|
.number()
|
|
206
206
|
.int()
|
|
207
207
|
.min(10)
|
|
208
|
-
.max(
|
|
208
|
+
.max(500)
|
|
209
209
|
.default(20)
|
|
210
|
-
.describe("How many of the last log lines to return."),
|
|
210
|
+
.describe("How many of the last log lines to return (up to 500; the MCP keeps 2000 per log)."),
|
|
211
211
|
})
|
|
212
212
|
.refine((x) => [x.image_id, x.service_id, x.deployment_id].filter(Boolean).length === 1, "Pass one of image_id, service_id or deployment_id.");
|
|
213
213
|
export const listFilesInput = z.strictObject({
|
|
@@ -227,6 +227,25 @@ const confirm = z
|
|
|
227
227
|
.boolean()
|
|
228
228
|
.default(false)
|
|
229
229
|
.describe("false (default) returns the full list for the user to approve once; true performs it.");
|
|
230
|
+
export const deleteInput = z.strictObject({
|
|
231
|
+
project_id: id,
|
|
232
|
+
application_ids: z
|
|
233
|
+
.array(id)
|
|
234
|
+
.max(20)
|
|
235
|
+
.optional()
|
|
236
|
+
.describe("Applications to delete, each with all its services."),
|
|
237
|
+
service_ids: z
|
|
238
|
+
.array(id)
|
|
239
|
+
.max(50)
|
|
240
|
+
.optional()
|
|
241
|
+
.describe("Services to delete; the rest of their application stays (services[].id in get_deployment)."),
|
|
242
|
+
image_ids: z
|
|
243
|
+
.array(id)
|
|
244
|
+
.max(50)
|
|
245
|
+
.optional()
|
|
246
|
+
.describe("Images to delete (list_images). An image a remaining service uses is kept."),
|
|
247
|
+
confirm,
|
|
248
|
+
});
|
|
230
249
|
export const movePathInput = z.strictObject({
|
|
231
250
|
project_id: id,
|
|
232
251
|
desk_id: id,
|
package/dist/server.js
CHANGED
|
@@ -27,9 +27,10 @@ const DESK_DEFAULT = new Set([
|
|
|
27
27
|
"update_app",
|
|
28
28
|
"start_app",
|
|
29
29
|
"stop_app",
|
|
30
|
+
"delete_resources",
|
|
30
31
|
]);
|
|
31
32
|
import { ZodError } from "zod";
|
|
32
|
-
import { buildInput, listInput, deployInput, updateInput, lifecycleInput, getInput, logsInput, listFilesInput, createFolderInput, syncFilesInput, movePathInput, deletePathInput, } from "./schemas.js";
|
|
33
|
+
import { buildInput, listInput, deployInput, updateInput, lifecycleInput, deleteInput, getInput, logsInput, listFilesInput, createFolderInput, syncFilesInput, movePathInput, deletePathInput, } from "./schemas.js";
|
|
33
34
|
async function main() {
|
|
34
35
|
const config = configFromEnv();
|
|
35
36
|
const api = new PlatformApi(config);
|
|
@@ -58,11 +59,18 @@ async function main() {
|
|
|
58
59
|
// registry image is added to the project as an external image: no desk, no build.
|
|
59
60
|
const added = new Map();
|
|
60
61
|
let services = [];
|
|
62
|
+
let switchedOn = false;
|
|
61
63
|
for (const x of await engine.resolveImages(a.project_id, a.services)) {
|
|
62
64
|
if (!x.image) {
|
|
63
65
|
services.push(x);
|
|
64
66
|
continue;
|
|
65
67
|
}
|
|
68
|
+
// Constructor adds external images only to a project with deployment on, which the
|
|
69
|
+
// deployment itself would switch on only later.
|
|
70
|
+
if (!switchedOn) {
|
|
71
|
+
await engine.ensureDeployment(a.project_id);
|
|
72
|
+
switchedOn = true;
|
|
73
|
+
}
|
|
66
74
|
if (!/^[a-z0-9][a-z0-9._/:@-]*$/i.test(x.image))
|
|
67
75
|
throw new ToolError("invalid_input", `Service ${x.name}: invalid image reference.`);
|
|
68
76
|
const ref = shortReference(x.image);
|
|
@@ -225,7 +233,7 @@ async function main() {
|
|
|
225
233
|
? text.replace(/Where to act: ask the user for the Constructor desk link.*?if the user has not said where to deploy or where files live, ask\. /, deskInstructions(config.localDesk) + " ")
|
|
226
234
|
: text;
|
|
227
235
|
const server = new McpServer({ name: "constructor-research", version: VERSION }, {
|
|
228
|
-
instructions: withDesk(`Access: the MCP works with one Constructor and the user's personal access key for it, set up outside the chat. When a tool returns needs_key, pass its instructions on to the user; never ask for the key in the chat. Where to act: ask the user for the Constructor desk link (they open the desk in the browser and copy the address; it contains /projects/<project>/desks/<desk>) and pass it as desk_url. Do not pick a project yourself; if the user has not said where to deploy or where files live, ask. Given a project only (project_id), the MCP uses its only desk, or creates one for a deploy when there is none; when the project has several desks it returns desk_choice_required with their names and links: ask the user which one. Ask the user only before replacing, renaming or deleting files on a disk, once per request for the whole list (the tools return confirm_required); creating folders and uploading new files need no question. ${RULES} For a local app, pass build.local_path (the folder with the Dockerfile) and deploy_app uploads it first. A service can also take image: a public registry reference (repo:tag) that runs unchanged. The MCP uses the copy in the project when there is one (list_images shows source and reference), otherwise adds it to the project as an external image, with no desk and no build; if Constructor refuses it (image_refused), tell the user the reason. Hardware: leave it out; the default is used. Set hardware minimums only when the app cannot run without a GPU or a lot of RAM. Use deploy_app/update_app once for the WHOLE application. The MCP builds, resolves service URLs, configures and starts services in the background. IDs are automatic. To wait, run the wait command that next_action names (with a shell), or call get_deployment(wait_seconds=45) again until it is finished; never perform the deployment steps yourself. Never end the turn while a deployment the user asked for is still running. When the user asks to deploy or build, wait until the deployment is finished before answering, then give the public URL or what failed. On failure, tell the user the failed stage/service; failure.log_tail and get_logs show the last build or service log lines. Do not use browser or debugging tools. For source files: sync_files to the desk before building (the MCP checks each Dockerfile on the disk and reports warnings); after a needs_upload pause, sync and call get_deployment with files_uploaded=true. Started is not readiness.`),
|
|
236
|
+
instructions: withDesk(`Access: the MCP works with one Constructor and the user's personal access key for it, set up outside the chat. When a tool returns needs_key, pass its instructions on to the user; never ask for the key in the chat. Never read the key file or call Constructor's API yourself (curl, scripts): everything goes through these tools, and if they cannot do something, tell the user. Where to act: ask the user for the Constructor desk link (they open the desk in the browser and copy the address; it contains /projects/<project>/desks/<desk>) and pass it as desk_url. Do not pick a project yourself; if the user has not said where to deploy or where files live, ask. Given a project only (project_id), the MCP uses its only desk, or creates one for a deploy when there is none; when the project has several desks it returns desk_choice_required with their names and links: ask the user which one. Ask the user only before replacing, renaming or deleting files on a disk, once per request for the whole list (the tools return confirm_required); creating folders and uploading new files need no question. ${RULES} For a local app, pass build.local_path (the folder with the Dockerfile) and deploy_app uploads it first. A service can also take image: a public registry reference (repo:tag) that runs unchanged. The MCP uses the copy in the project when there is one (list_images shows source and reference), otherwise adds it to the project as an external image, with no desk and no build; if Constructor refuses it (image_refused), tell the user the reason. Hardware: leave it out; the default is used. Set hardware minimums only when the app cannot run without a GPU or a lot of RAM. Use deploy_app/update_app once for the WHOLE application. The MCP builds, resolves service URLs, configures and starts services in the background. IDs are automatic. To wait, run the wait command that next_action names (with a shell), or call get_deployment(wait_seconds=45) again until it is finished; never perform the deployment steps yourself. Never end the turn while a deployment the user asked for is still running. When the user asks to deploy or build, wait until the deployment is finished before answering, then give the public URL or what failed. On failure, tell the user the failed stage/service; failure.log_tail and get_logs show the last build or service log lines. Do not use browser or debugging tools. To remove applications, services or images, use delete_resources (it asks the user first). For source files: sync_files to the desk before building (the MCP checks each Dockerfile on the disk and reports warnings); after a needs_upload pause, sync and call get_deployment with files_uploaded=true. Started is not readiness.`),
|
|
229
237
|
});
|
|
230
238
|
const register = (name, description, schema, fn, readOnly = false, budget = 20000, scope) => {
|
|
231
239
|
const here = config.localDesk && DESK_DEFAULT.has(name) ? config.localDesk : undefined;
|
|
@@ -322,8 +330,9 @@ async function main() {
|
|
|
322
330
|
register("update_app", "Update/add selected services in one request; preserve omitted settings. MCP handles builds, links and restarts in the background. Environment variables merge; supplied port/volume lists replace their lists. Resume a failed update using deployment_id and service overrides. The Dockerfile rules in deploy_app apply.", updateInput, checked((a) => runtime.update(a)), false, 60000, "deploy");
|
|
323
331
|
register("start_app", "Start all or selected services as one operation. MCP handles all requests. Waits up to wait_seconds (default 20); remaining execution continues in the background. Started does not mean ready.", lifecycleInput, (a) => runtime.lifecycle("start", a), false, 20000, "project");
|
|
324
332
|
register("stop_app", "Stop all or selected services as one operation. MCP handles all requests. Waits up to wait_seconds (default 20). Stopped means stop requests accepted, not verified teardown.", lifecycleInput, (a) => runtime.lifecycle("stop", a), false, 20000, "project");
|
|
333
|
+
register("delete_resources", "Delete applications (each with all its services), single services, or images of one project, in one call for the whole request. Without confirm it returns what would be deleted (confirm_required), with public URLs and volumes whose data is lost, for the user to approve once; repeat with confirm=true. An image a remaining service uses is kept. Unfinished deployments of affected applications are ended first. Cannot be undone.", deleteInput, (a) => engine.deleteResources(a), false, 60000, "project");
|
|
325
334
|
register("get_deployment", "With deployment_id, observe/wait for background execution; the MCP owns execution. Each call waits up to wait_seconds (default 45, max 50); to wait longer, call again, as often as needed (a loop of get_deployment calls is fine), until execution is finished; do not answer the user while it is still in the background. Services carry status_changes and restarts_seen when the MCP saw the status change or a new container start. After sync_files (or manual upload) set files_uploaded=true; after a new key is saved, checking the job resumes it. With no arguments, returns the map of all deployments: every deployment-enabled project with its applications and services (names, native statuses, public URLs, ports). With desk_url or project_id, returns that project's desks, images, hardware and applications; add application_id for one application. resume=false observes only. Never returns environment-variable values.", getInput, (a) => runtime.get(a), false, 55000, "deploy");
|
|
326
|
-
register("get_logs", "Last lines (default 20, up to
|
|
335
|
+
register("get_logs", "Last lines (default 20, up to 500) of a build or service log: why a build or start failed, how far a long build got, what a starting service prints. Constructor serves logs only live: a build log while the build runs, a service log for its current container while it runs (both replayed from the start, then streamed). The MCP follows the builds it starts until they end, and the services it starts or shows for two hours after that (or after the last get_logs), and keeps their last 2000 lines on this machine for 14 days, so they stay readable after the build ends, the container restarts or the agent restarts; watched says when it followed. Anything else can be read only while it runs. When a new container starts, the lines of the one before stay, above a '--- new container' marker, and restarts_seen counts them: that answers whether a service keeps restarting and why. An empty service log on a running service usually means a crash loop.", logsInput, async (a) => {
|
|
327
336
|
const i = logsInput.parse(a);
|
|
328
337
|
let targets = [];
|
|
329
338
|
if (i.image_id)
|