constructor-research-mcp 0.6.2 → 0.6.4

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 CHANGED
@@ -1,5 +1,9 @@
1
1
  # Constructor Research MCP
2
2
 
3
+ > **0.6.4:** with no project or desk named (and not inside a desk), `deploy_app` creates a new project from a short `project_name` and deploys there.
4
+ >
5
+ > **0.6.3:** `delete_resources` deletes applications, services and images, after the user approves the list.
6
+ >
3
7
  > **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.
4
8
  >
5
9
  > **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`).
@@ -91,28 +95,29 @@ When the MCP runs in VS Code inside a Constructor Research desk, it finds that d
91
95
 
92
96
  `CONSTRUCTOR_LOCAL_DESK=0` turns this off.
93
97
 
94
- ## Thirteen tools
95
-
96
- | Tool | Agent's task |
97
- | ------------------------ | ----------------------------------------------------------------------------------- |
98
- | `deploy_app` | Describe all services in one request, or resume that deployment with overrides. |
99
- | `update_app` | Describe selected changes/additions; the MCP builds and restarts affected services. |
100
- | `start_app` / `stop_app` | Request lifecycle changes for all or selected services. |
101
- | `get_deployment` | Map all deployments, inspect a project or app, or wait for background execution. |
102
- | `get_logs` | Last 10–500 lines of a build or service log (see "Logs"). |
103
- | `build_image` | Build an image independently when needed. |
104
- | `list_images` | List image IDs, Dockerfiles and native build statuses. |
105
- | `list_files` | List a disk's files and folders; `recursive:true` walks subfolders. |
106
- | `create_folder` | Create a disk folder, including missing parents. |
107
- | `sync_files` | Upload new and changed files; asks once before replacing existing files. |
108
- | `move_path` | Rename or move files/folders in one batch, approved once; never overwrites. |
109
- | `delete_path` | Delete files/folders in one batch; reports first, deletes only with `confirm:true`. |
110
-
111
- No special clone/new-instance workflow is implemented. The thirteen tools use the same standard MCP transport across harnesses.
98
+ ## Fourteen tools
99
+
100
+ | Tool | Agent's task |
101
+ | ------------------------ | ---------------------------------------------------------------------------------------------- |
102
+ | `deploy_app` | Describe all services in one request, or resume that deployment with overrides. |
103
+ | `update_app` | Describe selected changes/additions; the MCP builds and restarts affected services. |
104
+ | `start_app` / `stop_app` | Request lifecycle changes for all or selected services. |
105
+ | `delete_resources` | Delete applications, single services or images; lists them first, deletes with `confirm:true`. |
106
+ | `get_deployment` | Map all deployments, inspect a project or app, or wait for background execution. |
107
+ | `get_logs` | Last 10–500 lines of a build or service log (see "Logs"). |
108
+ | `build_image` | Build an image independently when needed. |
109
+ | `list_images` | List image IDs, Dockerfiles and native build statuses. |
110
+ | `list_files` | List a disk's files and folders; `recursive:true` walks subfolders. |
111
+ | `create_folder` | Create a disk folder, including missing parents. |
112
+ | `sync_files` | Upload new and changed files; asks once before replacing existing files. |
113
+ | `move_path` | Rename or move files/folders in one batch, approved once; never overwrites. |
114
+ | `delete_path` | Delete files/folders in one batch; reports first, deletes only with `confirm:true`. |
115
+
116
+ No special clone/new-instance workflow is implemented. The fourteen tools use the same standard MCP transport across harnesses.
112
117
 
113
118
  ## Where to act: the desk link
114
119
 
115
- The agent does not choose a project or desk. It asks the user for the desk link: open the desk in Constructor and copy the browser address, for example
120
+ The agent never picks an existing project itself. It uses the project or desk the user named (now or earlier in the conversation); inside a Constructor desk, that desk is the default. The desk link is the browser address of a desk, for example
116
121
 
117
122
  ```text
118
123
  https://constructor.app/research/projects/<project_id>/desks/<desk_id>/viewer/file
@@ -120,6 +125,14 @@ https://constructor.app/research/projects/<project_id>/desks/<desk_id>/viewer/fi
120
125
 
