constructor-research-mcp 0.6.4 → 0.6.5
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 +2 -0
- package/README.md +19 -12
- package/dist/agents.d.ts +5 -1
- package/dist/agents.js +12 -3
- package/dist/api.d.ts +12 -0
- package/dist/api.js +64 -2
- package/dist/config.d.ts +2 -0
- package/dist/config.js +1 -0
- package/dist/desk.d.ts +6 -0
- package/dist/desk.js +14 -0
- package/dist/install.js +36 -5
- package/dist/key.d.ts +3 -1
- package/dist/key.js +8 -3
- package/examples/codex.toml +2 -0
- package/package.json +1 -1
package/INSTALL.md
CHANGED
|
@@ -70,6 +70,8 @@ The first start downloads the package and can exceed Codex's 10-second start lim
|
|
|
70
70
|
[mcp_servers.constructor-research]
|
|
71
71
|
command = "npx"
|
|
72
72
|
args = ["-y", "constructor-research-mcp@latest"]
|
|
73
|
+
# Inside a Constructor desk: pass the desk and its access key on (Codex passes only a few variables).
|
|
74
|
+
env_vars = ["ROLOS_PROJECT_ID", "ROLOS_DESK_ID", "ROLOS_API_SERVER", "RESEARCH_PROJECT_ID", "RESEARCH_DESK_ID", "RESEARCH_API_SERVER", "RESEARCH_ACCESS_KEY"]
|
|
73
75
|
startup_timeout_sec = 60
|
|
74
76
|
tool_timeout_sec = 30
|
|
75
77
|
|
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Constructor Research MCP
|
|
2
2
|
|
|
3
|
+
> **0.6.5:** inside a Constructor desk, the MCP uses the access key the desk provides (`RESEARCH_ACCESS_KEY`), so the user needs no key of their own (once Research sets it); the Codex entry passes the desk's variables on to the MCP.
|
|
4
|
+
>
|
|
3
5
|
> **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
6
|
>
|
|
5
7
|
> **0.6.3:** `delete_resources` deletes applications, services and images, after the user approves the list.
|
|
@@ -64,23 +66,24 @@ npx -y -p constructor-research-mcp@latest constructor-research-set-key https://a
|
|
|
64
66
|
|
|
65
67
|
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.
|
|
66
68
|
|
|
67
|
-
`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.
|
|
69
|
+
`CONSTRUCTOR_ACCESS_KEY` in the MCP settings takes precedence over the file and over a desk's key. 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.
|
|
68
70
|
|
|
69
71
|
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`.
|
|
70
72
|
|
|
71
73
|
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.
|
|
72
74
|
|
|
73
|
-
| Variable | Default
|
|
74
|
-
| ----------------------------------- |
|
|
75
|
-
| `CONSTRUCTOR_BASE_URL` | unset: the Constructor of the saved key, else `https://constructor.app`; set, it fixes the host
|
|
76
|
-
| `CONSTRUCTOR_API_PATH` | `/api/platform-account/v1`
|
|
77
|
-
| `CONSTRUCTOR_STORAGE_PATH` | `/api/platform-storage`
|
|
78
|
-
| `CONSTRUCTOR_ACCESS_KEY` | unset: the key file is used
|
|
79
|
-
| `
|
|
80
|
-
| `
|
|
81
|
-
| `
|
|
82
|
-
| `
|
|
83
|
-
| `
|
|
75
|
+
| Variable | Default |
|
|
76
|
+
| ----------------------------------- | ------------------------------------------------------------------------------------------------------ |
|
|
77
|
+
| `CONSTRUCTOR_BASE_URL` | unset: the Constructor of the saved key, else `https://constructor.app`; set, it fixes the host |
|
|
78
|
+
| `CONSTRUCTOR_API_PATH` | `/api/platform-account/v1` |
|
|
79
|
+
| `CONSTRUCTOR_STORAGE_PATH` | `/api/platform-storage` |
|
|
80
|
+
| `CONSTRUCTOR_ACCESS_KEY` | unset: the key file is used |
|
|
81
|
+
| `RESEARCH_ACCESS_KEY` | set by Constructor Research inside a desk: the desk's key, used when `CONSTRUCTOR_ACCESS_KEY` is unset |
|
|
82
|
+
| `CONSTRUCTOR_KEY_FILE` | `~/.config/constructor-research/access-key.json` |
|
|
83
|
+
| `CONSTRUCTOR_DESK_ROOT` | `~/project` (inside a desk only) |
|
|
84
|
+
| `CONSTRUCTOR_STATE_DIR` | `~/.local/state/constructor-research-mcp` |
|
|
85
|
+
| `CONSTRUCTOR_UPLOAD_SETTLE_SECONDS` | `30` |
|
|
86
|
+
| `CONSTRUCTOR_READINESS_SECONDS` | `60` |
|
|
84
87
|
|
|
85
88
|
HTTPS is required except on localhost.
|
|
86
89
|
|
|
@@ -93,6 +96,10 @@ When the MCP runs in VS Code inside a Constructor Research desk, it finds that d
|
|
|
93
96
|
- `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;
|
|
94
97
|
- two addresses can lead to the user's Constructor: the one the user named (the saved key's, or `CONSTRUCTOR_BASE_URL`; without either, the desk's server) and the desk's server (`ROLOS_API_SERVER`), which may differ from it, e.g. `https://constructor.app` in a desk opened on `https://acme.constructor.app`. The MCP asks the desk's server once whether it accepts the key: if it does, requests go there, else to the user's address. Links shown to the user and key help keep the user's address, and desk links from either address are accepted. Setup (`install`, `constructor-research-set-key`) checks the key with both and saves it for the user's address when either accepts it.
|
|
95
98
|
|
|
99
|
+
- **the desk's access key:** Constructor Research sets `RESEARCH_ACCESS_KEY` in the desk, and the MCP uses it, so the user needs no key of their own and `install` asks for none. A key the user saved for this Constructor stays and takes over when Constructor rejects the desk's key. Once accepted, the desk's key is also saved to the key file, marked `"source": "desk"` (never over a key the user saved), so the wait command and hooks find it even where the agent's shell drops variables named `*KEY*` (Codex does).
|
|
100
|
+
|
|
101
|
+
Codex starts MCP servers with only a few variables (`HOME`, `PATH`, …). Its entry therefore lists the desk's variables in `env_vars` (names only, no values); `install` writes it. Claude Code passes its whole environment on. Agents that pass on neither (Cline) do not see the desk.
|
|
102
|
+
|
|
96
103
|
`CONSTRUCTOR_LOCAL_DESK=0` turns this off.
|
|
97
104
|
|
|
98
105
|
## Fourteen tools
|
package/dist/agents.d.ts
CHANGED
|
@@ -41,7 +41,11 @@ export interface Result {
|
|
|
41
41
|
export declare const succeeded: (r: Result) => boolean;
|
|
42
42
|
/** The entry as each agent expects it. */
|
|
43
43
|
export declare function entryFor(kind: Kind, spec: Spec, opencodeV2?: boolean): object;
|
|
44
|
-
/**
|
|
44
|
+
/**
|
|
45
|
+
* Codex: the first npx start downloads the package and can exceed Codex's 10 s start limit.
|
|
46
|
+
* Codex starts MCP servers with only a few variables (HOME, PATH, …); env_vars passes on the
|
|
47
|
+
* ones a Constructor desk sets, names only, so the MCP finds the desk and the desk's key.
|
|
48
|
+
*/
|
|
45
49
|
export declare const tomlBlock: ({ command, args }: Spec) => string;
|
|
46
50
|
/** What will be written, for --verbose. */
|
|
47
51
|
export declare function describe(kind: Kind, spec: Spec, opencodeV2?: boolean): string[];
|
package/dist/agents.js
CHANGED
|
@@ -12,6 +12,7 @@ import { homedir } from "node:os";
|
|
|
12
12
|
import { basename, dirname, join } from "node:path";
|
|
13
13
|
import { isDeepStrictEqual } from "node:util";
|
|
14
14
|
import { parse as parseToml } from "smol-toml";
|
|
15
|
+
import { DESK_ENV } from "./desk.js";
|
|
15
16
|
export const SERVER = "constructor-research";
|
|
16
17
|
export const PACKAGE_SPEC = "constructor-research-mcp@latest";
|
|
17
18
|
/** The command every agent runs. On Windows npx is a .cmd script, which agents start through cmd. */
|
|
@@ -163,8 +164,12 @@ export function entryFor(kind, spec, opencodeV2 = false) {
|
|
|
163
164
|
}
|
|
164
165
|
}
|
|
165
166
|
const tomlString = (s) => JSON.stringify(s);
|
|
166
|
-
/**
|
|
167
|
-
|
|
167
|
+
/**
|
|
168
|
+
* Codex: the first npx start downloads the package and can exceed Codex's 10 s start limit.
|
|
169
|
+
* Codex starts MCP servers with only a few variables (HOME, PATH, …); env_vars passes on the
|
|
170
|
+
* ones a Constructor desk sets, names only, so the MCP finds the desk and the desk's key.
|
|
171
|
+
*/
|
|
172
|
+
export const tomlBlock = ({ command, args }) => `[mcp_servers.${SERVER}]\ncommand = ${tomlString(command)}\nargs = [${args.map(tomlString).join(", ")}]\nenv_vars = [${DESK_ENV.map(tomlString).join(", ")}]\nstartup_timeout_sec = 60\n`;
|
|
168
173
|
/** What will be written, for --verbose. */
|
|
169
174
|
export function describe(kind, spec, opencodeV2 = false) {
|
|
170
175
|
if (kind === "codex")
|
|
@@ -349,7 +354,11 @@ export function writeToml(path, spec, scope) {
|
|
|
349
354
|
return untouched("could not be edited safely");
|
|
350
355
|
}
|
|
351
356
|
const entry = after.mcp_servers?.[SERVER];
|
|
352
|
-
if (!isDeepStrictEqual(plain(entry), {
|
|
357
|
+
if (!isDeepStrictEqual(plain(entry), {
|
|
358
|
+
...spec,
|
|
359
|
+
env_vars: DESK_ENV,
|
|
360
|
+
startup_timeout_sec: 60,
|
|
361
|
+
}) ||
|
|
353
362
|
!isDeepStrictEqual(withoutOurs(parseToml(old)), withoutOurs(after)))
|
|
354
363
|
return untouched(`sets ${SERVER} in a form this setup does not edit`);
|
|
355
364
|
const backup = backupOnce(file);
|
package/dist/api.d.ts
CHANGED
|
@@ -38,6 +38,18 @@ export declare class PlatformApi {
|
|
|
38
38
|
* changes; an unreachable server is asked again after a minute.
|
|
39
39
|
*/
|
|
40
40
|
origin(key: string): Promise<string>;
|
|
41
|
+
/** What Constructor said about the desk's key; see deskKey(). */
|
|
42
|
+
private deskCheck?;
|
|
43
|
+
/**
|
|
44
|
+
* Inside a Constructor desk, RESEARCH_ACCESS_KEY is the key the desk provides, so the user
|
|
45
|
+
* need not supply one. It is used first; a key the user saved for this Constructor takes over
|
|
46
|
+
* when Constructor rejects it. Once accepted it is saved to the key file (marked "desk") unless
|
|
47
|
+
* the user saved a key of their own there, so the wait command and hooks find it even when the
|
|
48
|
+
* agent's shell drops variables named *KEY*. Constructor is asked about the key once, and only
|
|
49
|
+
* when there is a choice or something to save.
|
|
50
|
+
*/
|
|
51
|
+
private deskKey;
|
|
52
|
+
private checkDeskKey;
|
|
41
53
|
/** The access-key header for a request, and the origin the request goes to. */
|
|
42
54
|
private auth;
|
|
43
55
|
private rejected;
|
package/dist/api.js
CHANGED
|
@@ -2,7 +2,7 @@ import { AsyncLocalStorage } from "node:async_hooks";
|
|
|
2
2
|
import { createHash } from "node:crypto";
|
|
3
3
|
import { setTimeout as delay } from "node:timers/promises";
|
|
4
4
|
import { DEFAULT_BASE_URL, VERSION } from "./config.js";
|
|
5
|
-
import { readKeyFile, routeKey } from "./key.js";
|
|
5
|
+
import { readKeyFile, routeKey, saveKeyFile, } from "./key.js";
|
|
6
6
|
export class ToolError extends Error {
|
|
7
7
|
code;
|
|
8
8
|
status;
|
|
@@ -49,6 +49,7 @@ export class PlatformApi {
|
|
|
49
49
|
* Read before every tool call, so a key saved meanwhile is used without a restart.
|
|
50
50
|
*/
|
|
51
51
|
async refresh() {
|
|
52
|
+
// A key in the MCP settings names no Constructor; it wins over the desk's and the file's.
|
|
52
53
|
if (this.config.baseUrlFixed || this.config.accessKey)
|
|
53
54
|
return;
|
|
54
55
|
const saved = await readKeyFile(this.config.keyFile).catch(() => undefined);
|
|
@@ -88,10 +89,68 @@ export class PlatformApi {
|
|
|
88
89
|
this.route = route;
|
|
89
90
|
return route.origin;
|
|
90
91
|
}
|
|
92
|
+
/** What Constructor said about the desk's key; see deskKey(). */
|
|
93
|
+
deskCheck;
|
|
94
|
+
/**
|
|
95
|
+
* Inside a Constructor desk, RESEARCH_ACCESS_KEY is the key the desk provides, so the user
|
|
96
|
+
* need not supply one. It is used first; a key the user saved for this Constructor takes over
|
|
97
|
+
* when Constructor rejects it. Once accepted it is saved to the key file (marked "desk") unless
|
|
98
|
+
* the user saved a key of their own there, so the wait command and hooks find it even when the
|
|
99
|
+
* agent's shell drops variables named *KEY*. Constructor is asked about the key once, and only
|
|
100
|
+
* when there is a choice or something to save.
|
|
101
|
+
*/
|
|
102
|
+
async deskKey(env, saved) {
|
|
103
|
+
const usable = saved?.url === this.config.baseUrl ? saved : undefined;
|
|
104
|
+
const clean = cleanKey(env);
|
|
105
|
+
if (!clean)
|
|
106
|
+
return usable?.key ?? env;
|
|
107
|
+
if (usable && cleanKey(usable.key) === clean)
|
|
108
|
+
return clean;
|
|
109
|
+
const save = !saved || (saved.source === "desk" && !!usable);
|
|
110
|
+
if (!usable && !save)
|
|
111
|
+
return clean;
|
|
112
|
+
const result = await this.checkDeskKey(clean);
|
|
113
|
+
if (result === "rejected") {
|
|
114
|
+
if (usable)
|
|
115
|
+
return usable.key;
|
|
116
|
+
throw new ToolError("needs_key", this.keyHelp("Constructor rejected the access key this desk provides (RESEARCH_ACCESS_KEY)."), 401);
|
|
117
|
+
}
|
|
118
|
+
if (result === "ok" && save)
|
|
119
|
+
await saveKeyFile(this.config.keyFile, this.config.baseUrl, clean, "desk")
|
|
120
|
+
// The key still works from the environment; only the wait command misses the copy.
|
|
121
|
+
.catch(() => undefined);
|
|
122
|
+
return clean;
|
|
123
|
+
}
|
|
124
|
+
checkDeskKey(key) {
|
|
125
|
+
const home = this.config.baseUrl;
|
|
126
|
+
const server = this.config.localDesk?.server;
|
|
127
|
+
const tag = createHash("sha256")
|
|
128
|
+
.update(`${home}\n${server}\n${key}`)
|
|
129
|
+
.digest("hex");
|
|
130
|
+
if (this.deskCheck?.tag === tag && Date.now() < this.deskCheck.until)
|
|
131
|
+
return this.deskCheck.result;
|
|
132
|
+
const check = {
|
|
133
|
+
tag,
|
|
134
|
+
until: Infinity,
|
|
135
|
+
result: routeKey(home, server, this.config.apiPath, key, {
|
|
136
|
+
checkHome: true,
|
|
137
|
+
timeoutMs: Math.min(5000, this.config.requestTimeoutMs),
|
|
138
|
+
}).then((r) => {
|
|
139
|
+
// Only a clear yes or no holds; an unreachable Constructor is asked again in a minute.
|
|
140
|
+
if (r.result !== "ok" && r.result !== "rejected")
|
|
141
|
+
check.until = Date.now() + 60000;
|
|
142
|
+
return r.result ?? "unreachable";
|
|
143
|
+
}),
|
|
144
|
+
};
|
|
145
|
+
this.deskCheck = check;
|
|
146
|
+
return check.result;
|
|
147
|
+
}
|
|
91
148
|
/** The access-key header for a request, and the origin the request goes to. */
|
|
92
149
|
async auth() {
|
|
93
150
|
let key = this.config.accessKey;
|
|
94
|
-
if (key === undefined)
|
|
151
|
+
if (key === undefined && this.config.deskKey)
|
|
152
|
+
key = await this.deskKey(this.config.deskKey, await readKeyFile(this.config.keyFile).catch(() => undefined));
|
|
153
|
+
else if (key === undefined) {
|
|
95
154
|
let saved;
|
|
96
155
|
try {
|
|
97
156
|
saved = await readKeyFile(this.config.keyFile);
|
|
@@ -115,6 +174,9 @@ export class PlatformApi {
|
|
|
115
174
|
};
|
|
116
175
|
}
|
|
117
176
|
rejected() {
|
|
177
|
+
// The next call asks again which key to use and where it goes.
|
|
178
|
+
this.deskCheck = undefined;
|
|
179
|
+
this.route = undefined;
|
|
118
180
|
return new ToolError("needs_key", this.keyHelp("Constructor rejected the access key (revoked, expired or for another Constructor)."), 401);
|
|
119
181
|
}
|
|
120
182
|
/**
|
package/dist/config.d.ts
CHANGED
|
@@ -16,6 +16,8 @@ export interface Config {
|
|
|
16
16
|
keeperPath?: string;
|
|
17
17
|
/** Personal access key (rk-…) from CONSTRUCTOR_ACCESS_KEY; without it the key file is read. */
|
|
18
18
|
accessKey?: string;
|
|
19
|
+
/** Inside a desk: the access key Constructor Research provides there (RESEARCH_ACCESS_KEY). */
|
|
20
|
+
deskKey?: string;
|
|
19
21
|
/** Saved key and the Constructor it belongs to (JSON, mode 600); CONSTRUCTOR_KEY_FILE moves it. */
|
|
20
22
|
keyFile: string;
|
|
21
23
|
stateDir: string;
|
package/dist/config.js
CHANGED
|
@@ -50,6 +50,7 @@ export function configFromEnv(env = process.env) {
|
|
|
50
50
|
storagePath: storagePath.replace(/\/$/, ""),
|
|
51
51
|
keeperPath: keeperPath.replace(/\/$/, ""),
|
|
52
52
|
accessKey: env.CONSTRUCTOR_ACCESS_KEY?.trim() || undefined,
|
|
53
|
+
deskKey: (localDesk && env.RESEARCH_ACCESS_KEY?.trim()) || undefined,
|
|
53
54
|
keyFile: expand(env.CONSTRUCTOR_KEY_FILE ?? DEFAULT_KEY_FILE),
|
|
54
55
|
stateDir: expand(env.CONSTRUCTOR_STATE_DIR ?? "~/.local/state/constructor-research-mcp"),
|
|
55
56
|
requestTimeoutMs: 15000,
|
package/dist/desk.d.ts
CHANGED
|
@@ -11,6 +11,12 @@ export interface LocalDesk {
|
|
|
11
11
|
/** The Constructor the desk belongs to. */
|
|
12
12
|
server?: string;
|
|
13
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* What Constructor sets in a desk that the MCP reads: the desk, its server, and the access key
|
|
16
|
+
* the desk provides. Agents that start the MCP with a reduced environment (Codex) are told to
|
|
17
|
+
* pass these on.
|
|
18
|
+
*/
|
|
19
|
+
export declare const DESK_ENV: string[];
|
|
14
20
|
export declare function localDeskFromEnv(env: NodeJS.ProcessEnv, origin: (link: string) => string): LocalDesk | undefined;
|
|
15
21
|
/**
|
|
16
22
|
* Disk path ("/a/Dockerfile") of a local path inside the desk's project folder, or undefined
|
package/dist/desk.js
CHANGED
|
@@ -2,6 +2,20 @@ import { realpathSync } from "node:fs";
|
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import { isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
4
4
|
const ID = /^[a-zA-Z0-9_-]{4,128}$/;
|
|
5
|
+
/**
|
|
6
|
+
* What Constructor sets in a desk that the MCP reads: the desk, its server, and the access key
|
|
7
|
+
* the desk provides. Agents that start the MCP with a reduced environment (Codex) are told to
|
|
8
|
+
* pass these on.
|
|
9
|
+
*/
|
|
10
|
+
export const DESK_ENV = [
|
|
11
|
+
"ROLOS_PROJECT_ID",
|
|
12
|
+
"ROLOS_DESK_ID",
|
|
13
|
+
"ROLOS_API_SERVER",
|
|
14
|
+
"RESEARCH_PROJECT_ID",
|
|
15
|
+
"RESEARCH_DESK_ID",
|
|
16
|
+
"RESEARCH_API_SERVER",
|
|
17
|
+
"RESEARCH_ACCESS_KEY",
|
|
18
|
+
];
|
|
5
19
|
export function localDeskFromEnv(env, origin) {
|
|
6
20
|
if (["0", "false", "off"].includes((env.CONSTRUCTOR_LOCAL_DESK ?? "").toLowerCase()))
|
|
7
21
|
return undefined;
|
package/dist/install.js
CHANGED
|
@@ -230,11 +230,17 @@ export async function runInstall(argv) {
|
|
|
230
230
|
let base;
|
|
231
231
|
/** Inside a Constructor desk, the server it names; the key is checked there too. */
|
|
232
232
|
const deskServer = config.localDesk?.server;
|
|
233
|
+
/** The access key the desk provides (RESEARCH_ACCESS_KEY); no question then. A key given for -y wins. */
|
|
234
|
+
const deskKey = config.deskKey &&
|
|
235
|
+
!flag("--key-stdin") &&
|
|
236
|
+
!(yes && env.CONSTRUCTOR_ACCESS_KEY)
|
|
237
|
+
? accessKey(config.deskKey)
|
|
238
|
+
: undefined;
|
|
233
239
|
try {
|
|
234
240
|
const given = value("--constructor");
|
|
235
241
|
if (given)
|
|
236
242
|
base = linkOrigin(given);
|
|
237
|
-
else if (yes)
|
|
243
|
+
else if (yes || deskKey)
|
|
238
244
|
base = saved?.url ?? deskServer ?? DEFAULT_BASE_URL;
|
|
239
245
|
else {
|
|
240
246
|
// Inside a desk its server is the likely answer, but the user may open another address.
|
|
@@ -319,7 +325,30 @@ export async function runInstall(argv) {
|
|
|
319
325
|
return route.result;
|
|
320
326
|
};
|
|
321
327
|
let key;
|
|
322
|
-
|
|
328
|
+
let keySource;
|
|
329
|
+
let deskDone = false;
|
|
330
|
+
if (deskKey) {
|
|
331
|
+
if ((await check(deskKey)) === "ok") {
|
|
332
|
+
deskDone = true;
|
|
333
|
+
// A key the user saved for this Constructor stays: the MCP falls back to it.
|
|
334
|
+
if (saved?.url === base && !saved.source && saved.key !== deskKey)
|
|
335
|
+
p.log.info(`This desk provides an access key (${mask(deskKey)}); the MCP uses it, and the key saved for ${short(base)} if Constructor rejects the desk's.`);
|
|
336
|
+
else {
|
|
337
|
+
key = deskKey;
|
|
338
|
+
keySource = "desk";
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
else {
|
|
342
|
+
if (yes)
|
|
343
|
+
keyProblem = "the access key this desk provides was not accepted";
|
|
344
|
+
else
|
|
345
|
+
p.log.warn("The access key this desk provides was not accepted.");
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
if (deskDone) {
|
|
349
|
+
// The desk's key is accepted; nothing to ask.
|
|
350
|
+
}
|
|
351
|
+
else if (yes) {
|
|
323
352
|
const raw = flag("--key-stdin")
|
|
324
353
|
? await readStdin()
|
|
325
354
|
: env.CONSTRUCTOR_ACCESS_KEY;
|
|
@@ -333,7 +362,7 @@ export async function runInstall(argv) {
|
|
|
333
362
|
}
|
|
334
363
|
}
|
|
335
364
|
else if (!(saved && saved.url === base))
|
|
336
|
-
keyProblem
|
|
365
|
+
keyProblem ||= "no key given (CONSTRUCTOR_ACCESS_KEY or --key-stdin)";
|
|
337
366
|
}
|
|
338
367
|
else {
|
|
339
368
|
const keep = saved?.url === base &&
|
|
@@ -371,9 +400,11 @@ export async function runInstall(argv) {
|
|
|
371
400
|
if (dry)
|
|
372
401
|
p.log.info(`Dry run: key ${mask(key)} not saved.`);
|
|
373
402
|
else {
|
|
374
|
-
await saveKeyFile(config.keyFile, base, key);
|
|
403
|
+
await saveKeyFile(config.keyFile, base, key, keySource);
|
|
375
404
|
keySaved = true;
|
|
376
|
-
p.log.success(
|
|
405
|
+
p.log.success(keySource
|
|
406
|
+
? `The access key this desk provides (${mask(key)}) is saved to ${bold(show(config.keyFile))} ${dim("(readable only by you)")}, so the wait command finds it too; no key from you is needed`
|
|
407
|
+
: `Key saved to ${bold(show(config.keyFile))} ${dim("(readable only by you)")}`);
|
|
377
408
|
}
|
|
378
409
|
}
|
|
379
410
|
else if (keyProblem)
|
package/dist/key.d.ts
CHANGED
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
export interface SavedKey {
|
|
3
3
|
url: string;
|
|
4
4
|
key: string;
|
|
5
|
+
/** "desk": the MCP saved the key a Constructor desk provides (CONSTRUCTOR_ACCESS_KEY); absent: the user saved it. */
|
|
6
|
+
source?: "desk";
|
|
5
7
|
}
|
|
6
8
|
/** The saved key, or undefined when none was saved. A broken file throws. */
|
|
7
9
|
export declare function readKeyFile(file: string): Promise<SavedKey | undefined>;
|
|
8
10
|
/** Saves the key for one Constructor, mode 600, replacing the file in one step. */
|
|
9
|
-
export declare function saveKeyFile(file: string, url: string, key: string): Promise<void>;
|
|
11
|
+
export declare function saveKeyFile(file: string, url: string, key: string, source?: "desk"): Promise<void>;
|
|
10
12
|
export type KeyCheck = "ok" | "rejected" | "no_api" | "unreachable";
|
|
11
13
|
/** Ask Constructor whether it accepts the key: 200 accepted, 401 rejected, else no public API. */
|
|
12
14
|
export declare function checkKey(url: string, apiPath: string, key: string, timeoutMs?: number): Promise<{
|
package/dist/key.js
CHANGED
|
@@ -23,13 +23,18 @@ export async function readKeyFile(file) {
|
|
|
23
23
|
}
|
|
24
24
|
if (typeof data?.key !== "string" || typeof data?.url !== "string")
|
|
25
25
|
throw new Error("expected url and key");
|
|
26
|
-
return {
|
|
26
|
+
return {
|
|
27
|
+
url: originOf(data.url),
|
|
28
|
+
key: data.key,
|
|
29
|
+
...(data.source === "desk" ? { source: "desk" } : {}),
|
|
30
|
+
};
|
|
27
31
|
}
|
|
28
32
|
/** Saves the key for one Constructor, mode 600, replacing the file in one step. */
|
|
29
|
-
export async function saveKeyFile(file, url, key) {
|
|
33
|
+
export async function saveKeyFile(file, url, key, source) {
|
|
30
34
|
await mkdir(dirname(file), { recursive: true, mode: 0o700 });
|
|
31
35
|
const tmp = `${file}.${process.pid}.${randomBytes(4).toString("hex")}.tmp`;
|
|
32
|
-
await writeFile(tmp, JSON.stringify({ url: originOf(url), key }) +
|
|
36
|
+
await writeFile(tmp, JSON.stringify({ url: originOf(url), key, ...(source ? { source } : {}) }) +
|
|
37
|
+
"\n", {
|
|
33
38
|
mode: 0o600,
|
|
34
39
|
flag: "wx",
|
|
35
40
|
});
|
package/examples/codex.toml
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
[mcp_servers.constructor-research]
|
|
2
2
|
command = "npx"
|
|
3
3
|
args = ["-y", "constructor-research-mcp@latest"]
|
|
4
|
+
# Inside a Constructor desk: pass the desk and its access key on (Codex passes only a few variables).
|
|
5
|
+
env_vars = ["ROLOS_PROJECT_ID", "ROLOS_DESK_ID", "ROLOS_API_SERVER", "RESEARCH_PROJECT_ID", "RESEARCH_DESK_ID", "RESEARCH_API_SERVER", "RESEARCH_ACCESS_KEY"]
|
|
4
6
|
# The first start downloads the package.
|
|
5
7
|
startup_timeout_sec = 60
|
|
6
8
|
tool_timeout_sec = 30
|