constructor-research-mcp 0.4.0-beta.1 → 0.4.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/INSTALL.md +29 -25
- package/README.md +26 -16
- package/dist/config.d.ts +3 -0
- package/dist/config.js +6 -2
- package/dist/desk.d.ts +23 -0
- package/dist/desk.js +52 -0
- package/dist/files.d.ts +6 -0
- package/dist/files.js +45 -0
- package/dist/location.d.ts +3 -1
- package/dist/location.js +11 -2
- package/dist/server.js +56 -3
- package/package.json +1 -1
package/INSTALL.md
CHANGED
|
@@ -8,24 +8,32 @@ The MCP lets Claude Code, Codex or OpenCode deploy apps to Constructor Research:
|
|
|
8
8
|
- a personal access key (`rk-…`) for your Constructor
|
|
9
9
|
- macOS, Windows or Linux
|
|
10
10
|
|
|
11
|
-
## 1. Add it to your tool
|
|
11
|
+
## 1. Add it to your tool, with your key
|
|
12
|
+
|
|
13
|
+
The key is required: the MCP does nothing without it. The address is `https://constructor.app`; if your organisation has its own Constructor, use its address instead (e.g. `https://acme.constructor.app`). Replace `rk-your-key` with your key.
|
|
12
14
|
|
|
13
15
|
**Claude Code**: run once:
|
|
14
16
|
|
|
15
17
|
```sh
|
|
16
|
-
claude mcp add --scope user constructor-research
|
|
18
|
+
claude mcp add --scope user constructor-research \
|
|
19
|
+
-e CONSTRUCTOR_BASE_URL=https://constructor.app \
|
|
20
|
+
-e CONSTRUCTOR_ACCESS_KEY=rk-your-key \
|
|
21
|
+
-- npx -y constructor-research-mcp@beta
|
|
17
22
|
```
|
|
18
23
|
|
|
19
24
|
On Windows (not WSL), use this instead:
|
|
20
25
|
|
|
21
26
|
```bat
|
|
22
|
-
claude mcp add --scope user constructor-research -- cmd /c npx -y constructor-research-mcp@beta
|
|
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@beta
|
|
23
28
|
```
|
|
24
29
|
|
|
25
30
|
**Codex**: run once:
|
|
26
31
|
|
|
27
32
|
```sh
|
|
28
|
-
codex mcp add constructor-research
|
|
33
|
+
codex mcp add constructor-research \
|
|
34
|
+
--env CONSTRUCTOR_BASE_URL=https://constructor.app \
|
|
35
|
+
--env CONSTRUCTOR_ACCESS_KEY=rk-your-key \
|
|
36
|
+
-- npx -y constructor-research-mcp@beta
|
|
29
37
|
```
|
|
30
38
|
|
|
31
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:
|
|
@@ -36,21 +44,13 @@ command = "npx"
|
|
|
36
44
|
args = ["-y", "constructor-research-mcp@beta"]
|
|
37
45
|
startup_timeout_sec = 60
|
|
38
46
|
tool_timeout_sec = 30
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
**OpenCode**: run once; it adds the entry to your OpenCode config and keeps what is already there. Check your version with `opencode --version`. OpenCode 2.x:
|
|
42
|
-
|
|
43
|
-
```sh
|
|
44
|
-
opencode mcp add --global constructor-research -- npx -y constructor-research-mcp@beta
|
|
45
|
-
```
|
|
46
47
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
opencode mcp add constructor-research -- npx -y constructor-research-mcp@beta
|
|
48
|
+
[mcp_servers.constructor-research.env]
|
|
49
|
+
CONSTRUCTOR_BASE_URL = "https://constructor.app"
|
|
50
|
+
CONSTRUCTOR_ACCESS_KEY = "rk-your-key"
|
|
51
51
|
```
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
**OpenCode**: add the entry to `~/.config/opencode/opencode.json` (or a project's `opencode.json`), keeping what is already there. Check your version with `opencode --version`. OpenCode 1.x:
|
|
54
54
|
|
|
55
55
|
```json
|
|
56
56
|
{
|
|
@@ -58,29 +58,33 @@ Or add it by hand to `~/.config/opencode/opencode.json` (or a project's `opencod
|
|
|
58
58
|
"mcp": {
|
|
59
59
|
"constructor-research": {
|
|
60
60
|
"type": "local",
|
|
61
|
-
"command": ["npx", "-y", "constructor-research-mcp@beta"]
|
|
61
|
+
"command": ["npx", "-y", "constructor-research-mcp@beta"],
|
|
62
|
+
"environment": {
|
|
63
|
+
"CONSTRUCTOR_BASE_URL": "https://constructor.app",
|
|
64
|
+
"CONSTRUCTOR_ACCESS_KEY": "rk-your-key"
|
|
65
|
+
}
|
|
62
66
|
}
|
|
63
67
|
}
|
|
64
68
|
}
|
|
65
69
|
```
|
|
66
70
|
|
|
67
|
-
|
|
71
|
+
In 2.x the entry goes one level deeper, under `mcp.servers`, as in [examples/opencode-v2.json](examples/opencode-v2.json), with the same `environment`.
|
|
72
|
+
|
|
73
|
+
Then restart the tool, or run `/mcp` in Claude Code, so it starts the MCP. The first start downloads it and can take a minute.
|
|
68
74
|
|
|
69
|
-
## 2.
|
|
75
|
+
## 2. Or keep the key out of the tool's settings
|
|
70
76
|
|
|
71
|
-
|
|
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@beta`, and the same for Codex and OpenCode) and save the key in a terminal; it asks for the key without showing it:
|
|
72
78
|
|
|
73
79
|
```sh
|
|
74
|
-
npx -y -p constructor-research-mcp@beta constructor-research-set-key https://
|
|
80
|
+
npx -y -p constructor-research-mcp@beta constructor-research-set-key https://constructor.app
|
|
75
81
|
```
|
|
76
82
|
|
|
77
|
-
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 and
|
|
78
|
-
|
|
79
|
-
Then restart the tool, or run `/mcp` in Claude Code, so it starts the MCP. The first start downloads it and can take a minute.
|
|
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.
|
|
80
84
|
|
|
81
85
|
## 3. Optional: get told when a deployment finishes
|
|
82
86
|
|
|
83
|
-
Builds can take many minutes. These add-ons wake the agent when a deployment it started finishes:
|
|
87
|
+
Builds can take many minutes. These add-ons wake the agent when a deployment it started finishes. They do not see the MCP settings: with the key in step 1, also save it with `set-key` (step 2), or give the hooks the same two variables.
|
|
84
88
|
|
|
85
89
|
- Claude Code: merge [examples/claude-hooks.json](examples/claude-hooks.json) into `~/.claude/settings.json`.
|
|
86
90
|
- Codex: copy [examples/codex-hooks.json](examples/codex-hooks.json) to `~/.codex/hooks.json`, then trust it in `/hooks`.
|
package/README.md
CHANGED
|
@@ -6,37 +6,35 @@ Local stdio MCP for Codex CLI, Claude Code and OpenCode. Submit the whole applic
|
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
9
|
-
You need Node.js 22
|
|
9
|
+
You need Node.js 22+ and your personal access key (`rk-…`); the MCP does not work without it. Add the MCP with the key; the address is `https://constructor.app` unless your organisation has its own Constructor (e.g. `https://acme.constructor.app`).
|
|
10
10
|
|
|
11
11
|
**Claude Code**
|
|
12
12
|
|
|
13
13
|
```sh
|
|
14
|
-
claude mcp add --scope user constructor-research
|
|
14
|
+
claude mcp add --scope user constructor-research \
|
|
15
|
+
-e CONSTRUCTOR_BASE_URL=https://constructor.app \
|
|
16
|
+
-e CONSTRUCTOR_ACCESS_KEY=rk-your-key \
|
|
17
|
+
-- npx -y constructor-research-mcp@beta
|
|
15
18
|
```
|
|
16
19
|
|
|
17
20
|
**Codex**
|
|
18
21
|
|
|
19
22
|
```sh
|
|
20
|
-
codex mcp add constructor-research
|
|
23
|
+
codex mcp add constructor-research \
|
|
24
|
+
--env CONSTRUCTOR_BASE_URL=https://constructor.app \
|
|
25
|
+
--env CONSTRUCTOR_ACCESS_KEY=rk-your-key \
|
|
26
|
+
-- npx -y constructor-research-mcp@beta
|
|
21
27
|
```
|
|
22
28
|
|
|
23
|
-
**OpenCode 2.x
|
|
29
|
+
**OpenCode**: add the entry to `~/.config/opencode/opencode.json` (layouts for 1.x and 2.x in [INSTALL.md](INSTALL.md)).
|
|
24
30
|
|
|
25
|
-
|
|
26
|
-
opencode mcp add --global constructor-research -- npx -y constructor-research-mcp@beta
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
**OpenCode 1.x** (no `--global` there):
|
|
30
|
-
|
|
31
|
-
```sh
|
|
32
|
-
opencode mcp add constructor-research -- npx -y constructor-research-mcp@beta
|
|
33
|
-
```
|
|
31
|
+
Then restart the tool and ask the agent anything about Constructor. Windows notes, the optional wake-up hooks and troubleshooting are in [INSTALL.md](INSTALL.md). Restarting the tool picks up a new version.
|
|
34
32
|
|
|
35
|
-
|
|
33
|
+
The key then sits in the tool's settings file (`~/.claude.json`, `~/.codex/config.toml`, `opencode.json`). To keep it out of there, add the MCP without the two variables and save the key with `set-key` (below).
|
|
36
34
|
|
|
37
35
|
## Access key and connection
|
|
38
36
|
|
|
39
|
-
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
|
|
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:
|
|
40
38
|
|
|
41
39
|
```sh
|
|
42
40
|
npx -y -p constructor-research-mcp@beta constructor-research-set-key https://acme.constructor.app
|
|
@@ -44,7 +42,7 @@ npx -y -p constructor-research-mcp@beta constructor-research-set-key https://acm
|
|
|
44
42
|
|
|
45
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
44
|
|
|
47
|
-
|
|
45
|
+
`CONSTRUCTOR_ACCESS_KEY` in the MCP settings takes precedence over the file. The wait hooks do not see the MCP settings: with the key there, give the hooks the same two variables in their own environment, or save the key with `set-key` as well.
|
|
48
46
|
|
|
49
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`.
|
|
50
48
|
|
|
@@ -57,12 +55,24 @@ Deployment must be switched on for the project. If it is off and the key may not
|
|
|
57
55
|
| `CONSTRUCTOR_STORAGE_PATH` | `/api/platform-storage` |
|
|
58
56
|
| `CONSTRUCTOR_ACCESS_KEY` | unset: the key file is used |
|
|
59
57
|
| `CONSTRUCTOR_KEY_FILE` | `~/.config/constructor-research/access-key.json` |
|
|
58
|
+
| `CONSTRUCTOR_DESK_ROOT` | `~/project` (inside a desk only) |
|
|
60
59
|
| `CONSTRUCTOR_STATE_DIR` | `~/.local/state/constructor-research-mcp` |
|
|
61
60
|
| `CONSTRUCTOR_UPLOAD_SETTLE_SECONDS` | `30` |
|
|
62
61
|
| `CONSTRUCTOR_READINESS_SECONDS` | `60` |
|
|
63
62
|
|
|
64
63
|
HTTPS is required except on localhost.
|
|
65
64
|
|
|
65
|
+
## Inside a Constructor desk (VS Code)
|
|
66
|
+
|
|
67
|
+
When the MCP runs in VS Code inside a Constructor Research desk, it finds that desk from the environment Constructor sets there (`ROLOS_PROJECT_ID`/`RESEARCH_PROJECT_ID`, `ROLOS_DESK_ID`/`RESEARCH_DESK_ID`, `ROLOS_API_SERVER`/`RESEARCH_API_SERVER`) and works in it:
|
|
68
|
+
|
|
69
|
+
- the desk's project folder (`~/project`, or `CONSTRUCTOR_DESK_ROOT`) is its disk, so the agent creates and changes files there directly; nothing is uploaded, and `sync_files`, `list_files`, `create_folder`, `move_path` and `delete_path` answer `local_desk` for this desk;
|
|
70
|
+
- `build_image`, `deploy_app`, `update_app`, `start_app`, `stop_app` and `list_images` act on this desk and project without a desk link; a `desk_url` or other IDs still name another desk;
|
|
71
|
+
- `build.dockerfile` is the path inside the project folder (`/backend/Dockerfile`), or `build.local_path` names a folder inside it; Dockerfiles are checked from the local files;
|
|
72
|
+
- the MCP works with the desk's Constructor (`ROLOS_API_SERVER`) unless `CONSTRUCTOR_BASE_URL` is set.
|
|
73
|
+
|
|
74
|
+
`CONSTRUCTOR_LOCAL_DESK=0` turns this off.
|
|
75
|
+
|
|
66
76
|
## Thirteen tools
|
|
67
77
|
|
|
68
78
|
| Tool | Agent's task |
|
package/dist/config.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { type LocalDesk } from "./desk.js";
|
|
1
2
|
export interface Config {
|
|
2
3
|
/** The Constructor the MCP works with: CONSTRUCTOR_BASE_URL, else the one the saved key belongs to. */
|
|
3
4
|
baseUrl: string;
|
|
4
5
|
baseUrlFixed?: boolean;
|
|
6
|
+
/** The Constructor desk this MCP runs inside (VS Code in Constructor Research), if any. */
|
|
7
|
+
localDesk?: LocalDesk;
|
|
5
8
|
apiPath: string;
|
|
6
9
|
storagePath?: string;
|
|
7
10
|
/** Build-log service root; build logs stream only while a build runs. */
|
package/dist/config.js
CHANGED
|
@@ -2,6 +2,7 @@ import { readFileSync } from "node:fs";
|
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import { join, resolve, sep } from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { localDeskFromEnv } from "./desk.js";
|
|
5
6
|
/** Where the MCP works unless CONSTRUCTOR_BASE_URL or the saved key names another Constructor. */
|
|
6
7
|
export const DEFAULT_BASE_URL = "https://constructor.app";
|
|
7
8
|
/** The origin of a Constructor link; HTTPS except on localhost. */
|
|
@@ -28,7 +29,9 @@ export function configFromEnv(env = process.env) {
|
|
|
28
29
|
if (url.search || url.hash || url.pathname !== "/")
|
|
29
30
|
throw new Error("CONSTRUCTOR_BASE_URL must be an origin without a path or credentials.");
|
|
30
31
|
}
|
|
31
|
-
|
|
32
|
+
// Inside a Constructor desk, its Constructor is the one to work with.
|
|
33
|
+
const localDesk = localDeskFromEnv(env, originOf);
|
|
34
|
+
const baseUrl = originOf(fixed ?? localDesk?.server ?? DEFAULT_BASE_URL);
|
|
32
35
|
const apiPath = env.CONSTRUCTOR_API_PATH ?? "/api/platform-account/v1";
|
|
33
36
|
if (!/^\/[a-zA-Z0-9/_-]+$/.test(apiPath) || apiPath.includes("//"))
|
|
34
37
|
throw new Error("Invalid CONSTRUCTOR_API_PATH.");
|
|
@@ -41,7 +44,8 @@ export function configFromEnv(env = process.env) {
|
|
|
41
44
|
const expand = (s) => resolve(s.startsWith("~/") ? homedir() + s.slice(1) : s);
|
|
42
45
|
return {
|
|
43
46
|
baseUrl,
|
|
44
|
-
baseUrlFixed: !!fixed,
|
|
47
|
+
baseUrlFixed: !!fixed || !!localDesk?.server,
|
|
48
|
+
localDesk,
|
|
45
49
|
apiPath: apiPath.replace(/\/$/, ""),
|
|
46
50
|
storagePath: storagePath.replace(/\/$/, ""),
|
|
47
51
|
keeperPath: keeperPath.replace(/\/$/, ""),
|
package/dist/desk.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Constructor desk this MCP runs inside (VS Code in Constructor Research), from the
|
|
3
|
+
* environment Constructor sets there. Its project folder is the desk's disk, so the agent edits
|
|
4
|
+
* files in place and the MCP never uploads to it.
|
|
5
|
+
*/
|
|
6
|
+
export interface LocalDesk {
|
|
7
|
+
projectId: string;
|
|
8
|
+
deskId: string;
|
|
9
|
+
/** The desk's project folder on this machine; the disk root for builds. */
|
|
10
|
+
root: string;
|
|
11
|
+
/** The Constructor the desk belongs to. */
|
|
12
|
+
server?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function localDeskFromEnv(env: NodeJS.ProcessEnv, origin: (link: string) => string): LocalDesk | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Disk path ("/a/Dockerfile") of a local path inside the desk's project folder, or undefined
|
|
17
|
+
* when it lies outside. Symlinks are resolved on both sides when the path exists.
|
|
18
|
+
*/
|
|
19
|
+
export declare function diskPath(desk: LocalDesk, local: string): string | undefined;
|
|
20
|
+
/** Absolute local path of a disk path; refuses anything that escapes the project folder. */
|
|
21
|
+
export declare function localPath(desk: LocalDesk, disk: string): string;
|
|
22
|
+
/** What the agent is told about working inside the desk. */
|
|
23
|
+
export declare function deskInstructions(desk: LocalDesk): string;
|
package/dist/desk.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { realpathSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
4
|
+
const ID = /^[a-zA-Z0-9_-]{4,128}$/;
|
|
5
|
+
export function localDeskFromEnv(env, origin) {
|
|
6
|
+
if (["0", "false", "off"].includes((env.CONSTRUCTOR_LOCAL_DESK ?? "").toLowerCase()))
|
|
7
|
+
return undefined;
|
|
8
|
+
const projectId = env.ROLOS_PROJECT_ID || env.RESEARCH_PROJECT_ID;
|
|
9
|
+
const deskId = env.ROLOS_DESK_ID || env.RESEARCH_DESK_ID;
|
|
10
|
+
if (!projectId || !deskId || !ID.test(projectId) || !ID.test(deskId))
|
|
11
|
+
return undefined;
|
|
12
|
+
let server;
|
|
13
|
+
try {
|
|
14
|
+
const s = env.ROLOS_API_SERVER || env.RESEARCH_API_SERVER;
|
|
15
|
+
server = s ? origin(s) : undefined;
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
server = undefined;
|
|
19
|
+
}
|
|
20
|
+
const home = env.HOME || homedir();
|
|
21
|
+
const root = resolve(env.CONSTRUCTOR_DESK_ROOT ?? join(home, "project"));
|
|
22
|
+
return { projectId, deskId, root, server };
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Disk path ("/a/Dockerfile") of a local path inside the desk's project folder, or undefined
|
|
26
|
+
* when it lies outside. Symlinks are resolved on both sides when the path exists.
|
|
27
|
+
*/
|
|
28
|
+
export function diskPath(desk, local) {
|
|
29
|
+
const real = (p) => {
|
|
30
|
+
try {
|
|
31
|
+
return realpathSync(p);
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return resolve(p);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
const rel = relative(real(desk.root), real(local));
|
|
38
|
+
if (rel.startsWith("..") || isAbsolute(rel))
|
|
39
|
+
return undefined;
|
|
40
|
+
return "/" + rel.split(sep).filter(Boolean).join("/");
|
|
41
|
+
}
|
|
42
|
+
/** Absolute local path of a disk path; refuses anything that escapes the project folder. */
|
|
43
|
+
export function localPath(desk, disk) {
|
|
44
|
+
const parts = disk.split("/").filter(Boolean);
|
|
45
|
+
if (parts.some((p) => p === ".." || p === "."))
|
|
46
|
+
throw new Error("Disk paths must not contain . or ..");
|
|
47
|
+
return join(desk.root, ...parts);
|
|
48
|
+
}
|
|
49
|
+
/** What the agent is told about working inside the desk. */
|
|
50
|
+
export function deskInstructions(desk) {
|
|
51
|
+
return `This MCP runs inside Constructor desk ${desk.deskId} of project ${desk.projectId} (VS Code in Constructor Research). That desk's disk is the local folder ${desk.root}: create and change its files there directly with your own file and shell tools, and do not use sync_files, list_files, create_folder, move_path or delete_path for this desk. build_image, deploy_app, update_app, start_app, stop_app and list_images use this desk and project by default, so no desk link is needed; pass desk_url only when the user names another desk. When the Dockerfile and sources are ready, call deploy_app (or build_image) with build.dockerfile as the path inside ${desk.root} (for example /backend/Dockerfile), or build.local_path set to a folder inside ${desk.root}; nothing is uploaded.`;
|
|
52
|
+
}
|
package/dist/files.d.ts
CHANGED
|
@@ -32,6 +32,10 @@ export declare class FileManager {
|
|
|
32
32
|
/** Type of a path, or null when missing. */
|
|
33
33
|
private stat;
|
|
34
34
|
private mkcol;
|
|
35
|
+
/** The desk this MCP runs inside, when `desk` is it. */
|
|
36
|
+
private here;
|
|
37
|
+
/** File tools never touch the desk the MCP runs in: its files are local. */
|
|
38
|
+
private notHere;
|
|
35
39
|
list(raw: unknown): Promise<{
|
|
36
40
|
desk_id: string;
|
|
37
41
|
path: string;
|
|
@@ -108,6 +112,8 @@ export declare class FileManager {
|
|
|
108
112
|
missing: string[];
|
|
109
113
|
warnings: string[];
|
|
110
114
|
}>;
|
|
115
|
+
/** The same checks as on a disk, for the desk this MCP runs in: its files are local. */
|
|
116
|
+
private checkLocal;
|
|
111
117
|
/** Upload to a fresh temp file, move it over the target, then verify the server checksum. */
|
|
112
118
|
private upload;
|
|
113
119
|
}
|
package/dist/files.js
CHANGED
|
@@ -2,6 +2,7 @@ import { createHash, randomUUID } from "node:crypto";
|
|
|
2
2
|
import { createReadStream } from "node:fs";
|
|
3
3
|
import { lstat, open, readdir, readFile } from "node:fs/promises";
|
|
4
4
|
import { basename, join } from "node:path";
|
|
5
|
+
import { localPath } from "./desk.js";
|
|
5
6
|
import { ToolError } from "./api.js";
|
|
6
7
|
import { listFilesInput, createFolderInput, syncFilesInput, movePathInput, deletePathInput, } from "./schemas.js";
|
|
7
8
|
/** Single PUTs above ~9 MB are rejected with 413, so larger files go in ranged chunks. */
|
|
@@ -201,8 +202,20 @@ export class FileManager {
|
|
|
201
202
|
? `Cannot create ${parts.join("/")}: a parent path is missing or is a file.`
|
|
202
203
|
: `Folder creation returned HTTP ${r.status}.`, r.status);
|
|
203
204
|
}
|
|
205
|
+
/** The desk this MCP runs inside, when `desk` is it. */
|
|
206
|
+
here(desk) {
|
|
207
|
+
const d = this.api.config.localDesk;
|
|
208
|
+
return d && d.deskId === desk ? d : undefined;
|
|
209
|
+
}
|
|
210
|
+
/** File tools never touch the desk the MCP runs in: its files are local. */
|
|
211
|
+
notHere(desk) {
|
|
212
|
+
const d = this.here(desk);
|
|
213
|
+
if (d)
|
|
214
|
+
throw new ToolError("local_desk", `This MCP runs inside desk ${desk}: its disk is the local folder ${d.root}. Read and change files there directly with your own file and shell tools; nothing needs uploading. When the Dockerfile is ready, call deploy_app or build_image with the Dockerfile path inside ${d.root} (for example /Dockerfile).`);
|
|
215
|
+
}
|
|
204
216
|
async list(raw) {
|
|
205
217
|
const i = listFilesInput.parse(raw);
|
|
218
|
+
this.notHere(i.desk_id);
|
|
206
219
|
await this.engine.filesDesk(i.project_id, i.desk_id);
|
|
207
220
|
const start = segs(i.path);
|
|
208
221
|
const entries = [];
|
|
@@ -238,6 +251,7 @@ export class FileManager {
|
|
|
238
251
|
}
|
|
239
252
|
async createFolder(raw) {
|
|
240
253
|
const i = createFolderInput.parse(raw);
|
|
254
|
+
this.notHere(i.desk_id);
|
|
241
255
|
await this.engine.filesDesk(i.project_id, i.desk_id);
|
|
242
256
|
const parts = segs(i.path);
|
|
243
257
|
const created = [];
|
|
@@ -255,6 +269,7 @@ export class FileManager {
|
|
|
255
269
|
}
|
|
256
270
|
async move(raw) {
|
|
257
271
|
const i = movePathInput.parse(raw);
|
|
272
|
+
this.notHere(i.desk_id);
|
|
258
273
|
await this.engine.filesDesk(i.project_id, i.desk_id);
|
|
259
274
|
const desk = i.desk_id;
|
|
260
275
|
const plan = [];
|
|
@@ -318,6 +333,7 @@ export class FileManager {
|
|
|
318
333
|
}
|
|
319
334
|
async remove(raw) {
|
|
320
335
|
const i = deletePathInput.parse(raw);
|
|
336
|
+
this.notHere(i.desk_id);
|
|
321
337
|
await this.engine.filesDesk(i.project_id, i.desk_id);
|
|
322
338
|
const desk = i.desk_id;
|
|
323
339
|
const targets = [];
|
|
@@ -374,6 +390,7 @@ export class FileManager {
|
|
|
374
390
|
}
|
|
375
391
|
async sync(raw) {
|
|
376
392
|
const i = syncFilesInput.parse(raw);
|
|
393
|
+
this.notHere(i.desk_id);
|
|
377
394
|
const begun = Date.now();
|
|
378
395
|
await this.engine.filesDesk(i.project_id, i.desk_id);
|
|
379
396
|
const desk = i.desk_id;
|
|
@@ -632,6 +649,11 @@ export class FileManager {
|
|
|
632
649
|
const missing = [];
|
|
633
650
|
const warnings = [];
|
|
634
651
|
for (const b of sources) {
|
|
652
|
+
const local = this.here(b.desk_id);
|
|
653
|
+
if (local) {
|
|
654
|
+
await this.checkLocal(local, b, missing, warnings);
|
|
655
|
+
continue;
|
|
656
|
+
}
|
|
635
657
|
await this.engine.filesDesk(project, b.desk_id);
|
|
636
658
|
const parts = segs(b.dockerfile);
|
|
637
659
|
const r = await this.api.storage("GET", b.desk_id, href(parts));
|
|
@@ -661,6 +683,29 @@ export class FileManager {
|
|
|
661
683
|
}
|
|
662
684
|
return { missing, warnings: [...new Set(warnings)] };
|
|
663
685
|
}
|
|
686
|
+
/** The same checks as on a disk, for the desk this MCP runs in: its files are local. */
|
|
687
|
+
async checkLocal(desk, b, missing, warnings) {
|
|
688
|
+
const parts = segs(b.dockerfile);
|
|
689
|
+
let text;
|
|
690
|
+
try {
|
|
691
|
+
text = (await readFile(localPath(desk, b.dockerfile), "utf8")).slice(0, 256 * 1024);
|
|
692
|
+
}
|
|
693
|
+
catch {
|
|
694
|
+
missing.push(`${b.service}: ${parts.join("/")} (in ${desk.root})`);
|
|
695
|
+
return;
|
|
696
|
+
}
|
|
697
|
+
warnings.push(...lintDockerfile(parts.join("/"), text, b.ports).map((w) => `${b.service}: ${w}`));
|
|
698
|
+
const dir = parts.slice(0, -1);
|
|
699
|
+
for (const conf of configsCopied(text)) {
|
|
700
|
+
const body = await readFile(localPath(desk, [...dir, ...segs(conf)].join("/")), "utf8").then((t) => t.slice(0, 64 * 1024), () => "");
|
|
701
|
+
if (/^\s*listen\s+\[::\]/m.test(body))
|
|
702
|
+
warnings.push(`${b.service}: ${conf} has "listen [::]". nginx exits on start when the cluster has no IPv6; keep only the IPv4 listen line (listen <port>;).`);
|
|
703
|
+
}
|
|
704
|
+
const names = await readdir(localPath(desk, dir.join("/"))).catch(() => []);
|
|
705
|
+
for (const name of names)
|
|
706
|
+
if (/^(docker-)?compose\.ya?ml$/.test(name))
|
|
707
|
+
warnings.push(`${b.service}: ${[...dir, name].join("/")} is ignored; docker-compose is not supported, so each service is configured in deploy_app.`);
|
|
708
|
+
}
|
|
664
709
|
/** Upload to a fresh temp file, move it over the target, then verify the server checksum. */
|
|
665
710
|
async upload(desk, f, target, replace) {
|
|
666
711
|
const tmp = [TEMP, TEMP_PREFIX + randomUUID()];
|
package/dist/location.d.ts
CHANGED
|
@@ -2,7 +2,9 @@ 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>, scope: Exclude<Scope, "deploy"
|
|
5
|
+
export declare function located(schema: z.ZodObject<any>, scope: Exclude<Scope, "deploy">,
|
|
6
|
+
/** Inside a desk the IDs default to it, so neither a link nor IDs are required. */
|
|
7
|
+
implied?: boolean): z.ZodObject<{
|
|
6
8
|
[x: string]: any;
|
|
7
9
|
project_id: z.ZodOptional<z.ZodString>;
|
|
8
10
|
desk_id?: z.ZodOptional<z.ZodString> | undefined;
|
package/dist/location.js
CHANGED
|
@@ -2,7 +2,16 @@ 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, scope
|
|
5
|
+
export function located(schema, scope,
|
|
6
|
+
/** Inside a desk the IDs default to it, so neither a link nor IDs are required. */
|
|
7
|
+
implied = false) {
|
|
8
|
+
const extended = schema.extend({
|
|
9
|
+
project_id: id.optional(),
|
|
10
|
+
...("desk_id" in schema.shape ? { desk_id: id.optional() } : {}),
|
|
11
|
+
desk_url: deskUrl.optional(),
|
|
12
|
+
});
|
|
13
|
+
if (implied)
|
|
14
|
+
return extended;
|
|
6
15
|
return schema
|
|
7
16
|
.extend({
|
|
8
17
|
project_id: id.optional(),
|
|
@@ -35,7 +44,7 @@ export function parseDeskUrl(link, baseUrl, fixed = false) {
|
|
|
35
44
|
const base = new URL(baseUrl).origin;
|
|
36
45
|
if (url.origin !== base)
|
|
37
46
|
bad("wrong_environment", fixed
|
|
38
|
-
? `The link is for ${url.origin}, but this MCP is fixed to ${base} by CONSTRUCTOR_BASE_URL. Ask the user for a link from ${base}.`
|
|
47
|
+
? `The link is for ${url.origin}, but this MCP is fixed to ${base} by CONSTRUCTOR_BASE_URL or the desk it runs in. Ask the user for a link from ${base}.`
|
|
39
48
|
: `The link is for ${url.origin}, but the saved access key is for ${base}. If they work on ${url.origin}, the user saves a key for it in a terminal (it replaces the key for ${base}): npx -y -p constructor-research-mcp@${VERSION} constructor-research-set-key ${url.origin}. Never ask for the key in the chat.`);
|
|
40
49
|
return { project_id: m[1], desk_id: m[2] };
|
|
41
50
|
}
|
package/dist/server.js
CHANGED
|
@@ -11,6 +11,21 @@ import { basename } from "node:path";
|
|
|
11
11
|
import { LogFollower } from "./logs.js";
|
|
12
12
|
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
13
|
import { located, resolveDeskUrl } from "./location.js";
|
|
14
|
+
import { deskInstructions, diskPath } from "./desk.js";
|
|
15
|
+
/** Tools whose project and desk default to the desk the MCP runs inside. */
|
|
16
|
+
const DESK_DEFAULT = new Set([
|
|
17
|
+
"build_image",
|
|
18
|
+
"list_images",
|
|
19
|
+
"list_files",
|
|
20
|
+
"create_folder",
|
|
21
|
+
"sync_files",
|
|
22
|
+
"move_path",
|
|
23
|
+
"delete_path",
|
|
24
|
+
"deploy_app",
|
|
25
|
+
"update_app",
|
|
26
|
+
"start_app",
|
|
27
|
+
"stop_app",
|
|
28
|
+
]);
|
|
14
29
|
import { ZodError } from "zod";
|
|
15
30
|
import { buildInput, listInput, deployInput, updateInput, lifecycleInput, getInput, logsInput, listFilesInput, createFolderInput, syncFilesInput, movePathInput, deletePathInput, } from "./schemas.js";
|
|
16
31
|
async function main() {
|
|
@@ -35,6 +50,28 @@ async function main() {
|
|
|
35
50
|
services.push(x);
|
|
36
51
|
continue;
|
|
37
52
|
}
|
|
53
|
+
// Inside the desk the MCP runs in, its project folder is the disk: nothing to upload.
|
|
54
|
+
const here = config.localDesk;
|
|
55
|
+
if (here && b.desk_id === here.deskId) {
|
|
56
|
+
const at = diskPath(here, b.local_path);
|
|
57
|
+
if (!at)
|
|
58
|
+
throw new ToolError("invalid_input", `Service ${x.name}: local_path ${b.local_path} is outside this desk's project folder ${here.root}, which is the desk's disk. Move the sources into ${here.root}, then call again.`);
|
|
59
|
+
const { local_path: _l, remote_path: _r, ...rest } = b;
|
|
60
|
+
services.push({
|
|
61
|
+
...x,
|
|
62
|
+
build: {
|
|
63
|
+
...rest,
|
|
64
|
+
dockerfile: "/" +
|
|
65
|
+
[
|
|
66
|
+
...at.split("/"),
|
|
67
|
+
...(b.dockerfile ?? "Dockerfile").split("/"),
|
|
68
|
+
]
|
|
69
|
+
.filter(Boolean)
|
|
70
|
+
.join("/"),
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
38
75
|
if (!b.desk_id || !a.project_id)
|
|
39
76
|
throw new ToolError("invalid_input", `Service ${x.name}: local_path needs a disk. Pass desk_url (the desk link from the user) or build.desk_id with project_id.`);
|
|
40
77
|
const remote = (b.remote_path ?? basename(b.local_path))
|
|
@@ -114,12 +151,17 @@ async function main() {
|
|
|
114
151
|
}
|
|
115
152
|
: result;
|
|
116
153
|
};
|
|
154
|
+
/** Inside a desk, the agent edits its files in place instead of asking for a desk link. */
|
|
155
|
+
const withDesk = (text) => config.localDesk
|
|
156
|
+
? 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
|
+
: text;
|
|
117
158
|
const server = new McpServer({ name: "constructor-research", version: VERSION }, {
|
|
118
|
-
instructions: `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 or desk yourself; if the user has not said where to deploy or where files live, ask. 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. 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, call get_deployment(wait_seconds=20) again as often as needed (a loop of such calls is fine); never perform the deployment steps yourself. 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
|
|
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 or desk yourself; if the user has not said where to deploy or where files live, ask. 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. 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, call get_deployment(wait_seconds=20) again as often as needed (a loop of such calls is fine); never perform the deployment steps yourself. 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.`),
|
|
119
160
|
});
|
|
120
161
|
const register = (name, description, schema, fn, readOnly = false, budget = 20000, scope) => {
|
|
162
|
+
const here = config.localDesk && DESK_DEFAULT.has(name) ? config.localDesk : undefined;
|
|
121
163
|
if (scope && scope !== "deploy")
|
|
122
|
-
schema = located(schema, scope);
|
|
164
|
+
schema = located(schema, scope, !!here);
|
|
123
165
|
server.registerTool(name, {
|
|
124
166
|
description,
|
|
125
167
|
inputSchema: schema,
|
|
@@ -133,7 +175,18 @@ async function main() {
|
|
|
133
175
|
try {
|
|
134
176
|
await api.refresh();
|
|
135
177
|
const result = await api.withBudget(budget, () => fn(scope
|
|
136
|
-
? resolveDeskUrl(
|
|
178
|
+
? resolveDeskUrl(
|
|
179
|
+
// Inside a desk, a call that names no other desk acts on it.
|
|
180
|
+
here &&
|
|
181
|
+
!args?.desk_url &&
|
|
182
|
+
(!args?.project_id ||
|
|
183
|
+
args.project_id === here.projectId) &&
|
|
184
|
+
(!args?.desk_id || args.desk_id === here.deskId)
|
|
185
|
+
? {
|
|
186
|
+
...args,
|
|
187
|
+
desk_url: `${config.baseUrl}/research/projects/${here.projectId}/desks/${here.deskId}`,
|
|
188
|
+
}
|
|
189
|
+
: args, config.baseUrl, scope, config.baseUrlFixed)
|
|
137
190
|
: args));
|
|
138
191
|
return {
|
|
139
192
|
content: [
|