121
126
  Every tool accepts it as `desk_url`, in place of `project_id`/`desk_id`. Anything after `/desks/<desk_id>` is ignored. The link's host must be the Constructor the key belongs to (inside a desk, the desk's server too); a link from another one returns `wrong_environment` (see the access key above). Explicit IDs, if also sent, must agree with the link. In `deploy_app`/`update_app`, builds without their own `desk_id` use the link's desk; `start_app`/`stop_app` and `get_deployment` take only the project from it.
122
127
 
128
+ **No target at all** (no `desk_url` or `project_id`, and not inside a desk): `deploy_app` returns `no_target`, telling the agent not to ask but to repeat the call with `project_name`, a short name (one to three words) taken from the app, and to tell the user. With `project_name` the MCP then:
129
+
130
+ - creates the project (`POST /projects`, description "Created by the Constructor Research MCP for <app>"); a name already taken gets a number (`todo 2`);
131
+ - waits until it is active and switches deployment on;
132
+ - deploys there as usual (sources go to the project's desk, registry images are added as external images), and the result message carries the project's link.
133
+
134
+ The same request again (same `project_name` and `application_name` within a day) reuses that project instead of creating another: `created-projects.json` in the state directory records each creation before and after the request, so even an interrupted one is adopted. `project_name` is ignored when a project or desk is given.
135
+
123
136
  Given only `project_id`, the MCP finds the desk itself:
124
137
 
125
138
  - one desk in the project: it is used;
@@ -208,7 +221,7 @@ With `image`, the MCP first looks for it in the project (by `reference` or name)
208
221
  ## Missing prerequisites
209
222
 
210
223
  - **No or rejected key:** `needs_key` with the command to save one (see Access key). Save a valid key, then check the same deployment again.
211
- - **No project/disk:** omit `project_id`, optionally supply `project_name`, and use build sources without disk IDs. MCP creates the project/disk and enables deployment tools.
224
+ - **No project/disk:** omit `project_id` and pass `project_name`; the MCP creates the project, switches deployment on and uses or creates its desk (see "Where to act").
212
225
  - **Files absent:** `needs_upload` lists disks and Dockerfile paths. Upload with `sync_files` (or manually), then call `get_deployment` with `deployment_id` and `files_uploaded:true`.
213
226
 
214
227
  Before any build, the MCP reads each Dockerfile from its disk. A missing one returns `dockerfile_missing` and nothing is created. When every build's Dockerfile is present, the upload pause is skipped. The MCP also returns `dockerfile_warnings` (in `message` too) for: a name other than `Dockerfile`/`<name>.dockerfile`, no `FROM`, no `EXPOSE` or a service port that is not exposed, `localhost`/`127.0.0.1` in `ENV`/`ARG`/`CMD`/`ENTRYPOINT`, a docker-compose file next to the Dockerfile, compose-style default hosts in `ENV` (`http://cerbos:3592`, `temporal:7233`), an `ENTRYPOINT`/`CMD` script copied from the build context with no `chmod` (files uploaded to a desk lose the executable bit, so such a container exits before printing anything), and `listen [::]` in an nginx `.conf`/`.template` the Dockerfile copies (nginx exits where the cluster has no IPv6). The same rules are in the tool descriptions, so agents see them before writing a Dockerfile. An existing project with a conflicting name requires an explicit ID; the MCP does not guess.
@@ -228,6 +241,15 @@ Successful builds and unchanged service definitions are retained. Environment ov
228
241
 
229
242
  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.
230
243
 
244
+ ## Deleting applications, services and images
245
+
246
+ `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:
247
+
248
+ - ends unfinished deployments of the affected applications (`superseded`), so none of them recreates what is deleted;
249
+ - deletes services, then applications, then images (an image is free once its services are gone);
250
+ - 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`);
251
+ - reports each item as `deleted`, `already_gone`, `failed` or `uncertain` (`status: partial` when any was not deleted).
252
+
231
253
  ## Service links and volumes
232
254
 
233
255
  - 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.
