constructor-research-mcp 0.4.0-beta.3 → 0.4.1
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/INSTALL.md +17 -14
- package/README.md +15 -7
- package/dist/api.d.ts +5 -1
- package/dist/api.js +5 -1
- package/dist/deployment.d.ts +9 -0
- package/dist/deployment.js +66 -7
- package/dist/location.d.ts +1 -1
- package/dist/location.js +3 -7
- package/dist/runtime.js +1 -1
- package/dist/schemas.d.ts +3 -0
- package/dist/schemas.js +17 -3
- package/dist/server.js +65 -18
- package/dist/wait.d.ts +35 -0
- package/dist/wait.js +77 -2
- package/examples/claude-hooks.json +1 -1
- package/examples/claude.mcp.json +1 -1
- package/examples/codex-hooks.json +1 -1
- package/examples/codex.toml +1 -1
- package/examples/opencode-plugin.js +1 -1
- package/examples/opencode-v2.json +1 -1
- package/examples/opencode.json +1 -1
- package/package.json +1 -4
package/INSTALL.md
CHANGED
|
@@ -18,13 +18,13 @@ The key is required: the MCP does nothing without it. The address is `https://co
|
|
|
18
18
|
claude mcp add --scope user constructor-research \
|
|
19
19
|
-e CONSTRUCTOR_BASE_URL=https://constructor.app \
|
|
20
20
|
-e CONSTRUCTOR_ACCESS_KEY=rk-your-key \
|
|
21
|
-
-- npx -y constructor-research-mcp@
|
|
21
|
+
-- npx -y constructor-research-mcp@latest
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
On Windows (not WSL), use this instead:
|
|
25
25
|
|
|
26
26
|
```bat
|
|
27
|
-
claude mcp add --scope user constructor-research -e CONSTRUCTOR_BASE_URL=https://constructor.app -e CONSTRUCTOR_ACCESS_KEY=rk-your-key -- cmd /c npx -y constructor-research-mcp@
|
|
27
|
+
claude mcp add --scope user constructor-research -e CONSTRUCTOR_BASE_URL=https://constructor.app -e CONSTRUCTOR_ACCESS_KEY=rk-your-key -- cmd /c npx -y constructor-research-mcp@latest
|
|
28
28
|
```
|
|
29
29
|
|
|
30
30
|
**Codex**: run once:
|
|
@@ -33,7 +33,7 @@ claude mcp add --scope user constructor-research -e CONSTRUCTOR_BASE_URL=https:/
|
|
|
33
33
|
codex mcp add constructor-research \
|
|
34
34
|
--env CONSTRUCTOR_BASE_URL=https://constructor.app \
|
|
35
35
|
--env CONSTRUCTOR_ACCESS_KEY=rk-your-key \
|
|
36
|
-
-- npx -y constructor-research-mcp@
|
|
36
|
+
-- npx -y constructor-research-mcp@latest
|
|
37
37
|
```
|
|
38
38
|
|
|
39
39
|
The first start downloads the package and can exceed Codex's 10-second start limit. If Codex reports a timeout, restart it once, or add `startup_timeout_sec = 60` under `[mcp_servers.constructor-research]` in `~/.codex/config.toml`. The full entry, if you prefer to write it by hand:
|
|
@@ -41,7 +41,7 @@ The first start downloads the package and can exceed Codex's 10-second start lim
|
|
|
41
41
|
```toml
|
|
42
42
|
[mcp_servers.constructor-research]
|
|
43
43
|
command = "npx"
|
|
44
|
-
args = ["-y", "constructor-research-mcp@
|
|
44
|
+
args = ["-y", "constructor-research-mcp@latest"]
|
|
45
45
|
startup_timeout_sec = 60
|
|
46
46
|
tool_timeout_sec = 30
|
|
47
47
|
|
|
@@ -58,7 +58,7 @@ CONSTRUCTOR_ACCESS_KEY = "rk-your-key"
|
|
|
58
58
|
"mcp": {
|
|
59
59
|
"constructor-research": {
|
|
60
60
|
"type": "local",
|
|
61
|
-
"command": ["npx", "-y", "constructor-research-mcp@
|
|
61
|
+
"command": ["npx", "-y", "constructor-research-mcp@latest"],
|
|
62
62
|
"environment": {
|
|
63
63
|
"CONSTRUCTOR_BASE_URL": "https://constructor.app",
|
|
64
64
|
"CONSTRUCTOR_ACCESS_KEY": "rk-your-key"
|
|
@@ -74,25 +74,28 @@ Then restart the tool, or run `/mcp` in Claude Code, so it starts the MCP. The f
|
|
|
74
74
|
|
|
75
75
|
## 2. Or keep the key out of the tool's settings
|
|
76
76
|
|
|
77
|
-
Step 1 stores the key in the tool's settings file (`~/.claude.json`, `~/.codex/config.toml`, `opencode.json`). To avoid that, add the MCP without the two variables (`claude mcp add --scope user constructor-research -- npx -y constructor-research-mcp@
|
|
77
|
+
Step 1 stores the key in the tool's settings file (`~/.claude.json`, `~/.codex/config.toml`, `opencode.json`). To avoid that, add the MCP without the two variables (`claude mcp add --scope user constructor-research -- npx -y constructor-research-mcp@latest`, and the same for Codex and OpenCode) and save the key in a terminal; it asks for the key without showing it:
|
|
78
78
|
|
|
79
79
|
```sh
|
|
80
|
-
npx -y -p constructor-research-mcp@
|
|
80
|
+
npx -y -p constructor-research-mcp@latest constructor-research-set-key https://constructor.app
|
|
81
81
|
```
|
|
82
82
|
|
|
83
83
|
It checks the key with Constructor and saves it, with that address, to `~/.config/constructor-research/access-key.json` (readable only by you). Claude Code, Codex, OpenCode and the wait hooks all use this one file, and a new key needs no restart. To switch Constructor or replace a revoked key, run it again. A key set in the tool's settings wins over the file. Never paste the key into the chat.
|
|
84
84
|
|
|
85
|
-
## 3.
|
|
85
|
+
## 3. Recommended: wait for builds
|
|
86
86
|
|
|
87
|
-
Builds
|
|
87
|
+
Builds take minutes, and some agents (Codex in particular) end their turn before a build finishes, so the user has to ask again. The wait hook keeps the agent on it until the deployment ends. One command adds it, leaving your other settings and hooks as they are:
|
|
88
88
|
|
|
89
|
-
|
|
90
|
-
-
|
|
91
|
-
-
|
|
89
|
+
```sh
|
|
90
|
+
npx -y -p constructor-research-mcp@latest constructor-research-wait --install codex # ~/.codex/hooks.json
|
|
91
|
+
npx -y -p constructor-research-mcp@latest constructor-research-wait --install claude-code # ~/.claude/settings.json
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Restart the tool; in Codex, trust the new hook in `/hooks`. The hook only watches the deployments the MCP runs, so it works with the key in the MCP settings too. By hand: merge [examples/codex-hooks.json](examples/codex-hooks.json) or [examples/claude-hooks.json](examples/claude-hooks.json). OpenCode: copy [examples/opencode-plugin.js](examples/opencode-plugin.js) to `~/.config/opencode/plugins/`.
|
|
92
95
|
|
|
93
96
|
## Update
|
|
94
97
|
|
|
95
|
-
Restart the tool (or `/mcp` in Claude Code): `@
|
|
98
|
+
Restart the tool (or `/mcp` in Claude Code): `@latest` fetches the newest version on start. Your key is kept.
|
|
96
99
|
|
|
97
100
|
## Troubleshooting
|
|
98
101
|
|
|
@@ -109,7 +112,7 @@ which npx
|
|
|
109
112
|
**Check the MCP on its own.** Run the MCP Inspector, then turn on the server's toggle and open Tools:
|
|
110
113
|
|
|
111
114
|
```sh
|
|
112
|
-
npx @modelcontextprotocol/inspector@2.11.0 -- npx -y constructor-research-mcp@
|
|
115
|
+
npx @modelcontextprotocol/inspector@2.11.0 -- npx -y constructor-research-mcp@latest
|
|
113
116
|
```
|
|
114
117
|
|
|
115
118
|
## Uninstall
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Constructor Research MCP
|
|
2
2
|
|
|
3
|
-
> **
|
|
3
|
+
> **0.4:** works with Constructor's public API and a personal access key (`rk-…`); browser sign-in is gone. On a Constructor without the public API yet, pin the previous version: `constructor-research-mcp@0.3.3`.
|
|
4
4
|
|
|
5
5
|
Local stdio MCP for Codex CLI, Claude Code and OpenCode. Submit the whole application once; the MCP builds images, connects services, configures them and starts them. The agent supplies missing configuration and reports the result.
|
|
6
6
|
|
|
@@ -14,7 +14,7 @@ You need Node.js 22+ and your personal access key (`rk-…`); the MCP does not w
|
|
|
14
14
|
claude mcp add --scope user constructor-research \
|
|
15
15
|
-e CONSTRUCTOR_BASE_URL=https://constructor.app \
|
|
16
16
|
-e CONSTRUCTOR_ACCESS_KEY=rk-your-key \
|
|
17
|
-
-- npx -y constructor-research-mcp@
|
|
17
|
+
-- npx -y constructor-research-mcp@latest
|
|
18
18
|
```
|
|
19
19
|
|
|
20
20
|
**Codex**
|
|
@@ -23,7 +23,7 @@ claude mcp add --scope user constructor-research \
|
|
|
23
23
|
codex mcp add constructor-research \
|
|
24
24
|
--env CONSTRUCTOR_BASE_URL=https://constructor.app \
|
|
25
25
|
--env CONSTRUCTOR_ACCESS_KEY=rk-your-key \
|
|
26
|
-
-- npx -y constructor-research-mcp@
|
|
26
|
+
-- npx -y constructor-research-mcp@latest
|
|
27
27
|
```
|
|
28
28
|
|
|
29
29
|
**OpenCode**: add the entry to `~/.config/opencode/opencode.json` (layouts for 1.x and 2.x in [INSTALL.md](INSTALL.md)).
|
|
@@ -37,7 +37,7 @@ The key then sits in the tool's settings file (`~/.claude.json`, `~/.codex/confi
|
|
|
37
37
|
The MCP uses only a personal access key (`rk-…`) from Constructor's public API; there is no browser sign-in. Every request carries it as `X-Research-AccessKey: Bearer rk-…`, to the account API (`/api/platform-account/v1`), the desk storage (WebDAV) and the logs alike. The key never goes through the chat. It comes from the MCP settings (`CONSTRUCTOR_ACCESS_KEY`, with `CONSTRUCTOR_BASE_URL`, as in Install), or from a key file the user saves in a terminal, where the key is read hidden, checked against Constructor and saved:
|
|
38
38
|
|
|
39
39
|
```sh
|
|
40
|
-
npx -y -p constructor-research-mcp@
|
|
40
|
+
npx -y -p constructor-research-mcp@latest constructor-research-set-key https://acme.constructor.app
|
|
41
41
|
```
|
|
42
42
|
|
|
43
43
|
It goes to `~/.config/constructor-research/access-key.json` (mode 600) together with the Constructor it belongs to, and the MCP works with that Constructor. All harnesses (Claude Code, Codex, OpenCode) and the wait command share this one file. Every request rereads it, so a new key needs no restart. A key is never sent to a Constructor other than the one it was saved for.
|
|
@@ -46,7 +46,7 @@ It goes to `~/.config/constructor-research/access-key.json` (mode 600) together
|
|
|
46
46
|
|
|
47
47
|
Without a key, or when Constructor rejects it (401: revoked, expired or for another Constructor), tools return `needs_key` with the command above; a deployment pauses as `needs_key` and resumes on the next check once a valid key is saved. A desk link from another Constructor returns `wrong_environment`.
|
|
48
48
|
|
|
49
|
-
Deployment must be switched on for the project.
|
|
49
|
+
Deployment must be switched on for the project. When it is off, the MCP switches it on (`POST /projects/{id}/deployment`), which only the project owner may do. For anyone else (error 40005), the operation fails at stage `prepare` with a message asking the project owner to switch it on in Constructor.
|
|
50
50
|
|
|
51
51
|
| Variable | Default |
|
|
52
52
|
| ----------------------------------- | ----------------------------------------------------------------------------------------------- |
|
|
@@ -102,6 +102,12 @@ https://constructor.app/research/projects/<project_id>/desks/<desk_id>/viewer/fi
|
|
|
102
102
|
|
|
103
103
|
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; 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.
|
|
104
104
|
|
|
105
|
+
Given only `project_id`, the MCP finds the desk itself:
|
|
106
|
+
|
|
107
|
+
- one desk in the project: it is used;
|
|
108
|
+
- no desk: `deploy_app`/`update_app` create one (`<application>-source`) for the sources; the file tools return an error;
|
|
109
|
+
- several desks: nothing is changed and the tool returns `desk_choice_required` with each desk's `name`, `id` and `desk_url`. The agent asks the user which one and repeats the call with that link or ID.
|
|
110
|
+
|
|
105
111
|
## Normal deployment flow
|
|
106
112
|
|
|
107
113
|
1. Inspect with `get_deployment`: no arguments returns the map of all deployments (every deployment-enabled project → applications → services with names, native statuses, public URLs and ports; other projects are listed by name only); `desk_url` or `project_id` returns that project's disks, images, hardware and apps; add `application_id` for service details.
|
|
@@ -171,7 +177,9 @@ Private DNS works between containers; browser JavaScript needs a public backend
|
|
|
171
177
|
|
|
172
178
|
### Image reuse and limits
|
|
173
179
|
|
|
174
|
-
Replace a service's `build` with `"image_id":"IMAGE_ID"` to skip building. `list_images` returns compact records with `not_started`, `snapshot_creation`, `in_progress`, `done` or `error
|
|
180
|
+
Replace a service's `build` with `"image_id":"IMAGE_ID"` to skip building, or with `"image":"registry/repo:tag"` to run a ready-made image, such as `jgraph/drawio:latest` from Docker Hub. The agent looks up the repository, tag and port itself; nobody writes a Dockerfile. `list_images` returns compact records with `source` (`desk_build` or `external`), `reference` and `build_status` (`not_started`, `snapshot_creation`, `in_progress`, `done` or `error`); `detailed:true` returns full records.
|
|
181
|
+
|
|
182
|
+
With `image`, the MCP first looks for it in the project (by `reference` or name). External images there (`source: external`) are pulled, not built, so they are used whatever their build status, unless it is `error`. An image the project does not have is built on the desk from a one-line `FROM <image>` Dockerfile that the MCP writes to `.constructor/images/<name>/`, because the public API cannot add an external image yet.
|
|
175
183
|
|
|
176
184
|
- Build storage is omitted by default, using the API's documented **50 GB** default. Explicit `ephemeral_build_disk_size_gb` overrides must be **10–1000 GB**.
|
|
177
185
|
- Each service can have multiple ports (1–65535), with at most **one public port**. That port must match where the container listens.
|
|
@@ -253,7 +261,7 @@ Constructor serves logs only live, as a stream: a build log while the build runs
|
|
|
253
261
|
Builds can run for many minutes. The MCP keeps executing in the background, but an agent that has ended its turn is not told when they finish. `dist/wait.js` (bin `constructor-research-wait`) blocks until the given deployments, or all in-progress ones when no ID is given, finish, and prints one line each: status, message, services with public URLs, next step. Exit codes: `0` finished, `2` needs the user (failed, key, upload, volume confirmation), `3` still running at `--max-minutes` (default 60), `4` nothing in progress.
|
|
254
262
|
|
|
255
263
|
```sh
|
|
256
|
-
npx -y -p constructor-research-mcp@
|
|
264
|
+
npx -y -p constructor-research-mcp@latest constructor-research-wait <deployment_id>
|
|
257
265
|
```
|
|
258
266
|
|
|
259
267
|
It watches the checkpoints the MCP writes. For deployments named by ID, if no process has advanced one for a minute (the MCP was closed), it continues it itself, exactly as the MCP would on restart. Without IDs it only watches, since those deployments may belong to other sessions. While a deployment runs, `next_action` gives the agent the exact command, including the MCP's non-default `CONSTRUCTOR_*` settings; the wait command needs the same settings as the MCP.
|
package/dist/api.d.ts
CHANGED
|
@@ -3,7 +3,11 @@ export declare class ToolError extends Error {
|
|
|
3
3
|
code: string;
|
|
4
4
|
status?: number | undefined;
|
|
5
5
|
apiCode?: number | undefined;
|
|
6
|
-
|
|
6
|
+
/** Extra fields returned to the agent next to status and message. */
|
|
7
|
+
details?: Record<string, unknown> | undefined;
|
|
8
|
+
constructor(code: string, message: string, status?: number | undefined, apiCode?: number | undefined,
|
|
9
|
+
/** Extra fields returned to the agent next to status and message. */
|
|
10
|
+
details?: Record<string, unknown> | undefined);
|
|
7
11
|
}
|
|
8
12
|
export declare const segment: (s: string) => string;
|
|
9
13
|
/** A key as Constructor shows it, with or without the "Bearer " the header adds. */
|
package/dist/api.js
CHANGED
|
@@ -6,11 +6,15 @@ export class ToolError extends Error {
|
|
|
6
6
|
code;
|
|
7
7
|
status;
|
|
8
8
|
apiCode;
|
|
9
|
-
|
|
9
|
+
details;
|
|
10
|
+
constructor(code, message, status, apiCode,
|
|
11
|
+
/** Extra fields returned to the agent next to status and message. */
|
|
12
|
+
details) {
|
|
10
13
|
super(message);
|
|
11
14
|
this.code = code;
|
|
12
15
|
this.status = status;
|
|
13
16
|
this.apiCode = apiCode;
|
|
17
|
+
this.details = details;
|
|
14
18
|
}
|
|
15
19
|
}
|
|
16
20
|
export const segment = (s) => encodeURIComponent(s);
|
package/dist/deployment.d.ts
CHANGED
|
@@ -50,6 +50,15 @@ export declare class DeploymentEngine {
|
|
|
50
50
|
* and wait; it takes about 30-40 s.
|
|
51
51
|
*/
|
|
52
52
|
filesDesk(project: string, id: string): Promise<any>;
|
|
53
|
+
/** An image a service can run: built here, or external (pulled, never built). */
|
|
54
|
+
static usable(im: any): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* The desk to use when the call names only the project: the only desk, a new one
|
|
57
|
+
* when there is none and `create` is given, otherwise the user chooses.
|
|
58
|
+
*/
|
|
59
|
+
deskFor(project: string, create?: string): Promise<string>;
|
|
60
|
+
/** Turn each service's `image` into the project's image_id when the project has it (by reference or name); others are left as `image`. */
|
|
61
|
+
resolveImages(project: string, services: any[]): Promise<any[]>;
|
|
53
62
|
listImages(raw: unknown): Promise<{
|
|
54
63
|
results: any[];
|
|
55
64
|
total: number;
|
package/dist/deployment.js
CHANGED
|
@@ -370,6 +370,57 @@ export class DeploymentEngine {
|
|
|
370
370
|
return d;
|
|
371
371
|
throw new ToolError("not_ready", `The desk's file storage was stopped (desk not used recently), so the MCP started it, as opening the desk in the browser does. It is still ${status ?? "starting"}; this takes about 30-40 s. Nothing was changed. Repeat the same call in a moment.`);
|
|
372
372
|
}
|
|
373
|
+
/** An image a service can run: built here, or external (pulled, never built). */
|
|
374
|
+
static usable(im) {
|
|
375
|
+
return im?.source === "external"
|
|
376
|
+
? im.build_status !== "error"
|
|
377
|
+
: im?.build_status === "done";
|
|
378
|
+
}
|
|
379
|
+
/**
|
|
380
|
+
* The desk to use when the call names only the project: the only desk, a new one
|
|
381
|
+
* when there is none and `create` is given, otherwise the user chooses.
|
|
382
|
+
*/
|
|
383
|
+
async deskFor(project, create) {
|
|
384
|
+
await this.project(project);
|
|
385
|
+
const desks = await this.rows(this.root(project) + "/desks");
|
|
386
|
+
if (desks.length === 1)
|
|
387
|
+
return desks[0].id;
|
|
388
|
+
if (desks.length > 1)
|
|
389
|
+
throw new ToolError("desk_choice_required", `Project ${project} has ${desks.length} desks: ${desks.map((d) => `${d.name} (${d.id})`).join(", ")}. Nothing was changed. Ask the user which desk to use (name or link), then repeat the call with desk_url, or desk_id (build.desk_id for a service).`, undefined, undefined, {
|
|
390
|
+
desks: desks.map((d) => ({
|
|
391
|
+
id: d.id,
|
|
392
|
+
name: d.name,
|
|
393
|
+
desk_url: this.deskLink(project, d.id),
|
|
394
|
+
})),
|
|
395
|
+
});
|
|
396
|
+
if (!create)
|
|
397
|
+
bad(`Project ${project} has no desk. Ask the user to create one in Constructor, or deploy a local folder (deploy_app creates a desk for it).`);
|
|
398
|
+
const d = await this.api.request("POST", this.root(project) + "/desks", {
|
|
399
|
+
name: create,
|
|
400
|
+
});
|
|
401
|
+
return d.id;
|
|
402
|
+
}
|
|
403
|
+
/** Turn each service's `image` into the project's image_id when the project has it (by reference or name); others are left as `image`. */
|
|
404
|
+
async resolveImages(project, services) {
|
|
405
|
+
if (!services?.some((s) => s.image))
|
|
406
|
+
return services;
|
|
407
|
+
const images = await this.images(project);
|
|
408
|
+
return services.map((s) => {
|
|
409
|
+
if (!s.image)
|
|
410
|
+
return s;
|
|
411
|
+
const want = s.image.trim();
|
|
412
|
+
const hits = images.filter((im) => im.reference === want || im.name === want || im.id === want);
|
|
413
|
+
const im = hits.length > 1
|
|
414
|
+
? (hits.find((x) => x.reference === want) ??
|
|
415
|
+
bad(`Image "${want}" for ${s.name} matches several images: ${hits.map((x) => x.id).join(", ")}. Pass image_id.`))
|
|
416
|
+
: hits[0];
|
|
417
|
+
// Not in the project: the caller builds it from a one-line FROM Dockerfile.
|
|
418
|
+
if (!im)
|
|
419
|
+
return s;
|
|
420
|
+
const { image: _i, ...rest } = s;
|
|
421
|
+
return { ...rest, image_id: im.id };
|
|
422
|
+
});
|
|
423
|
+
}
|
|
373
424
|
async listImages(raw) {
|
|
374
425
|
const input = listInput.parse(raw);
|
|
375
426
|
await this.project(input.project_id);
|
|
@@ -387,6 +438,8 @@ export class DeploymentEngine {
|
|
|
387
438
|
dockerfile: x.dockerfile,
|
|
388
439
|
tag: x.tag,
|
|
389
440
|
build_status: x.build_status,
|
|
441
|
+
source: x.source,
|
|
442
|
+
reference: x.reference,
|
|
390
443
|
})),
|
|
391
444
|
total: results.length,
|
|
392
445
|
};
|
|
@@ -512,12 +565,16 @@ export class DeploymentEngine {
|
|
|
512
565
|
input.services.length)
|
|
513
566
|
bad("Service overrides must be unique.");
|
|
514
567
|
const images = op.project_id ? await this.images(op.project_id) : [];
|
|
568
|
+
if (op.project_id)
|
|
569
|
+
input.services = await this.resolveImages(op.project_id, input.services);
|
|
570
|
+
if (input.services.some((s) => s.image))
|
|
571
|
+
bad("In a resume, image must name an image already in the project; for a new registry image, send a new deploy_app or update_app.");
|
|
515
572
|
for (const override of input.services) {
|
|
516
573
|
const at = next.findIndex((s) => s.name === override.name);
|
|
517
574
|
if (at < 0)
|
|
518
575
|
bad("Resume overrides can only change services already in this deployment.");
|
|
519
576
|
if (override.image_id &&
|
|
520
|
-
!images.some((im) => im.id === override.image_id && im
|
|
577
|
+
!images.some((im) => im.id === override.image_id && DeploymentEngine.usable(im)))
|
|
521
578
|
bad("Replacement image is not successfully built in this project.");
|
|
522
579
|
const saved = next[at];
|
|
523
580
|
next[at] = {
|
|
@@ -785,13 +842,15 @@ export class DeploymentEngine {
|
|
|
785
842
|
/** Switches on deployment; when the key may not, the operation stops with what to do instead. */
|
|
786
843
|
async enableDeployment(op, project) {
|
|
787
844
|
try {
|
|
788
|
-
await this.mutate(op, "
|
|
845
|
+
await this.mutate(op, "POST", this.root(project) + "/deployment", { enabled: true }, () => {
|
|
789
846
|
op.status = "preparing";
|
|
790
847
|
});
|
|
791
848
|
}
|
|
792
849
|
catch (err) {
|
|
793
|
-
|
|
794
|
-
|
|
850
|
+
// Only the project owner may switch it on (421, error 40005); older servers answer 403.
|
|
851
|
+
if (err instanceof ToolError &&
|
|
852
|
+
(err.apiCode === 40005 || err.status === 403))
|
|
853
|
+
throw 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);
|
|
795
854
|
throw err;
|
|
796
855
|
}
|
|
797
856
|
}
|
|
@@ -933,8 +992,8 @@ export class DeploymentEngine {
|
|
|
933
992
|
bad(`New service ${s.name} requires image_id or build.`);
|
|
934
993
|
if (s.image_id) {
|
|
935
994
|
const im = images.find((x) => x.id === s.image_id);
|
|
936
|
-
if (!im
|
|
937
|
-
bad(`Image for ${s.name} is missing or not successfully built in this project.`);
|
|
995
|
+
if (!DeploymentEngine.usable(im))
|
|
996
|
+
bad(`Image for ${s.name} is missing, or not successfully built, in this project.`);
|
|
938
997
|
}
|
|
939
998
|
const hw = hardwareFor(s, old);
|
|
940
999
|
if (!hw || !hardware.some((h) => h.id === hw && !h.removed))
|
|
@@ -1235,7 +1294,7 @@ export class DeploymentEngine {
|
|
|
1235
1294
|
? `${this.api.keyHelp("Constructor rejected the access key, or none is set.")} Then call get_deployment with this deployment_id.`
|
|
1236
1295
|
: op.status === "needs_upload"
|
|
1237
1296
|
? "Upload files with sync_files, then call get_deployment with files_uploaded=true."
|
|
1238
|
-
: "Execution continues automatically in the MCP. Keep calling get_deployment with wait_seconds=
|
|
1297
|
+
: "Execution continues automatically in the MCP. Keep calling get_deployment with wait_seconds=45 until it is finished, then tell the user the result; do not orchestrate individual steps.",
|
|
1239
1298
|
};
|
|
1240
1299
|
if (cache) {
|
|
1241
1300
|
op.result = result;
|
package/dist/location.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { z } from "zod";
|
|
|
2
2
|
/** Where a tool acts: a desk (project + desk), a project only, or a deployment-shaped input whose schema already allows a missing project_id. */
|
|
3
3
|
export type Scope = "desk" | "project" | "deploy";
|
|
4
4
|
/** Tool-facing schema: the engine schema plus desk_url, with the IDs it supplies made optional. */
|
|
5
|
-
export declare function located(schema: z.ZodObject<any>,
|
|
5
|
+
export declare function located(schema: z.ZodObject<any>, _scope: Exclude<Scope, "deploy">,
|
|
6
6
|
/** Inside a desk the IDs default to it, so neither a link nor IDs are required. */
|
|
7
7
|
implied?: boolean): z.ZodObject<{
|
|
8
8
|
[x: string]: any;
|
package/dist/location.js
CHANGED
|
@@ -2,7 +2,7 @@ import { ToolError } from "./api.js";
|
|
|
2
2
|
import { VERSION } from "./config.js";
|
|
3
3
|
import { id, deskUrl } from "./schemas.js";
|
|
4
4
|
/** Tool-facing schema: the engine schema plus desk_url, with the IDs it supplies made optional. */
|
|
5
|
-
export function located(schema,
|
|
5
|
+
export function located(schema, _scope,
|
|
6
6
|
/** Inside a desk the IDs default to it, so neither a link nor IDs are required. */
|
|
7
7
|
implied = false) {
|
|
8
8
|
const extended = schema.extend({
|
|
@@ -19,12 +19,8 @@ implied = false) {
|
|
|
19
19
|
desk_url: deskUrl.optional(),
|
|
20
20
|
})
|
|
21
21
|
.refine((x) => !!x.desk_url ||
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
!!x.desk_id ||
|
|
25
|
-
schema.shape.desk_id.safeParse(undefined).success)), scope === "desk"
|
|
26
|
-
? "Provide desk_url (the desk link from the browser) or project_id and desk_id."
|
|
27
|
-
: "Provide desk_url (the desk link from the browser) or project_id.");
|
|
22
|
+
// Without desk_id the MCP picks the project's only desk, or asks which one.
|
|
23
|
+
!!x.project_id, "Provide desk_url (the desk link from the browser) or project_id.");
|
|
28
24
|
}
|
|
29
25
|
function bad(code, message) {
|
|
30
26
|
throw new ToolError(code, message);
|
package/dist/runtime.js
CHANGED
|
@@ -220,7 +220,7 @@ export class DeploymentRuntime {
|
|
|
220
220
|
? "Inspect the uncertain mutation in Constructor before submitting a new operation."
|
|
221
221
|
: terminal.has(op.status)
|
|
222
222
|
? undefined
|
|
223
|
-
: `
|
|
223
|
+
: `NOT FINISHED: do not answer the user yet. Run now, in the foreground: \`${waitCommand(this.engine.api.config, [op.id])}\`. It returns when the deployment ends and prints the public URL or what failed. No shell: call get_deployment with this deployment_id and wait_seconds=45 again, until it is finished.`,
|
|
224
224
|
};
|
|
225
225
|
}
|
|
226
226
|
async wait(id, milliseconds) {
|
package/dist/schemas.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export declare const serviceInput: z.ZodObject<{
|
|
|
18
18
|
name: z.ZodString;
|
|
19
19
|
service_id: z.ZodOptional<z.ZodString>;
|
|
20
20
|
image_id: z.ZodOptional<z.ZodString>;
|
|
21
|
+
image: z.ZodOptional<z.ZodString>;
|
|
21
22
|
build: z.ZodOptional<z.ZodObject<{
|
|
22
23
|
desk_id: z.ZodOptional<z.ZodString>;
|
|
23
24
|
dockerfile: z.ZodOptional<z.ZodString>;
|
|
@@ -66,6 +67,7 @@ export declare const deployInput: z.ZodObject<{
|
|
|
66
67
|
name: z.ZodString;
|
|
67
68
|
service_id: z.ZodOptional<z.ZodString>;
|
|
68
69
|
image_id: z.ZodOptional<z.ZodString>;
|
|
70
|
+
image: z.ZodOptional<z.ZodString>;
|
|
69
71
|
build: z.ZodOptional<z.ZodObject<{
|
|
70
72
|
desk_id: z.ZodOptional<z.ZodString>;
|
|
71
73
|
dockerfile: z.ZodOptional<z.ZodString>;
|
|
@@ -120,6 +122,7 @@ export declare const updateInput: z.ZodObject<{
|
|
|
120
122
|
name: z.ZodString;
|
|
121
123
|
service_id: z.ZodOptional<z.ZodString>;
|
|
122
124
|
image_id: z.ZodOptional<z.ZodString>;
|
|
125
|
+
image: z.ZodOptional<z.ZodString>;
|
|
123
126
|
build: z.ZodOptional<z.ZodObject<{
|
|
124
127
|
desk_id: z.ZodOptional<z.ZodString>;
|
|
125
128
|
dockerfile: z.ZodOptional<z.ZodString>;
|
package/dist/schemas.js
CHANGED
|
@@ -49,6 +49,13 @@ const wait = z
|
|
|
49
49
|
.max(20)
|
|
50
50
|
.default(20)
|
|
51
51
|
.describe("Wait up to this many seconds for completion; execution continues in the MCP after the response.");
|
|
52
|
+
/** get_deployment only: longer, so fewer calls; stays under the 60 s tool timeout of Codex. */
|
|
53
|
+
const longWait = z
|
|
54
|
+
.number()
|
|
55
|
+
.min(0)
|
|
56
|
+
.max(50)
|
|
57
|
+
.default(45)
|
|
58
|
+
.describe("Wait up to this many seconds (max 50) for the deployment to finish; it continues in the MCP after the response.");
|
|
52
59
|
const requestId = z
|
|
53
60
|
.string()
|
|
54
61
|
.min(1)
|
|
@@ -104,6 +111,13 @@ export const serviceInput = z
|
|
|
104
111
|
name: serviceName,
|
|
105
112
|
service_id: id.optional(),
|
|
106
113
|
image_id: id.optional(),
|
|
114
|
+
image: z
|
|
115
|
+
.string()
|
|
116
|
+
.min(1)
|
|
117
|
+
.max(256)
|
|
118
|
+
.regex(/^[a-z0-9][a-z0-9._\/:@-]*$/i, "image is a registry reference such as jgraph/drawio:latest or ghcr.io/org/app:1.2.")
|
|
119
|
+
.optional()
|
|
120
|
+
.describe("Run a ready-made image instead of building your own: a registry reference (docker.io/jgraph/drawio:latest, ghcr.io/org/app:1.2) or the name of an image already in the project. Find the repository and tag yourself (Docker Hub, the project's docs); do not write a Dockerfile for it. If the project already has it (an external image added in Constructor, or a build), it is used as is; otherwise the MCP builds it on the desk from a one-line FROM Dockerfile. Set ports to the port the image listens on (see its docs)."),
|
|
107
121
|
build: build.optional(),
|
|
108
122
|
hardware: z
|
|
109
123
|
.strictObject({
|
|
@@ -121,11 +135,11 @@ export const serviceInput = z
|
|
|
121
135
|
.describe("Plain strings, or {service, port[, scheme]} to point at another service of the same app; never localhost."),
|
|
122
136
|
depends_on: z.array(serviceName).optional(),
|
|
123
137
|
})
|
|
124
|
-
.refine((s) =>
|
|
138
|
+
.refine((s) => [s.image_id, s.image, s.build].filter(Boolean).length <= 1, "Choose one of image_id, image or build.");
|
|
125
139
|
export const deskUrl = z
|
|
126
140
|
.string()
|
|
127
141
|
.max(2048)
|
|
128
|
-
.describe("Link to the Constructor desk the user copied from the browser, e.g. https://constructor.app/research/projects/<project>/desks/<desk>/viewer/file. Supplies project_id and desk_id;
|
|
142
|
+
.describe("Link to the Constructor desk the user copied from the browser, e.g. https://constructor.app/research/projects/<project>/desks/<desk>/viewer/file. Supplies project_id and desk_id. With project_id alone the MCP uses the project's only desk; when the project has several, it asks for this link or desk_id.");
|
|
129
143
|
const deploymentShape = {
|
|
130
144
|
project_id: id.optional(),
|
|
131
145
|
desk_url: deskUrl
|
|
@@ -170,7 +184,7 @@ export const getInput = z
|
|
|
170
184
|
application_id: id.optional(),
|
|
171
185
|
files_uploaded: z.boolean().optional(),
|
|
172
186
|
resume: z.boolean().default(true),
|
|
173
|
-
wait_seconds:
|
|
187
|
+
wait_seconds: longWait,
|
|
174
188
|
})
|
|
175
189
|
.refine((x) => !x.application_id || !!x.project_id || !!x.desk_url, "application_id requires desk_url or project_id.")
|
|
176
190
|
.refine((x) => x.resume || x.files_uploaded === undefined, "files_uploaded cannot be set in observation mode.");
|
package/dist/server.js
CHANGED
|
@@ -7,7 +7,9 @@ import { StateStore } from "./store.js";
|
|
|
7
7
|
import { DeploymentEngine } from "./deployment.js";
|
|
8
8
|
import { DeploymentRuntime } from "./runtime.js";
|
|
9
9
|
import { FileManager, dockerignore } from "./files.js";
|
|
10
|
-
import { basename } from "node:path";
|
|
10
|
+
import { basename, join } from "node:path";
|
|
11
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
12
|
+
import { tmpdir } from "node:os";
|
|
11
13
|
import { LogFollower } from "./logs.js";
|
|
12
14
|
const RULES = "Dockerfile rules: one Dockerfile per service named Dockerfile or <name>.dockerfile; docker-compose is not supported. The Dockerfile must build everything itself; no separate setup script the user runs before the build. The app listens on 0.0.0.0 on a fixed port; only one port per service can be public. Services reach each other through internal references (bare host:port by default, http:// only when scheme is set), never localhost; do not bake compose-style fallback hosts (http://db:5432) into ENV. Files uploaded to a desk lose the executable bit: RUN chmod 0755 any entrypoint script you COPY. In nginx configs use only the IPv4 listen line. A volume belongs to one service; services cannot share a volume. Volume data survives restarts and image changes but is wiped if the service is deleted or the volume is removed or changed. The build context is the folder containing the Dockerfile, exactly like a local docker build in that folder. Test the image locally (docker build/run) before uploading.";
|
|
13
15
|
import { located, resolveDeskUrl } from "./location.js";
|
|
@@ -40,6 +42,42 @@ async function main() {
|
|
|
40
42
|
/** Verify Dockerfiles on their disks before any build; surface lint warnings to the agent. */
|
|
41
43
|
const checked = (fn, single = false) => async (a) => {
|
|
42
44
|
const begun = Date.now();
|
|
45
|
+
if (!single && a.project_id && a.services) {
|
|
46
|
+
// Images the project has by reference or name; builds without a desk go to the project's desk.
|
|
47
|
+
let services = await engine.resolveImages(a.project_id, a.services);
|
|
48
|
+
if (services.some((x) => x.image || (x.build && !x.build.desk_id))) {
|
|
49
|
+
const here = config.localDesk;
|
|
50
|
+
const desk = here && a.project_id === here.projectId
|
|
51
|
+
? here.deskId
|
|
52
|
+
: await engine.deskFor(a.project_id, `${a.application_name ?? "application"}-source`);
|
|
53
|
+
services = await Promise.all(services.map(async (x) => {
|
|
54
|
+
if (x.build && !x.build.desk_id)
|
|
55
|
+
return { ...x, build: { ...x.build, desk_id: desk } };
|
|
56
|
+
if (!x.image)
|
|
57
|
+
return x;
|
|
58
|
+
// A registry image the project does not have: build it from a one-line Dockerfile.
|
|
59
|
+
if (!/^[a-z0-9][a-z0-9._/:@-]*$/i.test(x.image))
|
|
60
|
+
throw new ToolError("invalid_input", `Service ${x.name}: invalid image reference.`);
|
|
61
|
+
const slug = x.image
|
|
62
|
+
.toLowerCase()
|
|
63
|
+
.replace(/[^a-z0-9]+/g, "-")
|
|
64
|
+
.replace(/^-|-$/g, "")
|
|
65
|
+
.slice(0, 80);
|
|
66
|
+
const remote = `.constructor/images/${slug}`;
|
|
67
|
+
const dir = here && desk === here.deskId
|
|
68
|
+
? join(here.root, remote)
|
|
69
|
+
: join(tmpdir(), "constructor-research-images", slug);
|
|
70
|
+
await mkdir(dir, { recursive: true });
|
|
71
|
+
await writeFile(join(dir, "Dockerfile"), `FROM ${x.image}\n`);
|
|
72
|
+
const { image: _i, ...rest } = x;
|
|
73
|
+
return {
|
|
74
|
+
...rest,
|
|
75
|
+
build: { desk_id: desk, local_path: dir, remote_path: remote },
|
|
76
|
+
};
|
|
77
|
+
}));
|
|
78
|
+
}
|
|
79
|
+
a = { ...a, services };
|
|
80
|
+
}
|
|
43
81
|
if (!single && a.services?.some((x) => x.build?.local_path)) {
|
|
44
82
|
// Upload local sources first, once per (disk, local folder, disk folder).
|
|
45
83
|
const done = new Set();
|
|
@@ -156,7 +194,7 @@ async function main() {
|
|
|
156
194
|
? 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) + " ")
|
|
157
195
|
: text;
|
|
158
196
|
const server = new McpServer({ name: "constructor-research", version: VERSION }, {
|
|
159
|
-
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
|
|
197
|
+
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. To run a ready-made image (for example from Docker Hub), pass image with its registry reference (repo:tag); look up the repository, tag and listening port yourself and do not write a Dockerfile for it. The MCP uses the copy in the project when there is one (list_images shows source and reference), otherwise builds it from FROM <image>. 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.`),
|
|
160
198
|
});
|
|
161
199
|
const register = (name, description, schema, fn, readOnly = false, budget = 20000, scope) => {
|
|
162
200
|
const here = config.localDesk && DESK_DEFAULT.has(name) ? config.localDesk : undefined;
|
|
@@ -174,27 +212,35 @@ async function main() {
|
|
|
174
212
|
}, async (args) => {
|
|
175
213
|
try {
|
|
176
214
|
await api.refresh();
|
|
177
|
-
const result = await api.withBudget(budget, () =>
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
args.project_id === here.projectId) &&
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
215
|
+
const result = await api.withBudget(budget, async () => {
|
|
216
|
+
const at = scope
|
|
217
|
+
? resolveDeskUrl(
|
|
218
|
+
// Inside a desk, a call that names no other desk acts on it.
|
|
219
|
+
here &&
|
|
220
|
+
!args?.desk_url &&
|
|
221
|
+
(!args?.project_id || args.project_id === here.projectId) &&
|
|
222
|
+
(!args?.desk_id || args.desk_id === here.deskId)
|
|
223
|
+
? {
|
|
224
|
+
...args,
|
|
225
|
+
desk_url: `${config.baseUrl}/research/projects/${here.projectId}/desks/${here.deskId}`,
|
|
226
|
+
}
|
|
227
|
+
: args, config.baseUrl, scope, config.baseUrlFixed)
|
|
228
|
+
: args;
|
|
229
|
+
// A desk tool given only the project acts on its only desk, or asks which one.
|
|
230
|
+
if (scope === "desk" &&
|
|
231
|
+
name !== "list_images" &&
|
|
232
|
+
at?.project_id &&
|
|
233
|
+
!at.desk_id)
|
|
234
|
+
at.desk_id = await engine.deskFor(at.project_id);
|
|
235
|
+
return fn(at);
|
|
236
|
+
});
|
|
191
237
|
return {
|
|
192
238
|
content: [
|
|
193
239
|
{
|
|
194
240
|
type: "text",
|
|
195
241
|
text: result.text ??
|
|
196
242
|
(result.status
|
|
197
|
-
? `${result.status}${result.deployment_id ? ` (${result.deployment_id})` : ""}${result.message ? `: ${result.message}` : ""}`
|
|
243
|
+
? `${result.status}${result.deployment_id ? ` (${result.deployment_id})` : ""}${result.message ? `: ${result.message}` : ""}${result.execution === "background" && result.next_action ? `\n${result.next_action}` : ""}`
|
|
198
244
|
: `Discovery result: ${result.total !== undefined ? result.total + " images" : Object.keys(result).join(", ")}. See structuredContent for details.`),
|
|
199
245
|
},
|
|
200
246
|
],
|
|
@@ -216,6 +262,7 @@ async function main() {
|
|
|
216
262
|
message: err.message,
|
|
217
263
|
http_status: err.status,
|
|
218
264
|
api_error_code: err.apiCode,
|
|
265
|
+
...err.details,
|
|
219
266
|
}
|
|
220
267
|
: {
|
|
221
268
|
status: "internal_error",
|
|
@@ -242,7 +289,7 @@ async function main() {
|
|
|
242
289
|
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");
|
|
243
290
|
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");
|
|
244
291
|
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");
|
|
245
|
-
register("get_deployment", "With deployment_id, observe/wait for background execution; the MCP owns execution. Each call waits up to wait_seconds (max
|
|
292
|
+
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");
|
|
246
293
|
register("get_logs", "Last lines (default 20, up to 50) 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 and services it starts or shows and keeps their last 50 lines, so they stay readable after the build ends or the container restarts; 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) => {
|
|
247
294
|
const i = logsInput.parse(a);
|
|
248
295
|
let targets = [];
|
package/dist/wait.d.ts
CHANGED
|
@@ -24,3 +24,38 @@ export declare function active(store: StateStore): Promise<string[]>;
|
|
|
24
24
|
export declare function waitFor(runtime: DeploymentRuntime, ids: string[], { maxMs, staleMs, pollMs }: WaitOptions): Promise<WaitResult>;
|
|
25
25
|
/** One line per deployment, for an agent to read. */
|
|
26
26
|
export declare function summary({ results, running }: WaitResult): string;
|
|
27
|
+
declare const HOOKS: {
|
|
28
|
+
readonly codex: {
|
|
29
|
+
readonly file: () => string;
|
|
30
|
+
readonly event: "Stop";
|
|
31
|
+
readonly entry: {
|
|
32
|
+
readonly hooks: readonly [{
|
|
33
|
+
readonly type: "command";
|
|
34
|
+
readonly command: "npx -y -p constructor-research-mcp@latest constructor-research-wait --hook codex";
|
|
35
|
+
readonly timeout: 600;
|
|
36
|
+
readonly statusMessage: "Waiting for Constructor deployments";
|
|
37
|
+
}];
|
|
38
|
+
};
|
|
39
|
+
readonly next: "Restart Codex and trust the new hook in /hooks.";
|
|
40
|
+
};
|
|
41
|
+
readonly "claude-code": {
|
|
42
|
+
readonly file: () => string;
|
|
43
|
+
readonly event: "PostToolUse";
|
|
44
|
+
readonly entry: {
|
|
45
|
+
readonly matcher: "mcp__constructor-research__(deploy_app|update_app|build_image|start_app|stop_app|get_deployment)";
|
|
46
|
+
readonly hooks: readonly [{
|
|
47
|
+
readonly type: "command";
|
|
48
|
+
readonly command: "npx -y -p constructor-research-mcp@latest constructor-research-wait --hook claude-code";
|
|
49
|
+
readonly asyncRewake: true;
|
|
50
|
+
}];
|
|
51
|
+
};
|
|
52
|
+
readonly next: "Restart Claude Code.";
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
/** Add the wait hook to the client's settings once; other settings and hooks stay as they are. */
|
|
56
|
+
export declare function installHook(client: keyof typeof HOOKS, file?: string): Promise<{
|
|
57
|
+
path: string;
|
|
58
|
+
added: boolean;
|
|
59
|
+
next: "Restart Claude Code." | "Restart Codex and trust the new hook in /hooks.";
|
|
60
|
+
}>;
|
|
61
|
+
export {};
|
package/dist/wait.js
CHANGED
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { setTimeout as delay } from "node:timers/promises";
|
|
9
9
|
import { readFile, unlink, writeFile } from "node:fs/promises";
|
|
10
|
-
import { join } from "node:path";
|
|
10
|
+
import { dirname, join } from "node:path";
|
|
11
|
+
import { homedir } from "node:os";
|
|
12
|
+
import { mkdir } from "node:fs/promises";
|
|
11
13
|
import { realpathSync } from "node:fs";
|
|
12
14
|
import { fileURLToPath } from "node:url";
|
|
13
15
|
import { configFromEnv } from "./config.js";
|
|
@@ -129,7 +131,63 @@ async function claim(dir, id) {
|
|
|
129
131
|
}
|
|
130
132
|
return () => unlink(file).catch(() => { });
|
|
131
133
|
}
|
|
134
|
+
/** The hook entry each client needs, as in examples/ (claude-hooks.json, codex-hooks.json). */
|
|
135
|
+
const HOOK = "npx -y -p constructor-research-mcp@latest constructor-research-wait";
|
|
136
|
+
const HOOKS = {
|
|
137
|
+
codex: {
|
|
138
|
+
file: () => join(process.env.CODEX_HOME ?? join(homedir(), ".codex"), "hooks.json"),
|
|
139
|
+
event: "Stop",
|
|
140
|
+
entry: {
|
|
141
|
+
hooks: [
|
|
142
|
+
{
|
|
143
|
+
type: "command",
|
|
144
|
+
command: `${HOOK} --hook codex`,
|
|
145
|
+
timeout: 600,
|
|
146
|
+
statusMessage: "Waiting for Constructor deployments",
|
|
147
|
+
},
|
|
148
|
+
],
|
|
149
|
+
},
|
|
150
|
+
next: "Restart Codex and trust the new hook in /hooks.",
|
|
151
|
+
},
|
|
152
|
+
"claude-code": {
|
|
153
|
+
file: () => join(process.env.CLAUDE_CONFIG_DIR ?? join(homedir(), ".claude"), "settings.json"),
|
|
154
|
+
event: "PostToolUse",
|
|
155
|
+
entry: {
|
|
156
|
+
matcher: "mcp__constructor-research__(deploy_app|update_app|build_image|start_app|stop_app|get_deployment)",
|
|
157
|
+
hooks: [
|
|
158
|
+
{
|
|
159
|
+
type: "command",
|
|
160
|
+
command: `${HOOK} --hook claude-code`,
|
|
161
|
+
asyncRewake: true,
|
|
162
|
+
},
|
|
163
|
+
],
|
|
164
|
+
},
|
|
165
|
+
next: "Restart Claude Code.",
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
/** Add the wait hook to the client's settings once; other settings and hooks stay as they are. */
|
|
169
|
+
export async function installHook(client, file) {
|
|
170
|
+
const h = HOOKS[client];
|
|
171
|
+
const path = file ?? h.file();
|
|
172
|
+
let settings = {};
|
|
173
|
+
try {
|
|
174
|
+
settings = JSON.parse(await readFile(path, "utf8"));
|
|
175
|
+
}
|
|
176
|
+
catch (err) {
|
|
177
|
+
if (err?.code !== "ENOENT")
|
|
178
|
+
throw new Error(`${path} is not valid JSON; nothing was changed.`);
|
|
179
|
+
}
|
|
180
|
+
settings.hooks ??= {};
|
|
181
|
+
const list = (settings.hooks[h.event] ??= []);
|
|
182
|
+
if (JSON.stringify(list).includes("constructor-research-wait"))
|
|
183
|
+
return { path, added: false, next: h.next };
|
|
184
|
+
list.push(h.entry);
|
|
185
|
+
await mkdir(dirname(path), { recursive: true });
|
|
186
|
+
await writeFile(path, JSON.stringify(settings, null, 2) + "\n");
|
|
187
|
+
return { path, added: true, next: h.next };
|
|
188
|
+
}
|
|
132
189
|
const USAGE = `Usage: constructor-research-wait [deployment_id ...] [--max-minutes N] [--hook claude-code|codex|opencode]
|
|
190
|
+
constructor-research-wait --install codex|claude-code
|
|
133
191
|
|
|
134
192
|
Waits until the deployments finish (all in-progress ones when no ID is given) and prints one line each.
|
|
135
193
|
Exit codes: 0 finished, 2 needs the user (failed, key, upload, confirmation), 3 still running at the
|
|
@@ -137,13 +195,30 @@ time limit, 4 nothing to wait for, 1 usage error.
|
|
|
137
195
|
|
|
138
196
|
--hook claude-code PostToolUse hook with asyncRewake: waits for the deployment in the tool result and
|
|
139
197
|
wakes Claude with the outcome (exit 2). opencode: the same, for the plugin.
|
|
140
|
-
--hook codex Stop hook: waits for in-progress deployments, then continues the turn with the outcome
|
|
198
|
+
--hook codex Stop hook: waits for in-progress deployments, then continues the turn with the outcome.
|
|
199
|
+
--install CLIENT Add that hook to ~/.codex/hooks.json or ~/.claude/settings.json (once; nothing else changes).`;
|
|
141
200
|
async function main(argv) {
|
|
142
201
|
const ids = [];
|
|
143
202
|
let hook;
|
|
144
203
|
let minutes;
|
|
145
204
|
for (let i = 0; i < argv.length; i++) {
|
|
146
205
|
const a = argv[i];
|
|
206
|
+
if (a === "--install") {
|
|
207
|
+
const client = argv[++i];
|
|
208
|
+
if (client !== "codex" && client !== "claude-code") {
|
|
209
|
+
console.error(USAGE);
|
|
210
|
+
return EXIT.error;
|
|
211
|
+
}
|
|
212
|
+
try {
|
|
213
|
+
const r = await installHook(client);
|
|
214
|
+
console.log(`${r.added ? "Added the wait hook to" : "The wait hook is already in"} ${r.path}. ${r.next} The hook reads the access key from the key file (constructor-research-set-key), not from the MCP settings.`);
|
|
215
|
+
return EXIT.done;
|
|
216
|
+
}
|
|
217
|
+
catch (err) {
|
|
218
|
+
console.error(err?.message ?? String(err));
|
|
219
|
+
return EXIT.error;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
147
222
|
if (a === "--hook")
|
|
148
223
|
hook = argv[++i];
|
|
149
224
|
else if (a === "--max-minutes")
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"hooks": [
|
|
7
7
|
{
|
|
8
8
|
"type": "command",
|
|
9
|
-
"command": "npx -y -p constructor-research-mcp@
|
|
9
|
+
"command": "npx -y -p constructor-research-mcp@latest constructor-research-wait --hook claude-code",
|
|
10
10
|
"asyncRewake": true
|
|
11
11
|
}
|
|
12
12
|
]
|
package/examples/claude.mcp.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"hooks": [
|
|
6
6
|
{
|
|
7
7
|
"type": "command",
|
|
8
|
-
"command": "npx -y -p constructor-research-mcp@
|
|
8
|
+
"command": "npx -y -p constructor-research-mcp@latest constructor-research-wait --hook codex",
|
|
9
9
|
"timeout": 600,
|
|
10
10
|
"statusMessage": "Waiting for Constructor deployments"
|
|
11
11
|
}
|
package/examples/codex.toml
CHANGED
package/examples/opencode.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "constructor-research-mcp",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Local deployment MCP for Constructor Research",
|
|
6
6
|
"license": "MIT",
|
|
@@ -56,8 +56,5 @@
|
|
|
56
56
|
"prettier": "3.9.10",
|
|
57
57
|
"tsx": "4.23.15",
|
|
58
58
|
"typescript": "7.0.2"
|
|
59
|
-
},
|
|
60
|
-
"publishConfig": {
|
|
61
|
-
"tag": "beta"
|
|
62
59
|
}
|
|
63
60
|
}
|