constructor-research-mcp 0.6.3 → 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,7 @@
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
+ >
3
5
  > **0.6.3:** `delete_resources` deletes applications, services and images, after the user approves the list.
4
6
  >
5
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.
@@ -115,7 +117,7 @@ No special clone/new-instance workflow is implemented. The fourteen tools use th
115
117
 
116
118
  ## Where to act: the desk link
117
119
 
118
- 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
119
121
 
120
122
  ```text
121
123
  https://constructor.app/research/projects/<project_id>/desks/<desk_id>/viewer/file
@@ -123,6 +125,14 @@ https://constructor.app/research/projects/<project_id>/desks/<desk_id>/viewer/fi
123
125
 
124
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.
125
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
+
126
136
  Given only `project_id`, the MCP finds the desk itself:
127
137
 
128
138
  - one desk in the project: it is used;
@@ -211,7 +221,7 @@ With `image`, the MCP first looks for it in the project (by `reference` or name)
211
221
  ## Missing prerequisites
212
222
 
213
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.
214
- - **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").
215
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`.
216
226
 
217
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.
@@ -158,6 +158,20 @@ export declare class DeploymentEngine {
158
158
  get(raw: unknown): Promise<any>;
159
159
  private mutate;
160
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
+ }>;
161
175
  /** Switches on deployment; when the key may not, the operation stops with what to do instead. */
162
176
  private enableDeployment;
163
177
  /**
@@ -1072,6 +1072,74 @@ export class DeploymentEngine {
1072
1072
  return this.view(op);
1073
1073
  }
1074
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
+ }
1075
1143
  /** Switches on deployment; when the key may not, the operation stops with what to do instead. */
1076
1144
  async enableDeployment(op, project) {
1077
1145
  try {
@@ -1177,19 +1245,9 @@ export class DeploymentEngine {
1177
1245
  }
1178
1246
  async advanceApp(op) {
1179
1247
  const input = op.input;
1180
- // For a new project all sources must be builds; image IDs are project-scoped.
1181
- if (!op.project_id) {
1182
- if (input.services.some((s) => !s.build || s.build.desk_id || s.service_id))
1183
- bad("A new project requires build sources without existing disk/service IDs.");
1184
- const matches = (await this.rows("/projects")).filter((p) => p.name === (input.project_name ?? input.application_name));
1185
- if (matches.length)
1186
- bad("A project with this name exists. Discover its ID with get_deployment before proceeding.");
1187
- await this.mutate(op, "POST", "/projects", { name: input.project_name ?? input.application_name }, (p) => {
1188
- op.project_id = p.id;
1189
- op.status = "preparing";
1190
- });
1191
- return this.view(op);
1192
- }
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.");
1193
1251
  const project = await this.project(op.project_id);
1194
1252
  if (project.status && project.status !== "active")
1195
1253
  throw new ToolError("not_ready", "Project is not active yet; retry later.");
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),
package/dist/server.js CHANGED
@@ -54,6 +54,21 @@ async function main() {
54
54
  };
55
55
  const prepared = async (fn, single, a, notes) => {
56
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
+ }
57
72
  if (!single && a.project_id && a.services) {
58
73
  // Images the project has (by reference or name) are used as they are. Any other
59
74
  // registry image is added to the project as an external image: no desk, no build.
@@ -230,10 +245,10 @@ async function main() {
230
245
  };
231
246
  /** Inside a desk, the agent edits its files in place instead of asking for a desk link. */
232
247
  const withDesk = (text) => config.localDesk
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) + " ")
248
+ ? text.replace(/Where to act: use the project or desk the user named.*?is created for the app\. /, deskInstructions(config.localDesk) + " ")
234
249
  : text;
235
250
  const server = new McpServer({ name: "constructor-research", version: VERSION }, {
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.`),
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.`),
237
252
  });
238
253
  const register = (name, description, schema, fn, readOnly = false, budget = 20000, scope) => {
239
254
  const here = config.localDesk && DESK_DEFAULT.has(name) ? config.localDesk : undefined;
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.3",
3
+ "version": "0.6.4",
4
4
  "type": "module",
5
5
  "description": "Local deployment MCP for Constructor Research",
6
6
  "license": "MIT",