@@ -66,6 +66,76 @@ export declare class DeploymentEngine {
66
66
  * has no such endpoint yet (the caller then builds it from FROM).
67
67
  */
68
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;
@@ -88,6 +158,20 @@ export declare class DeploymentEngine {
88
158
  get(raw: unknown): Promise<any>;
89
159
  private mutate;
90
160
  private advance;
161
+ /**
162
+ * Creates a project for a deployment that has no target (no project or desk named, not
163
+ * running inside a desk), switches deployment on and returns it. Repeating the same
164
+ * request (same name and application within a day) returns the same project: a ledger in
165
+ * the state directory records the creation before and after the request, so a crash in
166
+ * between adopts the project instead of creating a second one. A name already taken by
167
+ * another project gets a number ("todo 2").
168
+ */
169
+ createProject(name: string, application?: string): Promise<{
170
+ id: string;
171
+ name: string;
172
+ url: string;
173
+ created: boolean;
174
+ }>;
91
175
  /** Switches on deployment; when the key may not, the operation stops with what to do instead. */
92
176
  private enableDeployment;
93
177
  /**
@@ -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",
@@ -462,6 +462,198 @@ export class DeploymentEngine {
462
462
  throw err;
463
463
  }
464
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
+ }
465
657
  async listImages(raw) {
466
658
  const input = listInput.parse(raw);
467
659
  await this.project(input.project_id);
@@ -880,6 +1072,74 @@ export class DeploymentEngine {
880
1072
  return this.view(op);
881
1073
  }
882
1074
  }
1075
+ /**
1076
+ * Creates a project for a deployment that has no target (no project or desk named, not
1077
+ * running inside a desk), switches deployment on and returns it. Repeating the same
1078
+ * request (same name and application within a day) returns the same project: a ledger in
1079
+ * the state directory records the creation before and after the request, so a crash in
1080
+ * between adopts the project instead of creating a second one. A name already taken by
1081
+ * another project gets a number ("todo 2").
1082
+ */
1083
+ async createProject(name, application) {
1084
+ const wanted = name.trim().replace(/\s+/g, " ");
1085
+ const key = createHash("sha256")
1086
+ .update(`${this.store.endpoint}|${wanted}|${application ?? ""}`)
1087
+ .digest("hex");
1088
+ const link = (id) => `${this.api.config.baseUrl}/research/projects/${id}`;
1089
+ const found = await this.store.exclusive(async () => {
1090
+ const ledger = await this.store.created();
1091
+ const day = 24 * 60 * 60 * 1000;
1092
+ for (const k of Object.keys(ledger))
1093
+ if (Date.now() - ledger[k].at > day)
1094
+ delete ledger[k];
1095
+ const seen = ledger[key];
1096
+ const all = await this.rows("/projects");
1097
+ if (seen) {
1098
+ // Created before, or interrupted after asking Constructor: adopt that project.
1099
+ const mine = seen.project_id
1100
+ ? all.find((p) => p.id === seen.project_id)
1101
+ : all.find((p) => p.name === seen.name &&
1102
+ Date.parse(p.created_at ?? "") >= seen.at - 60000);
1103
+ if (mine && !mine.archived) {
1104
+ ledger[key] = { ...seen, project_id: mine.id };
1105
+ await this.store.saveCreated(ledger);
1106
+ return { project: mine, created: false };
1107
+ }
1108
+ }
1109
+ const taken = new Set(all.map((p) => p.name));
1110
+ let unique = wanted;
1111
+ for (let n = 2; taken.has(unique); n++)
1112
+ unique = `${wanted} ${n}`;
1113
+ ledger[key] = { name: unique, at: Date.now() };
1114
+ await this.store.saveCreated(ledger);
1115
+ const project = await this.api.request("POST", "/projects", {
1116
+ name: unique,
1117
+ description: `Created by the Constructor Research MCP${application ? ` for ${application}` : ""}.`,
1118
+ });
1119
+ if (!/^[a-zA-Z0-9_-]{4,128}$/.test(project?.id ?? ""))
1120
+ throw new ToolError("uncertain_outcome", "Creating the project returned no project ID. Check the user's projects (get_deployment) before trying again.");
1121
+ ledger[key] = {
1122
+ name: unique,
1123
+ at: ledger[key].at,
1124
+ project_id: project.id,
1125
+ };
1126
+ await this.store.saveCreated(ledger);
1127
+ return { project, created: true };
1128
+ });
1129
+ // A new project may take a moment to become active.
1130
+ let project = found.project;
1131
+ for (let i = 0; i < 20 && project.status && project.status !== "active"; i++) {
1132
+ await delay(1000);
1133
+ project = await this.project(project.id);
1134
+ }
1135
+ await this.ensureDeployment(project.id, project.deployment_enabled);
1136
+ return {
1137
+ id: project.id,
1138
+ name: project.name,
1139
+ url: link(project.id),
1140
+ created: found.created,
1141
+ };
1142
+ }
883
1143
  /** Switches on deployment; when the key may not, the operation stops with what to do instead. */
884
1144
  async enableDeployment(op, project) {
885
1145
  try {
@@ -985,19 +1245,9 @@ export class DeploymentEngine {
985
1245
  }
986
1246
  async advanceApp(op) {
987
1247
  const input = op.input;
988
- // For a new project all sources must be builds; image IDs are project-scoped.
989
- if (!op.project_id) {
990
- if (input.services.some((s) => !s.build || s.build.desk_id || s.service_id))
991
- bad("A new project requires build sources without existing disk/service IDs.");
992
- const matches = (await this.rows("/projects")).filter((p) => p.name === (input.project_name ?? input.application_name));
993
- if (matches.length)
994
- bad("A project with this name exists. Discover its ID with get_deployment before proceeding.");
995
- await this.mutate(op, "POST", "/projects", { name: input.project_name ?? input.application_name }, (p) => {
996
- op.project_id = p.id;
997
- op.status = "preparing";
998
- });
999
- return this.view(op);
1000
- }
1248
+ // A new project is created before the operation (createProject), so one is always set.
1249
+ if (!op.project_id)
1250
+ bad("No project: pass desk_url or project_id, or project_name to create a new project.");
1001
1251
  const project = await this.project(op.project_id);
1002
1252
  if (project.status && project.status !== "active")
1003
1253
  throw new ToolError("not_ready", "Project is not active yet; retry later.");
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
@@ -145,7 +145,9 @@ const deploymentShape = {
145
145
  desk_url: deskUrl
146
146
  .optional()
147
147
  .describe("Desk link from the user: sets project_id and the desk for builds without desk_id."),
148
- project_name: name.optional(),
148
+ project_name: name
149
+ .optional()
150
+ .describe("Only when the user named no project or desk: a short name (one to three words, from the app) for a NEW project. The MCP creates it, switches deployment on and deploys there; tell the user. Ignored when a project or desk is given."),
149
151
  application_name: name.optional(),
150
152
  services: z.array(serviceInput).min(1).optional(),
151
153
  files_uploaded: z.boolean().default(false),
@@ -227,6 +229,25 @@ const confirm = z
227
229
  .boolean()
228
230
  .default(false)
229
231
  .describe("false (default) returns the full list for the user to approve once; true performs it.");
232
+ export const deleteInput = z.strictObject({
233
+ project_id: id,
234
+ application_ids: z
235
+ .array(id)
236
+ .max(20)
237
+ .optional()
238
+ .describe("Applications to delete, each with all its services."),
239
+ service_ids: z
240
+ .array(id)
241
+ .max(50)
242
+ .optional()
243
+ .describe("Services to delete; the rest of their application stays (services[].id in get_deployment)."),
244
+ image_ids: z
245
+ .array(id)
246
+ .max(50)
247
+ .optional()
248
+ .describe("Images to delete (list_images). An image a remaining service uses is kept."),
249
+ confirm,
250
+ });
230
251
  export const movePathInput = z.strictObject({
231
252
  project_id: id,
232
253
  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);
@@ -53,6 +54,21 @@ async function main() {
53
54
  };
54
55
  const prepared = async (fn, single, a, notes) => {
55
56
  const begun = Date.now();
57
+ // No target anywhere: a new project, named by the agent, or a clear ask for that name.
58
+ if (!single && !a.project_id && !a.deployment_id && a.services) {
59
+ if (!a.project_name?.trim())
60
+ throw new ToolError("no_target", "No target for this deployment: no desk_url or project_id, and this MCP does not run inside a Constructor desk. If the user named a project or desk earlier in the conversation, pass it. Otherwise do not ask: repeat the same call with project_name, a short name (one to three words, from the app) for a new project, and tell the user that a new Constructor project with that name is created for the app.");
61
+ const p = await engine.createProject(a.project_name, a.application_name);
62
+ notes.push(p.created
63
+ ? `Created a new Constructor project "${p.name}" for this app, with deployment on: ${p.url}. Tell the user.`
64
+ : `Deploying to the project "${p.name}" this MCP created for this app earlier: ${p.url}.`);
65
+ const { project_name: _n, ...rest } = a;
66
+ a = { ...rest, project_id: p.id };
67
+ }
68
+ else if (!single && a.project_name && a.project_id) {
69
+ const { project_name: _n, ...rest } = a;
70
+ a = rest;
71
+ }
56
72
  if (!single && a.project_id && a.services) {
57
73
  // Images the project has (by reference or name) are used as they are. Any other
58
74
  // registry image is added to the project as an external image: no desk, no build.
@@ -229,10 +245,10 @@ async function main() {
229
245
  };
230
246
  /** Inside a desk, the agent edits its files in place instead of asking for a desk link. */
231
247
  const withDesk = (text) => config.localDesk
232
- ? 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) + " ")
248
+ ? text.replace(/Where to act: use the project or desk the user named.*?is created for the app\. /, deskInstructions(config.localDesk) + " ")
233
249
  : text;
234
250
  const server = new McpServer({ name: "constructor-research", version: VERSION }, {
235
- 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.`),
251
+ 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: use the project or desk the user named, now or earlier in the conversation; a desk link (the browser address of a desk, with /projects/<project>/desks/<desk>) goes in desk_url. Do not pick an existing project yourself. When the user named none, do not ask: call deploy_app with project_name, a short name (one to three words, from the app), and the MCP creates a new project with deployment on; tell the user a new Constructor project with that name is created for the app. 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.`),
236
252
  });
237
253
  const register = (name, description, schema, fn, readOnly = false, budget = 20000, scope) => {
238
254
  const here = config.localDesk && DESK_DEFAULT.has(name) ? config.localDesk : undefined;
@@ -329,6 +345,7 @@ async function main() {
329
345
  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");
330
346
  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");
331
347
  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");
348
+ 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");
332
349
  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");
333
350
  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) => {
334
351
  const i = logsInput.parse(a);
package/dist/store.d.ts CHANGED
@@ -81,6 +81,13 @@ export declare class StateStore {
81
81
  lastBeat(id: string): Promise<number>;
82
82
  private alive;
83
83
  save(op: Operation): Promise<void>;
84
+ /** Projects this MCP created for deployments without a target, by request key. */
85
+ created(): Promise<Record<string, {
86
+ name: string;
87
+ at: number;
88
+ project_id?: string;
89
+ }>>;
90
+ saveCreated(ledger: Record<string, unknown>): Promise<void>;
84
91
  exclusive<T>(fn: () => Promise<T>): Promise<T>;
85
92
  }
86
93
  /**
package/dist/store.js CHANGED
@@ -73,6 +73,25 @@ export class StateStore {
73
73
  });
74
74
  await rename(tmp, target);
75
75
  }
76
+ /** Projects this MCP created for deployments without a target, by request key. */
77
+ async created() {
78
+ try {
79
+ const data = JSON.parse(await readFile(join(this.config.stateDir, "created-projects.json"), "utf8"));
80
+ return data && typeof data === "object" ? data : {};
81
+ }
82
+ catch {
83
+ return {};
84
+ }
85
+ }
86
+ async saveCreated(ledger) {
87
+ await this.init();
88
+ const target = join(this.config.stateDir, "created-projects.json"), tmp = target + "." + randomUUID() + ".tmp";
89
+ await writeFile(tmp, JSON.stringify(ledger, null, 2), {
90
+ mode: 0o600,
91
+ flag: "wx",
92
+ });
93
+ await rename(tmp, target);
94
+ }
76
95
  async exclusive(fn) {
77
96
  await this.init();
78
97
  const lock = join(this.config.stateDir, ".lock");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "constructor-research-mcp",
3
- "version": "0.6.2",
3
+ "version": "0.6.4",
4
4
  "type": "module",
5
5
  "description": "Local deployment MCP for Constructor Research",
6
6
  "license": "MIT",