constructor-research-mcp 0.6.0 → 0.6.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/README.md +4 -2
- package/dist/api.d.ts +11 -1
- package/dist/api.js +48 -12
- package/dist/config.d.ts +6 -1
- package/dist/config.js +2 -2
- package/dist/install.js +29 -13
- package/dist/key.d.ts +22 -0
- package/dist/key.js +14 -0
- package/dist/location.d.ts +6 -3
- package/dist/location.js +7 -4
- package/dist/server.js +3 -1
- package/dist/set-key.js +19 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Constructor Research MCP
|
|
2
2
|
|
|
3
|
+
> **0.6.1:** inside a Constructor desk, a key saved for your Constructor works even when the desk names another address for it (`ROLOS_API_SERVER`, e.g. `constructor.app` in a desk opened on `acme.constructor.app`).
|
|
4
|
+
>
|
|
3
5
|
> **0.6:** a registry `image` the project does not have is added to it as an external image, with no desk and no build; Constructor refuses a bad one at once, with its reason.
|
|
4
6
|
>
|
|
5
7
|
> **0.5:** one command sets it up: `npx -y constructor-research-mcp@latest install` finds your coding agents, saves your access key and adds the MCP to each of them.
|
|
@@ -83,7 +85,7 @@ When the MCP runs in VS Code inside a Constructor Research desk, it finds that d
|
|
|
83
85
|
- 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;
|
|
84
86
|
- `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;
|
|
85
87
|
- `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;
|
|
86
|
-
- the
|
|
88
|
+
- 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.
|
|
87
89
|
|
|
88
90
|
`CONSTRUCTOR_LOCAL_DESK=0` turns this off.
|
|
89
91
|
|
|
@@ -114,7 +116,7 @@ The agent does not choose a project or desk. It asks the user for the desk link:
|
|
|
114
116
|
https://constructor.app/research/projects/<project_id>/desks/<desk_id>/viewer/file
|
|
115
117
|
```
|
|
116
118
|
|
|
117
|
-
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.
|
|
119
|
+
Every tool accepts it as `desk_url`, in place of `project_id`/`desk_id`. Anything after `/desks/<desk_id>` is ignored. The link's host must be the Constructor the key belongs to (inside a desk, the desk's server too); a link from another one returns `wrong_environment` (see the access key above). Explicit IDs, if also sent, must agree with the link. In `deploy_app`/`update_app`, builds without their own `desk_id` use the link's desk; `start_app`/`stop_app` and `get_deployment` take only the project from it.
|
|
118
120
|
|
|
119
121
|
Given only `project_id`, the MCP finds the desk itself:
|
|
120
122
|
|
package/dist/api.d.ts
CHANGED
|
@@ -28,7 +28,17 @@ export declare class PlatformApi {
|
|
|
28
28
|
* Read before every tool call, so a key saved meanwhile is used without a restart.
|
|
29
29
|
*/
|
|
30
30
|
refresh(): Promise<void>;
|
|
31
|
-
/**
|
|
31
|
+
/** Where requests went for the last key and pair of addresses; see origin(). */
|
|
32
|
+
private route?;
|
|
33
|
+
/**
|
|
34
|
+
* Where requests with this key go. Outside a desk, or when the desk's server is the user's
|
|
35
|
+
* Constructor, that is the user's Constructor. Inside a desk whose server (ROLOS_API_SERVER)
|
|
36
|
+
* differs, the server is asked once whether it accepts the key: if so, requests go there,
|
|
37
|
+
* else to the user's Constructor (routeKey). The answer holds until the key or an address
|
|
38
|
+
* changes; an unreachable server is asked again after a minute.
|
|
39
|
+
*/
|
|
40
|
+
origin(key: string): Promise<string>;
|
|
41
|
+
/** The access-key header for a request, and the origin the request goes to. */
|
|
32
42
|
private auth;
|
|
33
43
|
private rejected;
|
|
34
44
|
/**
|
package/dist/api.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
2
3
|
import { setTimeout as delay } from "node:timers/promises";
|
|
3
4
|
import { DEFAULT_BASE_URL, VERSION } from "./config.js";
|
|
4
|
-
import { readKeyFile } from "./key.js";
|
|
5
|
+
import { readKeyFile, routeKey } from "./key.js";
|
|
5
6
|
export class ToolError extends Error {
|
|
6
7
|
code;
|
|
7
8
|
status;
|
|
@@ -51,9 +52,43 @@ export class PlatformApi {
|
|
|
51
52
|
if (this.config.baseUrlFixed || this.config.accessKey)
|
|
52
53
|
return;
|
|
53
54
|
const saved = await readKeyFile(this.config.keyFile).catch(() => undefined);
|
|
54
|
-
this.config.baseUrl =
|
|
55
|
+
this.config.baseUrl =
|
|
56
|
+
saved?.url ?? this.config.localDesk?.server ?? DEFAULT_BASE_URL;
|
|
55
57
|
}
|
|
56
|
-
/**
|
|
58
|
+
/** Where requests went for the last key and pair of addresses; see origin(). */
|
|
59
|
+
route;
|
|
60
|
+
/**
|
|
61
|
+
* Where requests with this key go. Outside a desk, or when the desk's server is the user's
|
|
62
|
+
* Constructor, that is the user's Constructor. Inside a desk whose server (ROLOS_API_SERVER)
|
|
63
|
+
* differs, the server is asked once whether it accepts the key: if so, requests go there,
|
|
64
|
+
* else to the user's Constructor (routeKey). The answer holds until the key or an address
|
|
65
|
+
* changes; an unreachable server is asked again after a minute.
|
|
66
|
+
*/
|
|
67
|
+
async origin(key) {
|
|
68
|
+
const home = this.config.baseUrl;
|
|
69
|
+
const server = this.config.localDesk?.server;
|
|
70
|
+
if (!server || server === home)
|
|
71
|
+
return home;
|
|
72
|
+
const tag = createHash("sha256")
|
|
73
|
+
.update(`${home}\n${server}\n${key}`)
|
|
74
|
+
.digest("hex");
|
|
75
|
+
if (this.route?.tag === tag && Date.now() < this.route.until)
|
|
76
|
+
return this.route.origin;
|
|
77
|
+
const route = {
|
|
78
|
+
tag,
|
|
79
|
+
until: Infinity,
|
|
80
|
+
origin: routeKey(home, server, this.config.apiPath, key, {
|
|
81
|
+
timeoutMs: Math.min(5000, this.config.requestTimeoutMs),
|
|
82
|
+
}).then((r) => {
|
|
83
|
+
if (r.server === "unreachable")
|
|
84
|
+
route.until = Date.now() + 60000;
|
|
85
|
+
return r.origin;
|
|
86
|
+
}),
|
|
87
|
+
};
|
|
88
|
+
this.route = route;
|
|
89
|
+
return route.origin;
|
|
90
|
+
}
|
|
91
|
+
/** The access-key header for a request, and the origin the request goes to. */
|
|
57
92
|
async auth() {
|
|
58
93
|
let key = this.config.accessKey;
|
|
59
94
|
if (key === undefined) {
|
|
@@ -74,7 +109,10 @@ export class PlatformApi {
|
|
|
74
109
|
const clean = cleanKey(key);
|
|
75
110
|
if (!clean)
|
|
76
111
|
throw new ToolError("needs_key", this.keyHelp("The access key is not in a valid format."));
|
|
77
|
-
return {
|
|
112
|
+
return {
|
|
113
|
+
headers: { "X-Research-AccessKey": `Bearer ${clean}` },
|
|
114
|
+
origin: await this.origin(clean),
|
|
115
|
+
};
|
|
78
116
|
}
|
|
79
117
|
rejected() {
|
|
80
118
|
return new ToolError("needs_key", this.keyHelp("Constructor rejected the access key (revoked, expired or for another Constructor)."), 401);
|
|
@@ -85,7 +123,7 @@ export class PlatformApi {
|
|
|
85
123
|
* safe to repeat (all but MOVE and DELETE) are retried a few times with backoff.
|
|
86
124
|
*/
|
|
87
125
|
async storage(method, desk, path, init = {}) {
|
|
88
|
-
const auth = await this.auth();
|
|
126
|
+
const { headers: auth, origin } = await this.auth();
|
|
89
127
|
const retries = ["MOVE", "DELETE"].includes(method)
|
|
90
128
|
? []
|
|
91
129
|
: this.storageRetryMs;
|
|
@@ -97,7 +135,7 @@ export class PlatformApi {
|
|
|
97
135
|
const again = wait !== undefined && wait < remaining - 1000;
|
|
98
136
|
let response;
|
|
99
137
|
try {
|
|
100
|
-
response = await fetch(
|
|
138
|
+
response = await fetch(origin + this.davRoot(desk) + path, {
|
|
101
139
|
method,
|
|
102
140
|
headers: { ...auth, ...init.headers },
|
|
103
141
|
body: init.body,
|
|
@@ -129,12 +167,10 @@ export class PlatformApi {
|
|
|
129
167
|
* body and aborts through `signal`. 401 becomes needs_key; other statuses are returned.
|
|
130
168
|
*/
|
|
131
169
|
async stream(path, signal) {
|
|
132
|
-
const auth = await this.auth();
|
|
170
|
+
const { headers: auth, origin } = await this.auth();
|
|
133
171
|
let response;
|
|
134
172
|
try {
|
|
135
|
-
response = await fetch(this.config.
|
|
136
|
-
(this.config.keeperPath ?? "/api/platform-keeper") +
|
|
137
|
-
path, {
|
|
173
|
+
response = await fetch(origin + (this.config.keeperPath ?? "/api/platform-keeper") + path, {
|
|
138
174
|
headers: { ...auth, Accept: "text/event-stream" },
|
|
139
175
|
redirect: "manual",
|
|
140
176
|
signal,
|
|
@@ -156,13 +192,13 @@ export class PlatformApi {
|
|
|
156
192
|
return `${this.config.storagePath ?? "/api/platform-storage"}/desks/${segment(desk)}/dav/project/`;
|
|
157
193
|
}
|
|
158
194
|
async request(method, path, body) {
|
|
159
|
-
const auth = await this.auth();
|
|
195
|
+
const { headers: auth, origin } = await this.auth();
|
|
160
196
|
const remaining = (this.deadline.getStore() ?? Infinity) - Date.now();
|
|
161
197
|
if (remaining <= 0)
|
|
162
198
|
throw new ToolError("connection_error", "Operation time budget exhausted before sending the next request; resume with get_deployment.");
|
|
163
199
|
let response;
|
|
164
200
|
try {
|
|
165
|
-
response = await fetch(
|
|
201
|
+
response = await fetch(origin + this.config.apiPath + path, {
|
|
166
202
|
method,
|
|
167
203
|
headers: {
|
|
168
204
|
...auth,
|
package/dist/config.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { type LocalDesk } from "./desk.js";
|
|
2
2
|
export interface Config {
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* The user's Constructor: CONSTRUCTOR_BASE_URL, else the one the saved key belongs to, else
|
|
5
|
+
* the desk's. Links shown to the user, key help and the key file name it. Requests go there
|
|
6
|
+
* too, unless the desk's own server accepts the key (see PlatformApi.origin).
|
|
7
|
+
*/
|
|
4
8
|
baseUrl: string;
|
|
9
|
+
/** Set by CONSTRUCTOR_BASE_URL: a saved key for another Constructor is not used. */
|
|
5
10
|
baseUrlFixed?: boolean;
|
|
6
11
|
/** The Constructor desk this MCP runs inside (VS Code in Constructor Research), if any. */
|
|
7
12
|
localDesk?: LocalDesk;
|
package/dist/config.js
CHANGED
|
@@ -29,7 +29,7 @@ export function configFromEnv(env = process.env) {
|
|
|
29
29
|
if (url.search || url.hash || url.pathname !== "/")
|
|
30
30
|
throw new Error("CONSTRUCTOR_BASE_URL must be an origin without a path or credentials.");
|
|
31
31
|
}
|
|
32
|
-
// Inside a Constructor desk, its
|
|
32
|
+
// Inside a Constructor desk, its server is where the user works unless a key says otherwise.
|
|
33
33
|
const localDesk = localDeskFromEnv(env, originOf);
|
|
34
34
|
const baseUrl = originOf(fixed ?? localDesk?.server ?? DEFAULT_BASE_URL);
|
|
35
35
|
const apiPath = env.CONSTRUCTOR_API_PATH ?? "/api/platform-account/v1";
|
|
@@ -44,7 +44,7 @@ export function configFromEnv(env = process.env) {
|
|
|
44
44
|
const expand = (s) => resolve(s.startsWith("~/") ? homedir() + s.slice(1) : s);
|
|
45
45
|
return {
|
|
46
46
|
baseUrl,
|
|
47
|
-
baseUrlFixed: !!fixed
|
|
47
|
+
baseUrlFixed: !!fixed,
|
|
48
48
|
localDesk,
|
|
49
49
|
apiPath: apiPath.replace(/\/$/, ""),
|
|
50
50
|
storagePath: storagePath.replace(/\/$/, ""),
|
package/dist/install.js
CHANGED
|
@@ -9,7 +9,7 @@ import { styleText } from "node:util";
|
|
|
9
9
|
import { AGENTS, PACKAGE_SPEC, SERVER, applyEntry, claudeCliWorks, describe, detect, mcpCommand, succeeded, } from "./agents.js";
|
|
10
10
|
import { cleanKey } from "./api.js";
|
|
11
11
|
import { DEFAULT_BASE_URL, configFromEnv, originOf } from "./config.js";
|
|
12
|
-
import {
|
|
12
|
+
import { readKeyFile, routeKey, saveKeyFile } from "./key.js";
|
|
13
13
|
const bold = (s) => styleText("bold", s);
|
|
14
14
|
const dim = (s) => styleText("dim", s);
|
|
15
15
|
const accent = (s) => styleText("cyan", s);
|
|
@@ -228,14 +228,18 @@ export async function runInstall(argv) {
|
|
|
228
228
|
saved = undefined; // A broken key file is replaced by the new key.
|
|
229
229
|
}
|
|
230
230
|
let base;
|
|
231
|
+
/** Inside a Constructor desk, the server it names; the key is checked there too. */
|
|
232
|
+
const deskServer = config.localDesk?.server;
|
|
231
233
|
try {
|
|
232
234
|
const given = value("--constructor");
|
|
233
235
|
if (given)
|
|
234
236
|
base = linkOrigin(given);
|
|
235
237
|
else if (yes)
|
|
236
|
-
base = saved?.url ?? DEFAULT_BASE_URL;
|
|
238
|
+
base = saved?.url ?? deskServer ?? DEFAULT_BASE_URL;
|
|
237
239
|
else {
|
|
238
|
-
|
|
240
|
+
// Inside a desk its server is the likely answer, but the user may open another address.
|
|
241
|
+
const known = saved?.url ?? deskServer;
|
|
242
|
+
const savedOrg = known && known !== DEFAULT_BASE_URL ? known : "";
|
|
239
243
|
const where = await ask(p.select({
|
|
240
244
|
message: `Where do you have access to ${bold("Constructor Research")}?`,
|
|
241
245
|
initialValue: savedOrg ? "org" : "public",
|
|
@@ -286,21 +290,33 @@ export async function runInstall(argv) {
|
|
|
286
290
|
// ---- 4. the access key ---------------------------------------------------------------------
|
|
287
291
|
let keySaved = false;
|
|
288
292
|
let keyProblem = "";
|
|
293
|
+
const short = (u) => u.replace(/^https:\/\//, "");
|
|
289
294
|
const check = async (key) => {
|
|
290
295
|
if (demo)
|
|
291
296
|
return "ok";
|
|
292
297
|
const s = p.spinner();
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
298
|
+
const also = deskServer && deskServer !== base;
|
|
299
|
+
s.start(`Checking the key with ${short(base)}${also ? ` and this desk's server ${short(deskServer)}` : ""}`);
|
|
300
|
+
const route = await routeKey(base, deskServer, config.apiPath, key, {
|
|
301
|
+
checkHome: true,
|
|
302
|
+
});
|
|
303
|
+
const said = (where, r) => r === "rejected"
|
|
304
|
+
? `${where} rejected this key`
|
|
305
|
+
: r === "unreachable"
|
|
306
|
+
? `Could not reach ${where} (VPN?)`
|
|
307
|
+
: `${where} answered without the public API`;
|
|
308
|
+
if (route.result === "ok")
|
|
309
|
+
s.stop(route.origin === base
|
|
310
|
+
? "Key accepted"
|
|
311
|
+
: `Key accepted by this desk's server ${short(route.origin)}; requests from this desk go there${route.home === "ok" ? "" : ` (${said(short(base), route.home)})`}`);
|
|
299
312
|
else
|
|
300
|
-
s.error(
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
313
|
+
s.error([
|
|
314
|
+
said(base, route.home),
|
|
315
|
+
...(route.server
|
|
316
|
+
? [said(`this desk's server ${deskServer}`, route.server)]
|
|
317
|
+
: []),
|
|
318
|
+
].join("; "));
|
|
319
|
+
return route.result;
|
|
304
320
|
};
|
|
305
321
|
let key;
|
|
306
322
|
if (yes) {
|
package/dist/key.d.ts
CHANGED
|
@@ -13,3 +13,25 @@ export declare function checkKey(url: string, apiPath: string, key: string, time
|
|
|
13
13
|
result: KeyCheck;
|
|
14
14
|
status?: number;
|
|
15
15
|
}>;
|
|
16
|
+
/**
|
|
17
|
+
* Inside a Constructor desk two addresses can lead to the user's Constructor: the one the user
|
|
18
|
+
* named (the key's: links, key help and the key file keep it) and the server the desk names
|
|
19
|
+
* (ROLOS_API_SERVER), which may differ, e.g. https://constructor.app in a desk the user opened on
|
|
20
|
+
* https://acme.constructor.app. Requests go to the desk's server when it accepts the key, else to
|
|
21
|
+
* the user's address. The desk's server is the Constructor the desk runs on, so asking it about
|
|
22
|
+
* the key sends the key nowhere new.
|
|
23
|
+
*/
|
|
24
|
+
export interface KeyRoute {
|
|
25
|
+
/** Where requests with this key go. */
|
|
26
|
+
origin: string;
|
|
27
|
+
/** "ok" when an address accepted the key, else the user's address's answer; undefined when nothing was asked. */
|
|
28
|
+
result?: KeyCheck;
|
|
29
|
+
/** The user's address's answer; only when asked for (setup). */
|
|
30
|
+
home?: KeyCheck;
|
|
31
|
+
/** The desk server's answer; only inside a desk whose server differs from the user's address. */
|
|
32
|
+
server?: KeyCheck;
|
|
33
|
+
}
|
|
34
|
+
export declare function routeKey(home: string, server: string | undefined, apiPath: string, key: string, { checkHome, timeoutMs }?: {
|
|
35
|
+
checkHome?: boolean | undefined;
|
|
36
|
+
timeoutMs?: number | undefined;
|
|
37
|
+
}): Promise<KeyRoute>;
|
package/dist/key.js
CHANGED
|
@@ -63,3 +63,17 @@ export async function checkKey(url, apiPath, key, timeoutMs = 15000) {
|
|
|
63
63
|
return { result: "unreachable" };
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
|
+
export async function routeKey(home, server, apiPath, key, { checkHome = false, timeoutMs = 15000 } = {}) {
|
|
67
|
+
const other = server && server !== home ? server : undefined;
|
|
68
|
+
const [h, s] = await Promise.all([
|
|
69
|
+
checkHome ? checkKey(home, apiPath, key, timeoutMs) : undefined,
|
|
70
|
+
other ? checkKey(other, apiPath, key, timeoutMs) : undefined,
|
|
71
|
+
]);
|
|
72
|
+
const accepted = h?.result === "ok" || s?.result === "ok";
|
|
73
|
+
return {
|
|
74
|
+
origin: s?.result === "ok" ? other : home,
|
|
75
|
+
result: accepted ? "ok" : (h ?? s)?.result,
|
|
76
|
+
home: h?.result,
|
|
77
|
+
server: s?.result,
|
|
78
|
+
};
|
|
79
|
+
}
|
package/dist/location.d.ts
CHANGED
|
@@ -10,10 +10,13 @@ implied?: boolean): z.ZodObject<{
|
|
|
10
10
|
desk_id?: z.ZodOptional<z.ZodString> | undefined;
|
|
11
11
|
desk_url: z.ZodOptional<z.ZodString>;
|
|
12
12
|
}, z.core.$strip>;
|
|
13
|
-
/**
|
|
14
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Project and desk IDs from a desk link. Its host must be the user's Constructor (the first
|
|
15
|
+
* address) or, inside a desk, the server that desk names, which may differ from it.
|
|
16
|
+
*/
|
|
17
|
+
export declare function parseDeskUrl(link: string, baseUrl: string | string[], fixed?: boolean): {
|
|
15
18
|
project_id: string;
|
|
16
19
|
desk_id: string;
|
|
17
20
|
};
|
|
18
21
|
/** Replace desk_url with the IDs it carries; explicit IDs must agree with it. */
|
|
19
|
-
export declare function resolveDeskUrl(args: any, baseUrl: string, scope: Scope, fixed?: boolean): any;
|
|
22
|
+
export declare function resolveDeskUrl(args: any, baseUrl: string | string[], scope: Scope, fixed?: boolean): any;
|
package/dist/location.js
CHANGED
|
@@ -25,7 +25,10 @@ implied = false) {
|
|
|
25
25
|
function bad(code, message) {
|
|
26
26
|
throw new ToolError(code, message);
|
|
27
27
|
}
|
|
28
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
* Project and desk IDs from a desk link. Its host must be the user's Constructor (the first
|
|
30
|
+
* address) or, inside a desk, the server that desk names, which may differ from it.
|
|
31
|
+
*/
|
|
29
32
|
export function parseDeskUrl(link, baseUrl, fixed = false) {
|
|
30
33
|
let url;
|
|
31
34
|
try {
|
|
@@ -37,10 +40,10 @@ export function parseDeskUrl(link, baseUrl, fixed = false) {
|
|
|
37
40
|
const m = url.pathname.match(/\/projects\/([a-zA-Z0-9_-]{4,128})\/desks\/([a-zA-Z0-9_-]{4,128})(?:\/|$)/);
|
|
38
41
|
if (!m)
|
|
39
42
|
bad("invalid_input", "desk_url must contain /projects/<project>/desks/<desk>. Ask the user to open the desk in Constructor and copy the address bar.");
|
|
40
|
-
const base = new URL(
|
|
41
|
-
if (url.origin !== base)
|
|
43
|
+
const [base, ...also] = [baseUrl].flat().map((u) => new URL(u).origin);
|
|
44
|
+
if (url.origin !== base && !also.includes(url.origin))
|
|
42
45
|
bad("wrong_environment", fixed
|
|
43
|
-
? `The link is for ${url.origin}, but this MCP is fixed to ${base} by CONSTRUCTOR_BASE_URL
|
|
46
|
+
? `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}.`
|
|
44
47
|
: `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.`);
|
|
45
48
|
return { project_id: m[1], desk_id: m[2] };
|
|
46
49
|
}
|
package/dist/server.js
CHANGED
|
@@ -255,7 +255,9 @@ async function main() {
|
|
|
255
255
|
...args,
|
|
256
256
|
desk_url: `${config.baseUrl}/research/projects/${here.projectId}/desks/${here.deskId}`,
|
|
257
257
|
}
|
|
258
|
-
: args,
|
|
258
|
+
: args,
|
|
259
|
+
// Links from the desk's own server work too.
|
|
260
|
+
[config.baseUrl, config.localDesk?.server ?? []].flat(), scope, config.baseUrlFixed)
|
|
259
261
|
: args;
|
|
260
262
|
// A desk tool given only the project acts on its only desk, or asks which one.
|
|
261
263
|
if (scope === "desk" &&
|
package/dist/set-key.js
CHANGED
|
@@ -4,7 +4,13 @@
|
|
|
4
4
|
// Usage: npx -y -p constructor-research-mcp constructor-research-set-key <Constructor link>
|
|
5
5
|
import { configFromEnv, originOf } from "./config.js";
|
|
6
6
|
import { cleanKey } from "./api.js";
|
|
7
|
-
import {
|
|
7
|
+
import { routeKey, saveKeyFile } from "./key.js";
|
|
8
|
+
/** What an address answered about the key, for messages. */
|
|
9
|
+
const said = (r) => r === "rejected"
|
|
10
|
+
? "rejected this key"
|
|
11
|
+
: r === "unreachable"
|
|
12
|
+
? "could not be reached (VPN?)"
|
|
13
|
+
: "answered without the public API";
|
|
8
14
|
const USAGE = "Usage: npx -y -p constructor-research-mcp constructor-research-set-key <Constructor link, e.g. https://acme.constructor.app>\nThen paste the access key (rk-…) when asked, or pipe it in on stdin.";
|
|
9
15
|
/** One line from the terminal without echoing it, or all of stdin when piped. */
|
|
10
16
|
async function readSecret(prompt) {
|
|
@@ -71,22 +77,22 @@ async function main() {
|
|
|
71
77
|
console.error("That is not an access key; nothing saved.");
|
|
72
78
|
return 1;
|
|
73
79
|
}
|
|
74
|
-
// Check the key with Constructor before saving it.
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (result !== "ok") {
|
|
85
|
-
console.error(`${url} answered HTTP ${status}: it may not have the public API yet; nothing saved.`);
|
|
80
|
+
// Check the key with Constructor before saving it; inside a desk, with its server too.
|
|
81
|
+
const server = config.localDesk?.server;
|
|
82
|
+
const route = await routeKey(url, server, config.apiPath, key, {
|
|
83
|
+
checkHome: true,
|
|
84
|
+
});
|
|
85
|
+
if (route.result !== "ok") {
|
|
86
|
+
const also = route.server
|
|
87
|
+
? `; this desk's server ${server} ${said(route.server)}`
|
|
88
|
+
: "";
|
|
89
|
+
console.error(`${url} ${said(route.home)}${also}; nothing saved.`);
|
|
86
90
|
return 1;
|
|
87
91
|
}
|
|
88
92
|
await saveKeyFile(config.keyFile, url, key);
|
|
89
93
|
console.log(`Key for ${url} saved to ${config.keyFile}. The MCP uses it from the next call; no restart needed.`);
|
|
94
|
+
if (route.origin !== url)
|
|
95
|
+
console.log(`This desk's server ${route.origin} accepts it${route.home === "ok" ? " too" : ` (${url} ${said(route.home)})`}: requests from this desk go there.`);
|
|
90
96
|
return 0;
|
|
91
97
|
}
|
|
92
98
|
main().then((code) => (process.exitCode = code), () => {
|